How to convert a Cobject in C

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

How to convert a Cobject in C

Mathieu Suen-2

Hi,

I got on object in C that come from smalltalk.
It is a subclass of a CStruct.

Now in the VM I got an OOP.
How do I get back the C structure.
I am not inside a cCall or a primitive.

Thanks

Mathieu





_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: How to convert a Cobject in C

Paolo Bonzini-2
On 08/24/2010 11:05 AM, Mathieu Suen wrote:
>
> Hi,
>
> I got on object in C that come from smalltalk.
> It is a subclass of a CStruct.
>
> Now in the VM I got an OOP.
> How do I get back the C structure.

vmProxy->OOPToCObject, or gst_oop_to_cobject, depending on whether
you're in a module or you're the one linking to libgst.

> I am not inside a cCall or a primitive.

Where are you? :)

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Mathieu Suen-2
----- Message d'origine ----

> De : Paolo Bonzini <[hidden email]>
> Objet : Re: [Help-smalltalk] How to convert a Cobject in C
>
> On 08/24/2010 11:05 AM, Mathieu Suen wrote:
> >
> > Hi,
> >
> >  I got on object in C that come from smalltalk.
> > It is a subclass of a  CStruct.
> >
> > Now in the VM I got an OOP.
> > How do I get back  the C structure.
>
> vmProxy->OOPToCObject, or gst_oop_to_cobject,  depending on whether
> you're in a module or you're the one linking to  libgst.
>
> > I am not inside a cCall or a primitive.
>
> Where are  you? :)

:)
I am inside the _gst_send_message_internal.
I go look how  OOPToCObject is implement.


Thanks

>
> Paolo
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Mathieu Suen-2


> > De : Paolo Bonzini <[hidden email]>

> > On 08/24/2010  11:05 AM, Mathieu Suen wrote:
> > >
> > > Hi,
> > >
> >  >  I got on object in C that come from smalltalk.
> > > It is a  subclass of a  CStruct.
> > >
> > > Now in the VM I got an  OOP.
> > > How do I get back  the C structure.
> >
> >  vmProxy->OOPToCObject, or gst_oop_to_cobject,  depending on whether
> > you're in a module or you're the one linking to  libgst.
> >
> > > I am not inside a cCall or a primitive.
> >
> > Where  are  you? :)
>
> :)
> I am inside the _gst_send_message_internal.
> I  go look how  OOPToCObject is implement.

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.
Instead I have one more
field in the structure.
So the cast don't work in C:

stack = (jit_stack*)_gst_oop_to_c_object(jitMethod->jitState);

What is the proper way of dealing with that?

I could just use:
(jit_stack*)_gst_oop_to_c_object(jitMethod->jitState)+1;

But don't know if is it a good idea.

Thanks


>
>
> Thanks
>
> >
> > Paolo
> >
>
>
> _______________________________________________
> help-smalltalk  mailing list
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Paolo Bonzini-2
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.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Mathieu Suen-2




----- Message d'origine ----

> De : Paolo Bonzini <[hidden email]>
> À : Mathieu Suen <[hidden email]>
> Cc : [hidden email]
> 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
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Mathieu Suen-2
Paolo help me to find the bug.
It was a faulty declaration of the jit_local_state.

But now there is conflit beween the jit_local_state from gst and the one from
gnu lightning.
For example in i386 arch the gnu lightning jit_local_state is:

struct jit_local_state {
  int    framesize;
  int    argssize;
  int    alloca_offset;
  int    alloca_slack;
};

will in gst it is:

struct jit_local_state {
  int    framesize;
  int    argssize;
}

So shouold it be fixed?

Thanks



----- Message d'origine ----

> > 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...
> > >  ]
> > >
> _______________________________________________
> help-smalltalk  mailing list
> [hidden email]
> http://lists.gnu.org/mailman/listinfo/help-smalltalk
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Paolo Bonzini-2
On 08/24/2010 04:34 PM, Mathieu Suen wrote:

> Paolo help me to find the bug.
> It was a faulty declaration of the jit_local_state.
>
> But now there is conflit beween the jit_local_state from gst and the one from
> gnu lightning.
> For example in i386 arch the gnu lightning jit_local_state is:
>
> struct jit_local_state {
>    int    framesize;
>    int    argssize;
>    int    alloca_offset;
>    int    alloca_slack;
> };
>
> will in gst it is:
>
> struct jit_local_state {
>    int    framesize;
>    int    argssize;
> }

This is not in gst, it is in your version of gst.

If it is so tied to lightning, it should just include lightning.h and
not meddle with these problems.

Alternatively, use

struct _jit_stack {
     jit_insn *codeBuffer;
     jit_state state;
}

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

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

Mathieu Suen-2
> De : Paolo Bonzini <[hidden email]>

> This is not in gst, it is in your version of gst.
>
> If it is so  tied to lightning, it should just include lightning.h and
> not meddle with  these problems.

Actually I did include lightning.h but for some reason I got some dirty file
hanging arround.
So the lightning.h file was not the right one.

With a clean it work perfectly :)
Thanks for the indication.

>
> Alternatively, use
>
> struct _jit_stack {
>       jit_insn *codeBuffer;
>      jit_state  state;
> }
>
> Paolo
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk