# HG changeset patch # User laurent # Date 1274391413 -7200 # Node ID 0036357a990fbe3ccb72f966554f64bd12d6c64d # Parent 0ba6d614573e5d84baadf80300fe837fb4ce8080 Bug with global located variables accessors fixed diff -r 0ba6d614573e -r 0036357a990f lib/accessor.h --- 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;\ diff -r 0ba6d614573e -r 0036357a990f stage4/generate_c/generate_c_vardecl.cc --- 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)