Browse Source

Sol Part 50: Now 99.99% more stable!

Fixed a very annoying free of uninitialized pointer
Graham Northup 4 years ago
parent
commit
82d5646b0e
Signed by: Grissess <grissess@nexusg.org> GPG Key ID: 5D000E6F539376FB
4 changed files with 10 additions and 9 deletions
  1. 1
    1
      build.sh
  2. 1
    1
      gc.c
  3. 1
    1
      programs/test.sol
  4. 7
    6
      runtime.c

+ 1
- 1
build.sh View File

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

+ 1
- 1
gc.c View File

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

+ 1
- 1
programs/test.sol View File

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

+ 7
- 6
runtime.c View File

@@ -771,7 +771,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
771 771
 			break;
772 772
 
773 773
 		case EX_IFELSE:
774
-			value = sol_eval(state, expr->ifelse->cond);
774
+			value = sol_eval_inner(state, expr->ifelse->cond, jmp);
775 775
 			vint = sol_cast_int(state, value);
776 776
 			if(vint->ival) {
777 777
 				if(expr->ifelse->iftrue) {
@@ -790,7 +790,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
790 790
 		case EX_LOOP:
791 791
 			sol_obj_free(state->loopvalue);
792 792
 			state->loopvalue = sol_new_list(state);
793
-			value = sol_eval(state, expr->loop->cond);
793
+			value = sol_eval_inner(state, expr->loop->cond, jmp);
794 794
 			vint = sol_cast_int(state, value);
795 795
 			while(vint->ival) {
796 796
 				sol_obj_free(value);
@@ -802,7 +802,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
802 802
 					continue;
803 803
 				}
804 804
 				state->sflag = SF_NORMAL;
805
-				value = sol_eval(state, expr->loop->cond);
805
+				value = sol_eval_inner(state, expr->loop->cond, jmp);
806 806
 				vint = sol_cast_int(state, value);
807 807
 			}
808 808
 			state->sflag = SF_NORMAL;
@@ -814,7 +814,7 @@ sol_object_t *sol_eval_inner(sol_state_t *state, expr_node *expr, jmp_buf jmp) {
814 814
 		case EX_ITER:
815 815
 			sol_obj_free(state->loopvalue);
816 816
 			state->loopvalue = sol_new_list(state);
817
-			value = sol_eval(state, expr->iter->iter);
817
+			value = sol_eval_inner(state, expr->iter->iter, jmp);
818 818
 			if(value->ops->iter && value->ops->iter != sol_f_not_impl) {
819 819
 				list = sol_new_list(state);
820 820
 				sol_list_insert(state, list, 0, value);
@@ -864,7 +864,7 @@ sol_object_t *sol_eval(sol_state_t *state, expr_node *expr) {
864 864
 }
865 865
 
866 866
 void sol_exec(sol_state_t *state, stmt_node *stmt) {
867
-	sol_object_t *value, *vint, *list, *iter, *item;
867
+	sol_object_t *value = NULL, *vint = NULL, *list, *iter, *item;
868 868
 	stmtlist_node *curs;
869 869
 	if(!stmt) {
870 870
 		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) {
872 872
 	}
873 873
 	switch(stmt->type) {
874 874
 		case ST_EXPR:
875
+			vint = value;
875 876
 			value = state->lastvalue;
876 877
 			state->lastvalue = sol_eval(state, stmt->expr);
877
-			sol_obj_free(value);
878
+			sol_obj_free(vint);
878 879
 			if(sol_has_error(state)) {
879 880
 				sol_add_traceback(state, sol_new_stmtnode(state, st_copy(stmt)));
880 881
 			}

Loading…
Cancel
Save