Skip to content

Instantly share code, notes, and snippets.

View jimblandy's full-sized avatar

Jim Blandy jimblandy

View GitHub Profile
@jimblandy
jimblandy / moz-pause-on-crash.patch
Created June 27, 2018 20:13
Patch to make Firefox pause and wait to be debugged when it crashes
MOZ_PAUSE_ON_CRASH(6W ago) changes to: Bug 1421062: Enable production nightly balrog update on comm-c...
diff --git a/toolkit/xre/nsAppRunner.cpp b/toolkit/xre/nsAppRunner.cpp
--- a/toolkit/xre/nsAppRunner.cpp
+++ b/toolkit/xre/nsAppRunner.cpp
@@ -3426,6 +3426,13 @@
mAppData->flags |= NS_XRE_ENABLE_CRASH_REPORTER;
}
+ if (EnvHasValue("MOZ_PAUSE_ON_CRASH")) {
@jimblandy
jimblandy / unfold.rs
Created June 13, 2018 04:47
A Rust `unfold` function, to build an iterator by repeatedly applying a closure.
fn main() {
//let i = (0i32..).scan((0,1), |s,_| { *s = (s.1, s.0 + s.1); Some(s.0) });
let i = unfold((0, 1), |(a, b)| Some(((b, a+b), b)));
let v: Vec<i32> = i.take(20).collect();
println!("{:?}", v);
}
struct Unfolder<F, T>(F, Option<T>);
@jimblandy
jimblandy / main.rs
Last active May 28, 2018 19:44 — forked from c0gent/main.rs
Glium - instancing over a vertex buffer slice
//! An example demonstrating that glium has a problem using instancing when
//! the vertex buffer is a slice with a non-zero starting index.
//!
#[macro_use] extern crate glium;
use glium::{glutin, Surface};
// Vertex Shader:
static VERTEX_SHADER_SRC: &'static str = r#"
#version 140
@jimblandy
jimblandy / enable-api.md
Last active April 12, 2018 05:27
API styles for enabling and disabling things

Minutiae: API styles for enabling and disabling things

So there are two API styles for enabling and disabling something: you can have a boolean that you turn on and off (call this "flag style"); and you can have calls that increment and decrement a counter, and the thing is enabled depending on whether the count is zero (call this "semaphore style").

Semaphore style is essential in some cases. If there are many different influences who all have to come to consensus in order to enter a certain state, the counter is sort of a reference count: the number of people holding us in the lack-of-consensus state. In situations like this, flag style is a pain in the neck: you'd have to implement the counter someplace else just to decide when to flip the bit.

But if you need the thing to be enabled/disabled depending on a predicate on some state, and you're calling the API whenever the state changes, then the flag API is much better: evaluate the predicate, and set the flag. If a bug causes you to miss a transitio

@jimblandy
jimblandy / dumpFunctionSkeleton.patch
Created February 14, 2018 16:47
Patch implementing dumpFunctionSkeleton testing JS function in SpiderMonkey
diff --git a/js/src/builtin/TestingFunctions.cpp b/js/src/builtin/TestingFunctions.cpp
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -4948,24 +4948,184 @@ IsConstructor(JSContext* cx, unsigned ar
CallArgs args = CallArgsFromVp(argc, vp);
if (args.length() < 1)
args.rval().setBoolean(false);
else
args.rval().setBoolean(IsConstructor(args[0]));
return true;
diff --git a/devtools/server/actors/object.js b/devtools/server/actors/object.js
--- a/devtools/server/actors/object.js
+++ b/devtools/server/actors/object.js
@@ -397,17 +397,22 @@ ObjectActor.prototype = {
obj._safeGetters = null;
continue;
}
let result = getter.call(this.obj);
if (result && !("throw" in result)) {
shibui:src$ obj~/js/src/js
js> let u = 1/5, t = 3/5
js> u + u + u === t
false
js> 2**53 + 1 + 1 === 2**53 + 2
false
js> 2**52 + 1 + 1 === 2**52 + 2
true
js>
@jimblandy
jimblandy / jsfun.h.patch
Created February 12, 2018 21:34
Remove `wasm` member from `JSFunction`
diff --git a/js/src/jsfun.h b/js/src/jsfun.h
--- a/js/src/jsfun.h
+++ b/js/src/jsfun.h
@@ -123,31 +123,28 @@ class JSFunction : public js::NativeObje
friend class JSFunction;
js::Native func_; /* native method pointer or null */
union {
// Information about this function to be used by the JIT, only
// used if isBuiltinNative(); use the accessor!
const JSJitInfo* jitInfo_;
@jimblandy
jimblandy / write.cc
Created February 2, 2018 05:40
Dumb benchmark of memory initialization and file writing speeds
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
@jimblandy
jimblandy / EnterExit.cpp
Created January 18, 2018 21:45
Dumb-as-paste function call tracing
class EnterExit {
pid_t pid;
char thread_name[100];
const char* label;
void* ptr;
public:
EnterExit(const char* label, void* ptr)
: pid(getpid()),
label(label),