Pārlūkot izejas kodu

Fixed an issue with JSON func serialization.

Marco Bambini 8 gadi atpakaļ
vecāks
revīzija
a764af4f83

+ 1 - 1
src/compiler/gravity_lexer.c

@@ -603,7 +603,7 @@ gtoken_t gravity_lexer_token_type (gravity_lexer_t *lexer) {
 
 void gravity_lexer_skip_line (gravity_lexer_t *lexer) {
 	while (!IS_EOF) {
-		int c;
+		int c = 0;
 		next_utf8(lexer, &c);
 		if (is_newline(lexer, c)) {
 			INC_LINE;

+ 5 - 4
src/runtime/gravity_vm.c

@@ -1745,14 +1745,15 @@ gravity_closure_t *gravity_vm_loadfile (gravity_vm *vm, const char *path) {
 }
 
 gravity_closure_t *gravity_vm_loadbuffer (gravity_vm *vm, const char *buffer, size_t len) {
-	json_value *json = json_parse (buffer, len);
-	if (!json) goto abort_load;
-	if (json->type != json_object) goto abort_load;
-	
 	// state buffer for further processing super classes
 	void_r objects;
 	marray_init(objects);
 	
+    // start json parsing
+	json_value *json = json_parse (buffer, len);
+	if (!json) goto abort_load;
+	if (json->type != json_object) goto abort_load;
+	
 	// disable GC while deserializing objects
 	gravity_gc_setenabled(vm, false);
 	

+ 1 - 1
src/shared/gravity_value.c

@@ -574,7 +574,7 @@ static void gravity_function_cpool_dump (gravity_function_t *f) {
 }
 
 static void gravity_function_bytecode_serialize (gravity_function_t *f, json_t *json) {
-	if (!f->bytecode) {
+	if (!f->bytecode || !f->ninsts) {
 		json_add_null(json, GRAVITY_JSON_LABELBYTECODE);
 		return;
 	}