Fix free C string bugs in ffi

This commit is contained in:
2023-04-25 16:55:33 +00:00
parent a39aee66f5
commit 9b1cead91e
9 changed files with 36 additions and 49 deletions

View File

@@ -652,11 +652,6 @@ void phys2d_reindex_body(cpBody *body) {
cpSpaceReindexShapesForBody(space, body);
}
void register_collide(void *sym) {
}
void duk_call_phys_cb(cpVect norm, struct callee c, int hit, cpArbiter *arb)
{
cpShape *shape1;
@@ -699,14 +694,16 @@ static cpBool handle_collision(cpArbiter *arb, int type)
if (go->shape_cbs[i].shape == pshape1)
duk_call_phys_cb(norm1, go->shape_cbs[i].cbs.begin, g2, arb);
if (!JS_IsNull(go->cbs.begin.obj))
if (JS_IsObject(go->cbs.begin.obj))
duk_call_phys_cb(norm1, go->cbs.begin, g2, arb);
break;
case CTYPE_SEP:
if (!JS_IsNull(go->cbs.separate.obj))
if (JS_IsObject(go->cbs.separate.obj)) {
YughWarn("Made it here; separate.");
duk_call_phys_cb(norm1, go->cbs.separate, g2, arb);
}
break;
@@ -741,25 +738,6 @@ void phys2d_setup_handlers(int go)
handler->separateFunc = script_phys_cb_separate;
}
void phys2d_add_handler_type(int cmd, int go, struct callee c) {
switch (cmd) {
case 0:
id2go(go)->cbs.begin = c;
break;
case 1:
break;
case 2:
break;
case 3:
//handler->separateFunc = s7_phys_cb_separate;
//go->cbs->separate = cb;
break;
}
}
static int airborne = 0;
void inair(cpBody *body, cpArbiter *arbiter, void *data)

View File

@@ -118,8 +118,6 @@ struct shape_cb {
void fire_hits();
void phys2d_add_handler_type(int cmd, int go, struct callee c);
void register_collide(void *sym);
void phys2d_rm_go_handlers(int go);
void phys2d_set_gravity(cpVect v);

View File

@@ -561,8 +561,7 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
case 0:
str = JS_ToCString(js,argv[1]);
ret = JS_NewInt64(js, script_dofile(str));
JS_FreeCString(js,str);
return ret;
break;
case 1:
YughWarn("Do not set pawns here anymore; Do it entirely in script.");
@@ -619,14 +618,11 @@ JSValue duk_cmd(JSContext *js, JSValueConst this, int argc, JSValueConst *argv)
str = JS_ToCString(js,argv[1]);
str2 = JS_ToCString(js,argv[2]);
play_song(str,str2);
JS_FreeCString(js,str);
JS_FreeCString(js,str2);
break;
case 14:
str = JS_ToCString(js, argv[1]);
mini_sound(str);
JS_FreeCString(js,str);
break;
case 15:

View File

@@ -50,6 +50,23 @@ time_t file_mod_secs(const char *file) {
return attr.st_mtime;
}
void js_stacktrace()
{
YughWarn("Dumping stack ...");
JSValue error = JS_NewError(js);
JSValue stack = JS_GetPropertyStr(js, error, "stack");
if (JS_IsNull(stack)) return;
const char *stackstr = JS_ToCString(js,stack);
log_print(stackstr);
JS_FreeCString(js,stackstr);
JS_FreeValue(js,stack);
JS_FreeValue(js, error);
}
void js_dump_stack()
{
JSValue exception = JS_GetException(js);
@@ -64,7 +81,6 @@ void js_dump_stack()
JS_FreeCString(js, msg);
JS_FreeCString(js, stack);
}
}

View File

@@ -70,9 +70,8 @@ void print_stacktrace()
YughInfo("Stack size is %d.", size);
for (int i = 0; i < size; i++) {
for (int i = 0; i < size; i++)
YughCritical(stackstr[i]);
}
js_dump_stack();
@@ -80,12 +79,8 @@ void print_stacktrace()
void seghandle(int sig) {
#ifdef __linux__
if (strsignal(sig)) {
if (strsignal(sig))
YughCritical("CRASH! Signal: %s.", strsignal(sig));
}
else {
YughCritical("CRASH! Signal: %d.", sig);
}
print_stacktrace();