Ruby extension with vararg function woes

I’m developing a port of Ruby for the Nokia internet tablets (N800
currently) with full bindings to the Maemo platform (hildon widgets,
libosso, etc). I’ve hit a couple of snags along the way, which basically
go like this:

I have a function I need to bind/wrap for ruby. It’s prototype is:

osso_return_t osso_rpc_async_run( osso_context_t*, const gchar*, const
gchar*, const gchar*, const gchar* osso_rpc_async_f*, gpointer, int, …
);

My question is this, how would I go about binding a function that has
varargs? That is, how would I go about calling a C function that has
varargs in it’s prototype, like ‘printf’ et al, and the example enough.
I’m baffled.

So I’ve come here hoping that someone might have a solution for me,
hopefully someone has encountered and conquered this problem for. It
seems like a pretty common thing. Obviously, my life and a lot of other
peoples would be easier if people just stopped with this varargs stuff
:slight_smile:

Thanks for any help. - Tom.

alter… wrote:

osso_return_t osso_rpc_async_run( osso_context_t*, const gchar*, const gchar*, const gchar*, const gchar* osso_rpc_async_f*, gpointer, int, … );

My question is this, how would I go about binding a function that has varargs? That is, how would I go about calling a C function that has varargs in it’s prototype, like ‘printf’ et al, and the example enough. I’m baffled.

Ask on news:comp.lang.c , because AFAIK there might be a system to
convert an array into an argument stack. It must naturally port to the
hardware stack.

And post more code, so you won’t get lifers whining that your question
dares to mention anything besides raw C. Put in enough code samples
that someone who didn’t know Ruby but did know varargs could help.
Provide, for example, some reckoning of how Ruby does a raw array.

Another suggestion: Look inside Ruby’s source for sprintf.

Hi,

At Wed, 25 Jul 2007 03:40:03 +0900,
Phlip wrote in [ruby-talk:261581]:

osso_return_t osso_rpc_async_run( osso_context_t*, const gchar*, const gchar*, const gchar*, const gchar* osso_rpc_async_f*, gpointer, int, … );

My question is this, how would I go about binding a function
that has varargs? That is, how would I go about calling a C
function that has varargs in it’s prototype, like ‘printf’ et
al, and the example enough. I’m baffled.

Ask on news:comp.lang.c , because AFAIK there might be a system to
convert an array into an argument stack. It must naturally port to the
hardware stack.

No portable way, AFAIK. And even if there is a such way, it
would need va_list version of the function.

And post more code, so you won’t get lifers whining that your question
dares to mention anything besides raw C. Put in enough code samples
that someone who didn’t know Ruby but did know varargs could help.
Provide, for example, some reckoning of how Ruby does a raw array.

Another suggestion: Look inside Ruby’s source for sprintf.

Which do you mean rb_f_sprintf(), or vsnprintf()?

Nobuyoshi N. wrote:

No portable way, AFAIK. Â And even if there is a such way, it
would need va_list version of the function.

That’s why the OP needs to find a non-portable way, for that Nokia
gizmo.
The C newsgroup is still the best bet, because the Ruby side is less
important.

Another suggestion: Look inside Ruby’s source for sprintf.

Which do you mean rb_f_sprintf(), or vsnprintf()?

At the time, I meant Ruby’s own sprintf(), because I guessed it jumped
into
vsnprintf(). Like I posted here, it don’t, so don’t look there. Maybe
nothing in Ruby’s source code exploits any C varargs the way the OP
needs.