# New Ticket Created by Andy Dougherty
# Please include the string: [perl #30118]
# in the subject line of all future correspondence about this issue.
# <URL: http://rt.perl.org:80/rt3/Ticket/Display.html?id=30118 >
Sun's Workshop Compiler will not accept non-constant items in an
initialzation. Before this patch, compilation of parrot would fail
with lots of error messages of the form
"classes/null.c", line 1918: non-constant initializer: op "NAME"
The problem is lines like this in all the classes/*.c files:
const struct {
INTVAL func_nr;
INTVAL left, right;
funcptr_t func_ptr;
} _temp_mmd_init[] = {
{ MMD_ADD, entry, 0,
(funcptr_t) Parrot_Null_add }, [ ... ]
where 'entry' is an argument to the class_init() function.
The classes/*.c files are generated by lib/Parrot/Pmc2c.pm. This
patch changes Pmc2c.pm to initialize the arrays to a constant (0)
} _temp_mmd_init[] = {
{ MMD_ADD, 0, 0,
(funcptr_t) Parrot_Null_add }, [ ... ]
and then add in a simple initialization loop immediately after, where
each .left element gets set to 'entry'. Since I now modify the array,
I had to remove the 'const' qualifier.
--- parrot-current/lib/Parrot/Pmc2c.pm Sat May 15 19:00:15 2004
+++ parrot-andy/lib/Parrot/Pmc2c.pm Tue Jun 8 13:41:14 2004
@@ -541,7 +541,7 @@
$func = $method->{mmd};
# dynamic classes need the runtime type
# which is passed in entry to class_init
- $left = "entry"; #"enum_class_$classname";
+ $left = 0; # set to 'entry' below in initialization loop.
$right = 0;
push @mmds, [ $func, $left, $right, $meth_name ];
foreach my $variant (@{ $self->{mmd_variants}{$meth} }) {
@@ -549,7 +549,6 @@
$meth_name = $variant->[1] . '_' .$variant->[0];
push @mmds, [ $func, $left, $right, $meth_name];
}
-
}
}
my $methlist = join(",\n ", @meths);
@@ -583,16 +582,23 @@
$cout .= <<"EOC" if $mmd_list ne '/* N/Y */';
- const struct {
+ struct {
INTVAL func_nr;
INTVAL left, right;
funcptr_t func_ptr;
} _temp_mmd_init[] = {
$mmd_list
};
+ /* Dynamic classes need the runtime type
+ which is passed in entry to class_init.
+ */
+ #define N_MMD_INIT (sizeof(_temp_mmd_init)/sizeof(_temp_mmd_init[0]))
+ int i;
+ for (i = 0; i < (int)N_MMD_INIT; ++i) {
+ _temp_mmd_init[i].left = entry;
+ }
EOC
$cout .= <<"EOC";
- int i;
/*
* parrotio calls some class_init functions during its class_init
@@ -617,7 +623,6 @@
/*
* register mmds
*/
- #define N_MMD_INIT (sizeof(_temp_mmd_init)/sizeof(_temp_mmd_init[0]))
for (i = 0; i < (int)N_MMD_INIT; ++i) {
mmd_register(interp,
_temp_mmd_init[i].func_nr,
--
Andy Dougherty [EMAIL PROTECTED]