Login  Register

binding a C functions that allocates two chunks of memory and returns an integer

Posted by a001 on Nov 30, 2011; 10:23am
URL: https://forum.jogamp.org/binding-a-C-functions-that-allocates-two-chunks-of-memory-and-returns-an-integer-tp3547863.html

Thanks for all the great work with JogAmp and GlueGen.

I have a C library (to be called from Java) and I would be happy to use GlueGen to automate the generation of the necessary Java and JNI code.

However, after looking to the GlueGen manual, I'm afraid I'm still missing something. I've noticed the examples you provide about how to manage ingoing and outgoing structs, array of structs, and array of pointers. They are great.

Still, I have not understood how to bind API like the following:

  struct foo_s;                        /* forward decl */
  typedef struct foo_s foo_t;

  int foo(foo_t **a, foo_t **b);

foo allocates two variables of type foo_t and places the addresses of allocated memory respectively in *a and *b. Returns zero on success, or one of the applicable error values on failure.

Please, can you tell me how to generate the glue code for this?

In the examples you provide I've noticed that all functions allocating memory return a pointer to some static storage and how the ReturnValueCapacity directive is used to specify the size of the returned memory.

What if we need to allocate two chunks of memory and return an integer? Do we need to hand-write some glue code?

Thanks again for GlueGen and I'm looking forward to using it in this project.

Cheers,
a.