Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[perl #39244] [PATCH] Initialize I and N registers.

4 views
Skip to first unread message

Andy Dougherty

unread,
May 30, 2006, 11:32:09 AM5/30/06
to bugs-bi...@rt.perl.org
# New Ticket Created by Andy Dougherty
# Please include the string: [perl #39244]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=39244 >


Parrot's I and N registers are initialized to 0, but only for DEBUGGING
builds. For non-debugging builds, registers often, but not always, end
up as zero. This leads to subtle errors -- I have found and patched
several spots in the test suite where test files assumed registers were
zeroed. I suspect there are more errors waiting to be discovered.

I don't know what the ultimate intent is, but having initialization
depend on whether or not parrot was built with -DDEBUGGING doesn't seem
like a good long-term plan.

The first patch here simply removes the DEBUGGING conditional. This
way, registers are automatically zeroed, unless the user uses the -D40
flag.

The second patch changes the initial value to a different non-zero
value. This is useful for ferreting out hidden assumptions. If the
ultimate intent is to guarantee initialization to 0, then this second
patch should probably not be applied. However, if the intent is not to
guarantee initialization, then I'd recommend something like this second
patch be put in place, at least for a while, to ensure no programs are
relying on automatic initialization.


--- parrot-current/src/register.c 2006-05-11 09:01:03.960002000 -0400
+++ parrot-andy/src/register.c 2006-05-11 11:18:59.000000000 -0400
@@ -202,7 +202,6 @@
for (i = 0; i < ctx->n_regs_used[REGNO_STR]; i++) {
CTX_REG_STR(ctx, i) = NULL;
}
-#ifndef NDEBUG
for (i = 0; i < ctx->n_regs_used[REGNO_INT]; i++) {
/* depending on -D40 we set int, num to garbage or zero
*/
@@ -224,7 +223,6 @@
CTX_REG_NUM(ctx, i) = 0.0;
}
}
-#endif
}

static void
--- parrot-current/src/register.c 2006-05-11 11:18:59.000000000 -0400
+++ parrot-andy/src/register.c 2006-05-11 11:20:40.000000000 -0400
@@ -203,24 +203,24 @@
CTX_REG_STR(ctx, i) = NULL;
}
for (i = 0; i < ctx->n_regs_used[REGNO_INT]; i++) {
- /* depending on -D40 we set int, num to garbage or zero
+ /* depending on -D40 we set int, num to different garbage values
*/
if (Interp_debug_TEST(interpreter, PARROT_REG_DEBUG_FLAG)) {
/* TODO better use rand values */
CTX_REG_INT(ctx, i) = -999;
}
else {
- CTX_REG_INT(ctx, i) = 0;
+ CTX_REG_INT(ctx, i) = -888;
}
}
for (i = 0; i < ctx->n_regs_used[REGNO_NUM]; i++) {
- /* depending on -D40 we set int, num to garbage or zero
+ /* depending on -D40 we set int, num to different garbage values
*/
if (Interp_debug_TEST(interpreter, PARROT_REG_DEBUG_FLAG)) {
CTX_REG_NUM(ctx, i) = -99.9;
}
else {
- CTX_REG_NUM(ctx, i) = 0.0;
+ CTX_REG_NUM(ctx, i) = -88.8;
}
}
}

--
Andy Dougherty doug...@lafayette.edu

Leopold Toetsch

unread,
May 30, 2006, 4:53:13 PM5/30/06
to perl6-i...@perl.org, bugs-bi...@netlabs.develooper.com

On May 30, 2006, at 17:32, Andy Dougherty (via RT) wrote:

> However, if the intent is not to
> guarantee initialization, then I'd recommend something like this second
> patch be put in place, at least for a while, to ensure no programs are
> relying on automatic initialization.

Last time this came up the intent was: Parrot doesn't gurantee I/N
register to be initialized (it has to do that for P/S registers though,
to keep the garbage collector happy).

leo

Leopold Toetsch

unread,
Jun 5, 2006, 7:08:34 AM6/5/06
to perl6-i...@perl.org, bugs-bi...@netlabs.develooper.com

On May 30, 2006, at 17:32, Andy Dougherty (via RT) wrote:

>
> The second patch changes the initial value to a different non-zero
> value. This is useful for ferreting out hidden assumptions.


Applied now both (slightly modified: C<if> is pulled out of the loops).

I and N registers are never set to 0 / 0.0 on subroutine entry.

Thanks for the patch,
leo

0 new messages