Originally, I simply used:
gcc -I/usr/include/mozjs -g -DXP_UNIX test.c -lmozjs -o test
Using your more detailed command yields the same segfault, however.
It's worth noting that I am using 8.04 as 8.10 doesn't work on my
laptop. If it's of interest the md5 of of libmozjs.so is
2898019a2c9ac8c6d374a171ebe31411.
In gdb, I believe I've tracked down the problem to a a mistaken struct
size for JSFunctionSpec. In JS_DefineFunctions, they have this code:
JS_PUBLIC_API(JSBool)
JS_DefineFunctions(JSContext *cx, JSObject *obj, JSFunctionSpec *fs)
{
//...
for (; fs->name; fs++) {
//...
fun = JS_DefineFunction(cx, obj, fs->name, fs->call, fs->nargs, flags);
//...
}
//...
}
JS_DefineFunction makes a call to strlen(fs->name), which segfaults on
the second loop through. With the code that I provided, it tries to call
strlen(0x01). Specifically, its trying to call strlen() on the value of
JSFunctionSpec->extra from the element in the fs array before the
current one. I've tested this by changing the value of extra and
monitoring what it calls strlen() on.
When I copied the above code into my test program, I get no segfault.
sizeof(JSFunctionSpec) returns 16 bytes. It seems that the library that
was installed through the package manager thinks its a different value.
--
JS_DefineFunctions Does Not Work in 32bit Build (SegFaults)
https://bugs.launchpad.net/bugs/339331
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs