Leopold Toetsch <[EMAIL PROTECTED]> writes:

> Benjamin Goldberg <[EMAIL PROTECTED]> wrote:
> 
> > #define PARROT_DECLARE_STATIC_STRING(name, cstring) \
> 
> [ big snip ]
> 
> While Juergen's original or your proposal are fine, they don't work
> (or not as proposed). First there are compiler issues:
> 
> $ gcc -Iinclude -Lblib/lib -lparrot -ldl -Wall -g bg.c && ./a.out
> 
> #v+
> bg.c: In function `main':
> bg.c:35: warning: braces around scalar initializer
> bg.c:35: warning: (near initialization for 
> `_Parrot_static_mystr_STRING.obj.u.int_val')
> bg.c:35: warning: initialization makes integer from pointer without a cast
> bg.c:35: warning: excess elements in scalar initializer
> bg.c:35: warning: (near initialization for 
> `_Parrot_static_mystr_STRING.obj.u.int_val')
> #v-

The first warning is about the Union initialisation. A initialiser of
a union always initializes the first element, which is a INTVAL, but I
wanted to initialize the last item (which is not possible in pure
ANSI, but it turned out gcc got it right anyway). A simple change of
order in the Union would make this warning go away.

> The declaration looks ok at first sight, my gcc 2.95.2 might be wrong, but
> anyway, a bigger problem is here:
> 
>      PIO_printf(interpreter, "%S\n", mystr);
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x400f8725 in make_COW_reference (interpreter=0x8049828, s=0x80486e0)
>     at string.c:95
> 95              PObj_constant_CLEAR(s);
> (gdb) bac
> #0  0x400f8725 in make_COW_reference (interpreter=0x8049828, s=0x80486e0)
>     at string.c:95
> #1  0x400f91b6 in string_copy (interpreter=0x8049828, s=0x80486e0)
>     at string.c:497

Ah it seems that make_COW_reference wants to change a constant
string. As my code puts the static strings in .rodata (this was one of
the targets of my experiments) it is not possible in any way to change
this item. 

I even think PObj_constant_CLEAR(s) is evil. One reason for
setting a PObj_constant_FLAG is to declare that an object will not
change. Unsetting this flag means breaking this contract.

> snippet from objdump:
> 
>  .rodata        00000011              _Parrot_static_mystr_cstring.15
>  .rodata        00000024              _Parrot_static_mystr_STRING.16
> 
> If we get a general compiler independend solution for declaring static
> STRINGs we still have nothing for static keys.

The main problem of all this code is the union initialiser. Static
keys could also created with an initialisier, but i think this needs
an other union-val to be initialized. There are gcc extension to init
arbitary members, but ANSI-C allows only the initializiation of the
first member.

bye
boe
-- 
Juergen Boemmels                        [EMAIL PROTECTED]
Fachbereich Physik                      Tel: ++49-(0)631-205-2817
Universitaet Kaiserslautern             Fax: ++49-(0)631-205-3906
PGP Key fingerprint = 9F 56 54 3D 45 C1 32 6F  23 F6 C7 2F 85 93 DD 47

Reply via email to