[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] foreign functions, swig
From: |
John Lenz |
Subject: |
Re: [Chicken-users] foreign functions, swig |
Date: |
Sun, 21 May 2006 17:30:53 -0500 |
On Sat, 2006-05-20 at 14:18 -0700, Dan wrote:
> Thanks. I ended up writing SWIG typemaps (which I'm
> providing below, for those interested; no checks for
> now). I really think these should have been provided
> by SWIG, though...
> typedef unsigned int size_t;
You can do something like %apply unsigned int size_t; as well
>
> %typemap(in) float * {
> $1 = C_c_f32vector_or_null ($input);
> }
>
> %typemap(in) double * {
> $1 = C_c_f64vector_or_null ($input);
> }
>
> %typemap(in) int * {
> $1 = C_c_s32vector_or_null ($input);
> }
>
> %typemap(in) unsigned * {
> $1 = C_c_u32vector_or_null ($input);
> }
>
> %typemap(in) long * {
> $1 = C_c_s32vector_or_null ($input);
> }
>
> %typemap(in) unsigned long * {
> $1 = C_c_u32vector_or_null ($input);
> }
I was thinking about these, and I think should define something like
%typemap(in) unsigned int *u32vector {
$1 = C_c_u32vector_or_null($input);
}
(That is, give the typemap a name of u32vector.) Then to use the
typemap, you need to do something like
%apply unsigned int *u32vector { unsigned int *vec };
void test(unsigned int *vec) {
...
}
And then optionally %clear unsigned int *vec;
This way, including srfi4.i does not corrupt the global namespace of
typemaps. If you actually want to pass a double * somewhere as an
actual pointer, and not an array, you don't have to do anything. This
is how argout/argin typemaps work, you apply the unsigned int *OUTPUT
typemap to whatever you want to be an output argument.
If you just want to apply the typemap to everything, you can do
something like
%clear unsigned int *;
%apply unsigned int *u32vector { unsigned int * };
(You need the clear because %apply never overwrites existing typemaps)
What do you think about using this kind of interface?
John