Bug with global located variables accessors fixed
authorlaurent
Thu, 20 May 2010 23:36:53 +0200
changeset 242 0036357a990f
parent 241 0ba6d614573e
child 243 bdfee1f5be9e
child 244 3a478229db8b
Bug with global located variables accessors fixed
lib/accessor.h
stage4/generate_c/generate_c_vardecl.cc
--- a/lib/accessor.h	Wed May 19 21:51:52 2010 +0200
+++ b/lib/accessor.h	Thu May 20 23:36:53 2010 +0200
@@ -8,15 +8,31 @@
 #define __DECLARE_GLOBAL(type, resource, name)\
 	__IEC_##type##_t resource##__##name;\
 	static __IEC_##type##_t *GLOBAL__##name = &resource##__##name;\
+	void __INIT_GLOBAL_##name(type value) {\
+		(*GLOBAL__##name).value = value;\
+	}\
 	void __SET_GLOBAL_##name(type value) {\
 		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
 			(*GLOBAL__##name).value = value;\
+	}\
+	type* __GET_GLOBAL_##name(void) {\
+		return &((*GLOBAL__##name).value);\
 	}
 #define __DECLARE_GLOBAL_LOCATION(type, location)\
 	extern type *location;
 #define __DECLARE_GLOBAL_LOCATED(type, resource, name)\
 	__IEC_##type##_p resource##__##name;\
-	static __IEC_##type##_p *GLOBAL__##name;
+	static __IEC_##type##_p *GLOBAL__##name = &resource##__##name;\
+	void __INIT_GLOBAL_##name(type value) {\
+		*((*GLOBAL__##name).value) = value;\
+	}\
+	void __SET_GLOBAL_##name(type value) {\
+		if (!((*GLOBAL__##name).flags & __IEC_FORCE_FLAG))\
+			*((*GLOBAL__##name).value) = value;\
+	}\
+	type* __GET_GLOBAL_##name(void) {\
+		return (*GLOBAL__##name).value;\
+	}
 #define __DECLARE_EXTERNAL(type, name)\
 	__IEC_##type##_p name;
 #define __DECLARE_LOCATED(type, name)\
@@ -30,15 +46,14 @@
 	name.value = initial;\
 	__INIT_RETAIN(name, retained)
 #define __INIT_GLOBAL(name, initial, retained)\
-	(*GLOBAL__##name).value = initial;\
+	__INIT_GLOBAL_##name(initial);\
 	__INIT_RETAIN((*GLOBAL__##name), retained)
 #define __INIT_GLOBAL_LOCATED(resource, name, location, retained)\
 	resource##__##name.value = location;\
 	__INIT_RETAIN(resource##__##name, retained)
 #define __INIT_EXTERNAL(type, global, name, retained)\
-	{extern __IEC_##type##_t *GLOBAL__##global;\
-	 name.value = &((*GLOBAL__##global).value);\
-     __INIT_RETAIN(name, retained)}
+	name.value = __GET_GLOBAL_##global();\
+    __INIT_RETAIN(name, retained)
 #define __INIT_LOCATED(type, location, name, retained)\
 	{extern type *location;\
 	 name.value = location;\
--- a/stage4/generate_c/generate_c_vardecl.cc	Wed May 19 21:51:52 2010 +0200
+++ b/stage4/generate_c/generate_c_vardecl.cc	Thu May 20 23:36:53 2010 +0200
@@ -1945,7 +1945,6 @@
     case constructorinit_vf:
       if (symbol->global_var_name != NULL) {
     	s4o.print(nv->get());
-    	s4o.print(s4o.indent_spaces);
     	s4o.print(INIT_GLOBAL_LOCATED);
     	s4o.print("(");
     	if (this->resource_name != NULL) {
@@ -1960,7 +1959,6 @@
       }
       if (this->current_var_init_symbol != NULL) {
 	    s4o.print(nv->get());
-	    s4o.print(s4o.indent_spaces);
 	    s4o.print(INIT_GLOBAL);
 	    s4o.print("(");
 	    if (symbol->global_var_name != NULL)