# The following was supposedly scribed by
# Sisyphus
# on Saturday 21 August 2004 06:44 pm:

>In reality, I would like to wrap the GMP library's gmp_printf function.
>That function is analogous to C's printf function - it takes a 'char *
>format' as its first argument, followed by however many GMP objects as
>subsequent arguments. If I can work out how to wrap printf/vprintf, then
>(I hope) it will not be difficult to adapt that process to wrapping
>gmp_printf/gmp_vprintf.

Okay, but if they are all the same type of objects, you are basically only 
trying to wrap something like printf("%s %s %s %s", s1, s2, s3, s4) and we 
can forget about trying to detect integers vs floats and strings.

In the general "replicate printf" case, you are going to have to do a lot more 
work, and it almost seems that you have to parse the format do decide how to 
convert the arguments (isn't that what the stdio printf does? (except it 
would just be casting instead of mapping types))

>> The Inline::C-Cookbook has a good example for using Inline_Stack_Vars and
>> such to deal with arrays, but the generic printf emulation implies a lot
>> more about typemaps and unpacking each element of the list.
>
>Hmmm .... I've been starting to fear that there's going to be much more
>to this than I originally thought. The last part of that sentence does
>little to allay that fear :-)

Except, you have just said that you don't have to deal with typemaps.  
Everything is a GMP object (so, presumably, this is a blessed reference to a 
scalar which is the pointer's address?)  In any case, it's not a 
guess-my-type issue any more (which it is with printf.)

So, you need a function or macro which converts or casts one perl type into a 
C type, and some way to put that into the va_list.  I currently know nothing 
about va_list, but it looks like this needs to fetch a variable list of 
arguments from the list that came into the function.  That's not really what 
you want.

You want your perl-accessible function to use Inline_Stack_Item(i) to fetch 
the perl variables, but then you need to convert (unpack) each of these into 
a C variable (address?) and add them to some kind of list which you can use 
in the printf call.  From the looks of it, that's what you're working on, but 
you can't expect Inline to auto-typemap the arguments to a vararg function.

--Eric
-- 
"...our schools have been scientifically designed to 
prevent overeducation from happening."
                                        --William Troy Harris

Reply via email to