Просмотр исходного кода

[hlc] split hl_init_roots to prevent out of heap in msvc (#11988)

* [hlc] split hl_init_roots to prevent out of heap in msvc

* Fix typo
Yuxiao Mao 5 месяцев назад
Родитель
Сommit
a3f7fcc931
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      src/generators/hl2c.ml

+ 11 - 1
src/generators/hl2c.ml

@@ -1556,18 +1556,28 @@ let write_c com file (code:code) gnames =
 		sexpr "static struct _%s %s = {%s}" (ctype t) name (String.concat "," fields);
 		sexpr "static struct _%s %s = {%s}" (ctype t) name (String.concat "," fields);
 	) code.constants;
 	) code.constants;
 	line "";
 	line "";
-	line "void hl_init_roots() {";
+	line "void hl_init_roots_constants() {";
 	block ctx;
 	block ctx;
 	let is_const = Hashtbl.create 0 in
 	let is_const = Hashtbl.create 0 in
 	Array.iter (fun (g,fields) ->
 	Array.iter (fun (g,fields) ->
 		sexpr "%s = &const_%s" gnames.(g) gnames.(g);
 		sexpr "%s = &const_%s" gnames.(g) gnames.(g);
 		Hashtbl.add is_const g true;
 		Hashtbl.add is_const g true;
 	) code.constants;
 	) code.constants;
+	unblock ctx;
+	line "}";
+	line "void hl_init_roots_globals() {";
+	block ctx;
 	Array.iteri (fun i t ->
 	Array.iteri (fun i t ->
 		if is_ptr t && not (Hashtbl.mem is_const i) then sexpr "hl_add_root((void**)&%s)" gnames.(i);
 		if is_ptr t && not (Hashtbl.mem is_const i) then sexpr "hl_add_root((void**)&%s)" gnames.(i);
 	) code.globals;
 	) code.globals;
 	unblock ctx;
 	unblock ctx;
 	line "}";
 	line "}";
+	line "void hl_init_roots() {";
+	block ctx;
+	expr "hl_init_roots_constants()";
+	expr "hl_init_roots_globals()";
+	unblock ctx;
+	line "}";
 
 
 	let output_bytes f str =
 	let output_bytes f str =
 		for i = 0 to String.length str - 1 do
 		for i = 0 to String.length str - 1 do