Dear Ladies and Gentlemen,

I am writing to ask some advice about returning a variable number of
results from an XS in which the callled C function has a (callback)
function pointer argument that it calls to produce the results.

The situation is this,

/* callback */

void server_fn(struct print_job_info *p) {

  printf()              /* I would like this to replaced by 
                           pushing the formatted string onto the Perl 
                           stack.

                        eg XPUSHs(sv_2mortal(newSVpvf()))

                        */
}

/* This is the function wrapped by the XS */

int cli_print_queue(struct cli_state *cli, 
                    void (*fn)(struct print_job_info *))

It seems to me that 

1 I can only return results to Perl by an explicit XSRETURN(items) after 
the XPUSHs. 

Therefore I have to accumulate the number of XPUSHs in a global variable 
updated by the C callback (server_fn() above)).

Is that correct ?

2 Otherwise, the C callback should either 

2.1 update a global C structure that will then be accessed by the 
calling XS (cli_print_queue)

2.2 update a global Perl structure (eg an AV *) that will be returned by 
the calling XS

What is 'the recommended way' or what are some of the less obvious 
tradeoffs in each of these ways ?

Thank you,
 -- 
------------------------------------------------------------------------
Stanley Hopcroft
------------------------------------------------------------------------

'...No man is an island, entire of itself; every man is a piece of the
continent, a part of the main. If a clod be washed away by the sea,
Europe is the less, as well as if a promontory were, as well as if a
manor of thy friend's or of thine own were. Any man's death diminishes
me, because I am involved in mankind; and therefore never send to know
for whom the bell tolls; it tolls for thee...'

from Meditation 17, J Donne.

Reply via email to