c-call-out and c-call-in with struct.

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

c-call-out and c-call-in with struct.

Mathieu Suen-2
Hi All,

Will writing the objc binding I bump into a issue regarding c struct as
parameter and return value.
For example the NSView>>#bounds return a NSRect and
NSWindow>>#initWithContentRect:styleMask:backing:defer:
take a NSRect as first parameter.

I have a quick look at ffi to see if pass-by-value of a struct (with a size
grater than 8bit) was available

and on OSX 64bit the answer is yes for parameter. I didn't make the test for
return value.

Now in gst everything is bound to a cparam so that is going to make a lot of
refactoring in other to have c struct pass-by-value.

So what do you think.
I am ready to make the change if that's worth it.

Mathieu




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

Re: c-call-out and c-call-in with struct.

Paolo Bonzini-2
On 02/22/2011 03:47 PM, Mathieu Suen wrote:
> I have a quick look at ffi to see if pass-by-value of a struct (with a size
> grater than 8bit) was available

How do you do that?  (Serious question, I'm busy so I'm not looking it
up right now).

> Now in gst everything is bound to a cparam so that is going to make a lot of
> refactoring in other to have c struct pass-by-value.

This may or may not be true depending on the answer to question 1...

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] c-call-out and c-call-in with struct.

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

> De : Paolo Bonzini <[hidden email]>
> À : Mathieu Suen <[hidden email]>
> Cc : [hidden email]
> Envoyé le : Mar 22 février 2011, 16h 52min 43s
> Objet : Re: [Help-smalltalk] c-call-out and c-call-in with struct.
>
> On 02/22/2011 03:47 PM, Mathieu Suen wrote:
> > I have a quick look at ffi  to see if pass-by-value of a struct (with a size
> > greater than 8bit) was  available
>
> How do you do that?  (Serious question, I'm busy so I'm  not looking it up
>right now).


I have made a small test:

#include <stdlib.h>
#include <ffi.h>
#include <stdio.h>

typedef struct rect {

  double f;
  double g;
  double h;

} rect;

void
foo (rect argStruct)
{
  printf ("Receive a strcut by value f=%f, g=%f, h=%f\n", argStruct.f,
argStruct.g, argStruct.h);
}


int
main ()
{
  int i;
  ffi_cif cif;
  ffi_type * arg[1];
  ffi_type structType;
  ffi_type * element[4];
  void * value[1];
  rect aStruct;
  arg[0] = &structType;
  structType.size = 0;
  structType.alignment = 0;

  value[0] = (void*)&aStruct;

  for (i = 0; i < 3; i++)
    element[i] = &ffi_type_double;
  element[3] = NULL;

  structType.elements = &element;

  if (ffi_prep_cif (&cif, FFI_DEFAULT_ABI, 1, &ffi_type_void, arg) == FFI_OK)
    {
      aStruct.g = 5.5;
      aStruct.h = 3.4;
      aStruct.f = 9.0;
      ffi_call (&cif, foo, NULL, value);
    }
  else
    {
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;
}

So for example all you have to do is to declare the struct like this:

  ffi_type structType;
  ffi_type * element[4];
  for (i = 0; i < 3; i++)
    element[i] = &ffi_type_double;

  element[3] = NULL;
  structType.elements = &element;

>
> > Now in gst everything is bound to a  cparam so that is going to make a lot
of
> > refactoring in other to have c  struct pass-by-value.
>
> This may or may not be true depending on the answer  to question 1...
>
> Paolo
>




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