help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re : Re : Re : [Help-smalltalk] How to convert a Cobject in C


From: Mathieu Suen
Subject: Re : Re : Re : [Help-smalltalk] How to convert a Cobject in C
Date: Tue, 24 Aug 2010 13:01:08 +0000 (GMT)




----- Message d'origine ----
> De : Paolo Bonzini <address@hidden>
> À : Mathieu Suen <address@hidden>
> Cc : address@hidden
> Envoyé le : Mar 24 août 2010, 14h 39min 18s
> Objet : Re: Re : Re : [Help-smalltalk] How to convert a Cobject in C
> 
> On 08/24/2010 01:37 PM, Mathieu Suen wrote:
> > So I used the  _gst_oop_to_c_object but my object have one more instance
> >  variable:
> >
> > CStruct subclass: CJitState [
> >        | codeBuffer |
> >       ...snip...
> >  ]
> >
> > So the function _gst_oop_to_c_object does not return the  expected 
structure.
> 
> _What_ is the expected structure?  "jitState  codeBuffer", or "jitState 
> address"?  _gst_oop_to_c_object returns the  latter.  That works even if 
> you have other instance variables in  it.

Ok,
So if this is it the case I got an issue. :(
In C I have the following code:

typedef struct _jit_stack
{
  jit_state state;
  jit_insn *codeBuffer;
} jit_stack;

...
jitMethod = (gst_jit_method)OOP_TO_OBJ(methodOOP);
stack = (jit_stack*)_gst_oop_to_c_object(jitMethod->jitState);
methodFct = (pvf)stack->codeBuffer;
methodFct();
...

But when I am seatting in gdb an inspect the stack I got the following:
(gdb)  x/8wx 0x82c5880
0x82c5880:    0x082d591c    0x00000000    0x00000014    0x00000000
0x82c5890:    0x00000000    0x00000000    0x082d58a8    0x00000031

The codeBuffer is at 0x082d58a8 which is the 0x18(0x82c5880)
But the assembly at the point of methodFct(); I got:

call   *0x14(%eax) // %eax = 0x82c5880

The correct code should be 

call   *0x18(%eax)


The CJitState is create with a cCall:

jit_stack *
alloc_jit_state (size_t insnSize)
{
  jit_stack *new_jit_stack;
  new_jit_stack = calloc (1, sizeof (*new_jit_stack));
  new_jit_stack->state.x.pc = new_jit_stack->codeBuffer =
    calloc (insnSize, sizeof (*(new_jit_stack->codeBuffer)));
  return new_jit_stack;
}

And in st:
CJitState class >> primAlloc: nByte [
    "Allocate a new jit_state that hold the assembly code"
    <category: 'primitive allocation'>

    <cCall: 'lightningAllocJitState' returning: #{CJitState} args: #(#ulong)>
    ]

i don't know what cause the structure to change.
Thanks

> 
> Paolo
> 






reply via email to

[Prev in Thread] Current Thread [Next in Thread]