gpt4 book ai didi

c++ - spidermonkey 1.8.5 在 Debug模式下崩溃

转载 作者:行者123 更新时间:2023-11-28 07:42:08 26 4
gpt4 key购买 nike

我在我的应用程序中使用 Spidermonkey 1.8.5。当我使用调试 JS 库时,我的应用程序崩溃了。我正在使用以下选项构建库:--enable-debug --disable-optimize --enable-threadsafe

崩溃指向这里:断言失败:(cx)->thread->data.requestDepth || (cx)->thread == (cx)->runtime->gcThread, at ../../src/jsapi.cpp

这是示例程序

/* Include the JSAPI header file to get access to SpiderMonkey. */
#include "jsapi.h"



/* The class of the global object. */
static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS
};

/* The error reporter callback. */
void reportError(JSContext *cx, const char *message, JSErrorReport *report)
{
fprintf(stderr, "%s:%u:%s\n",
report->filename ? report->filename : "<no filename=\"filename\">",
(unsigned int) report->lineno,
message);
}

int main(int argc, const char *argv[])
{
/* JSAPI variables. */
JSRuntime *rt;
JSContext *cx;
JSObject *global;
printf("Started\n");
/* Create a JS runtime. You always need at least one runtime per process. */
rt = JS_NewRuntime(8 * 1024 * 1024);

if (rt == NULL)
return 1;

/*
* Create a context. You always need a context per thread.
* Note that this program is not multi-threaded.
*/
cx = JS_NewContext(rt, 8192);
if (cx == NULL)
return 1;

JS_SetErrorReporter(cx, reportError);

/*
* Create the global object in a new compartment.
* You always need a global object per context.
*/
global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
if (global == NULL)
return 1;

/*
* Populate the global object with the standard JavaScript
* function and object classes, such as Object, Array, Date.
*/
if (!JS_InitStandardClasses(cx, global))
return 1;

/* Your application code here. This may include JSAPI calls
* to create your own custom JavaScript objects and to run scripts.
*
* The following example code creates a literal JavaScript script,
* evaluates it, and prints the result to stdout.
*
* Errors are conventionally saved in a JSBool variable named ok.
*/
char *script = "'Hello ' + 'World!'";
jsval rval;
JSString *str;
JSBool ok;
const char *filename = "noname";
uintN lineno = 0;

ok = JS_EvaluateScript(cx, global, script, strlen(script),
filename, lineno, &rval);
if (rval == NULL | rval == JS_FALSE)
return 1;

str = JS_ValueToString(cx, rval);
printf("%s\n", JS_EncodeString(cx, str));

/* End of your application code */

/* Clean things up and shut down SpiderMonkey. */
JS_DestroyContext(cx);
JS_DestroyRuntime(rt);
JS_ShutDown();
return 0;
}

如果我在 Release模式下构建,程序运行良好。此问题仅与 Debug模式有关。我在这里缺少什么?

最佳答案

JS_NewCompartmentAndGlobalObject 调用之前插入 JS_BeginRequest(cx);

在调用 JS_DestroyContext 之前插入 JS_EndRequest(cx);

大多数 JSAPI 函数都需要一个请求。 (我不确定为什么。线程的最初原因与多线程有关,但现在每个 JSRuntime 都是单线程的。)

SpiderMonkey 的调试版本包括以 Release模式无法做到的方式检查 API 使用情况的断言。因此,您可能会再次看到仅调试断言。我强烈建议针对调试版本进行开发,因为这些断言几乎总是表明真正的问题。

下一个 SpiderMonkey 版本即将发布:https://bugzilla.mozilla.org/show_bug.cgi?id=735599#c54

关于c++ - spidermonkey 1.8.5 在 Debug模式下崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15615677/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com