Fix free C string bugs in ffi

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

View file

@ -83,7 +83,7 @@ ifeq ($(OS), WIN32)
EXT = .exe
else
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib -rdynamic
ELIBS = engine pthread yughc glfw3 quickjs c m dl
ELIBS = engine pthread yughc glfw3 quickjs tcc c m dl
CLIBS =
endif

View file

@ -17,7 +17,7 @@ name, position, and list of components are listed.
* Alt-O Add level to current level
* Alt-A or Alt-P Add a prefab
* Ctrl-I Objects on the level
* Ctrl-M Asset viewer. When on a component like a sprite, serves to select that sprite's texture
* Ctrl-E Asset viewer. When on a component like a sprite, serves to select that sprite's texture
* Ctrl-[ Downsize grid
* Ctrl-] Upsize grid
* Backtick REPL

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();

View file

@ -95,7 +95,7 @@ var sprite = clone(component, {
},
load_img(img) {
cmd(12, this.id, img);
cmd(12, this.id, img, this.rect);
},
kill() {

View file

@ -44,7 +44,7 @@ var Log = {
cmd(91,msg);
},
stack(skip) {
stack(skip = 0) {
var stack = (new Error()).stack;
var n = stack.next('\n',0)+1;
for (var i = 0; i < skip; i++)
@ -52,7 +52,6 @@ var Log = {
this.write(stack.slice(n));
},
};
var files = {};
@ -432,8 +431,13 @@ var Register = {
pawns: [],
pawn_input(fn, ...args) {
this.pawns.forEach(x => {
if (fn in x)
x[fn].call(x, ...args);
if (fn in x) {
x[fn](...args);
return;
var f = x[fn];
if (typeof f !== 'function') return;
x.f(...args);
}
});
},
@ -448,7 +452,7 @@ var Register = {
this.nk_guis = this.nk_guis.filter(x => x[1] !== obj);
this.pawns = this.pawns.filter(x => x[1] !== obj);
this.debugs = this.debugs.filter(x => x[1] !== obj);
this.physupdates = this.debugs.filter(x => x[1] !== obj);
this.physupdates = this.physupdates.filter(x => x[1] !== obj);
},
};
register(0, Register.update, Register);