Browse Source

Sol Part 50: Now 99.99% more stable!

Fixed a very annoying free of uninitialized pointer
master
Graham Northup 5 years ago
parent
commit
82d5646b0e
Signed by: grissess GPG Key ID: 5D000E6F539376FB
  1. 2
      build.sh
  2. 2
      gc.c
  3. 2
      programs/test.sol
  4. 13
      runtime.c

2
build.sh

@ -26,4 +26,4 @@ gcc -c $CFLAGS object.c
gcc -c $CFLAGS state.c
gcc -c $CFLAGS builtins.c
gcc -c $CFLAGS solrun.c
gcc $CFLAGS *.o -o solace -lm -ldl
gcc $CFLAGS *.o -o sol -lm -ldl

2
gc.c

@ -26,7 +26,7 @@ sol_object_t *_sol_gc_alloc_object(sol_state_t *state) {
void _sol_gc_obj_free(sol_object_t *obj) {
if(!obj) {
printf("WARNING: Attempt to free NULL\n");
/*printf("WARNING: Attempt to free NULL\n");*/
return;
}
if(sol_decref(obj) <= 0) {

2
programs/test.sol

@ -185,7 +185,7 @@ print('--- Exec/eval')
exec('print("Hello from exec!")')
print(eval('5 + 3'))
execfile('subtest.sol')
execfile('programs/subtest.sol')
print('--- Modulus')

13
runtime.c

@ -771,7 +771,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
break;
case EX_IFELSE:
value = sol_eval(state, expr->ifelse->cond);
value = sol_eval_inner(state, expr->ifelse->cond, jmp);
vint = sol_cast_int(state, value);
if(vint->ival) {
if(expr->ifelse->iftrue) {
@ -790,7 +790,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
case EX_LOOP:
sol_obj_free(state->loopvalue);
state->loopvalue = sol_new_list(state);
value = sol_eval(state, expr->loop->cond);
value = sol_eval_inner(state, expr->loop->cond, jmp);
vint = sol_cast_int(state, value);
while(vint->ival) {
sol_obj_free(value);
@ -802,7 +802,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
continue;
}
state->sflag = SF_NORMAL;
value = sol_eval(state, expr->loop->cond);
value = sol_eval_inner(state, expr->loop->cond, jmp);
vint = sol_cast_int(state, value);
}
state->sflag = SF_NORMAL;
@ -814,7 +814,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
case EX_ITER:
sol_obj_free(state->loopvalue);
state->loopvalue = sol_new_list(state);
value = sol_eval(state, expr->iter->iter);
value = sol_eval_inner(state, expr->iter->iter, jmp);
if(value->ops->iter && value->ops->iter != sol_f_not_impl) {
list = sol_new_list(state);
sol_list_insert(state, list, 0, value);
@ -864,7 +864,7 @@ sol_object_t *sol_eval(sol_state_t *state, expr_node *expr) {
}
void sol_exec(sol_state_t *state, stmt_node *stmt) {
sol_object_t *value, *vint, *list, *iter, *item;
sol_object_t *value = NULL, *vint = NULL, *list, *iter, *item;
stmtlist_node *curs;
if(!stmt) {
sol_obj_free(sol_set_error_string(state, "Execute NULL statement"));
@ -872,9 +872,10 @@ void sol_exec(sol_state_t *state, stmt_node *stmt) {
}
switch(stmt->type) {
case ST_EXPR:
vint = value;
value = state->lastvalue;
state->lastvalue = sol_eval(state, stmt->expr);
sol_obj_free(value);
sol_obj_free(vint);
if(sol_has_error(state)) {
sol_add_traceback(state, sol_new_stmtnode(state, st_copy(stmt)));
}

Loading…
Cancel
Save