Nicholas Clark <[EMAIL PROTECTED]> wrote:
> On Thu, Mar 11, 2004 at 10:33:24PM +0100, Leopold Toetsch wrote:
>> All PMCs are anchored properly?

> Yes. Arthur and I got it down to the appended test case, which is pure C
> embedding and extending parrot.

I already had mailed earlier with Arthur about that very problem. Parrot
needs a stack_limit (interprer->lo_var_ptr) for stack tracing. This
includes tracing processor registers which are placed on the stach in
trace_system_areas(). When this stack limit isn't set, stack walking can
not be done and all PMCs in hardware CPU registers and on the stack are
missed, which normally leads to ugly DOD bugs - they are really hard to
trace down.

So you have two possibilities to set the stack limit:

  interpreter->lo_var_ptr = &interpreter; // a local in the outermost
                                          // stack frame

or better, you run all your code through the wrapper:

- Parrot_run_native()

which enters a run loop after doing normal initialization (which
includes setting up a Parrot_exception which is used for exception
handling. The ops that get run are "enternative <yourcode>" ; end; "

Below is a working revision of your code.

(I know, that extend.c is missing some bits but that shouldn't be the
problem, we have just to add it)

leo


/* Needed to turn off GC */
#if 1
#include "parrot/parrot.h"
#endif

#include "parrot/embed.h"
#include "parrot/extend.h"
#include <stdio.h>
#include <stdlib.h>


Parrot_PMC make_a_pmc(Parrot_Interp interpreter) {
  Parrot_Int  type = Parrot_PMC_typenum(interpreter, "Integer");
  Parrot_PMC  p;

  p = Parrot_PMC_new(interpreter, type);
  Parrot_register_pmc(interpreter, p);
  return p;
}

static opcode_t*
run( Parrot_Interp interpreter, opcode_t *cur_op, opcode_t *start)
{
    int count = REG_INT(5); // fake argv passing - its normally P5
    printf ("Hello world %d\n", count);
    while (count--) {
        if (! (count & 0xfff)) {
            printf(".");
            fflush(stdout);
        }

        make_a_pmc(interpreter);
    }

    printf ("Goodbye world\n");
    return NULL;
}

int
main (int argc, char**argv) {
    int count;
    Parrot_Interp interpreter = Parrot_new(0);
    Parrot_init(interpreter);

#if 0
    /* Turn off GC  */
    interpreter->DOD_block_level++;
    interpreter->GC_block_level++;
#endif

    if (argc > 1) {
        count = atoi(argv[1]);
    } else {
        count = 1000000;
    }
    REG_INT(5) = count ; // fake argv passing
    Parrot_run_native(interpreter, run);
    Parrot_exit(0);
    return 0;
}

/* Compile with
  gcc -Iinclude -Wall -o stress_parrot stress_parrot.c blib/lib/libparrot.a
  -lm -ldl -lpthread # Don't need these on *BSD :-)
*/

Reply via email to