# Ruby extension with vararg function woes

**URL:** <https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236>\
**Category:** Ruby\
**Created:** [July 24, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236 "2007-07-24T15:14:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 24, 2007, 3:14pm UTC](https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236/1 "2007-07-24T15:14:17Z")

</div>

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  
🙂

Thanks for any help. - Tom.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 24, 2007, 8:41pm UTC](https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236/2 "2007-07-24T20:41:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 25, 2007, 3:02am UTC](https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236/3 "2007-07-25T03:02:38Z")

</div>

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()?

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [July 25, 2007, 7:16pm UTC](https://www.ruby-forum.com/t/ruby-extension-with-vararg-function-woes/110236/4 "2007-07-25T19:16:23Z")

</div>

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.
