Prechádzať zdrojové kódy

gc fix for MSVC Release

Nicolas Cannasse 9 rokov pred
rodič
commit
b0174be403
1 zmenil súbory, kde vykonal 31 pridanie a 29 odobranie
  1. 31 29
      src/alloc.c

+ 31 - 29
src/alloc.c

@@ -1,23 +1,23 @@
-/*
- * Copyright (C)2005-2016 Haxe Foundation
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
+/*
+ * Copyright (C)2005-2016 Haxe Foundation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
  */
 #include "hl.h"
 #ifdef HL_WIN
@@ -546,15 +546,16 @@ static void gc_clear_unmarked_mem() {
 #endif
 
 static void gc_mark() {
-	// prepare mark bits
-	jmp_buf tmp;
+	jmp_buf regs;
 	void **stack_head;
 	void **stack_top = (void**)gc_stack_top;
 	void **mark_stack = cur_mark_stack;
 	int mark_bytes = gc_stats.mark_bytes;
 	int pid, i;
 	unsigned char *mark_cur;
-	setjmp(tmp); // save registers
+	// save registers
+	setjmp(regs);
+	// prepare mark bits
 	if( mark_bytes > mark_size ) {
 		gc_free_page_memory(mark_data, mark_size);
 		if( mark_size == 0 ) mark_size = GC_PAGE_SIZE;
@@ -590,6 +591,7 @@ static void gc_mark() {
 	}
 	// scan stack
 	stack_head = (void**)&stack_head;
+	if( stack_head > (void**)&regs ) stack_head = (void**)&regs; // fix for compilers that might inverse variables
 	while( stack_head <= stack_top ) {
 		void *p = *stack_head++;
 		gc_pheader *page = GC_GET_PAGE(p);
@@ -670,12 +672,12 @@ HL_API void hl_gc_dump() {
 					hl_field_lookup *f = hl_lookup_find(hashes,h_count,hash);
 					if( f == NULL ) {
 						if( h_count == h_size ) {
-							int nsize = h_size ? h_size << 1 : 128;
-							hl_field_lookup *ns = (hl_field_lookup*)malloc(sizeof(hl_field_lookup)*nsize);
-							memcpy(ns,hashes,h_size*sizeof(hl_field_lookup));
-							free(hashes);
-							hashes = ns;
-							h_size = nsize;
+							int nsize = h_size ? h_size << 1 : 128;
+							hl_field_lookup *ns = (hl_field_lookup*)malloc(sizeof(hl_field_lookup)*nsize);
+							memcpy(ns,hashes,h_size*sizeof(hl_field_lookup));
+							free(hashes);
+							hashes = ns;
+							h_size = nsize;
 						}
 						f = hl_lookup_insert(hashes,h_count++,hash,NULL,0);
 					}