Hi Brian,

thank you for your fast response.

On Mon, Jan 01 2001, Brian Ingerson wrote:
> > 
> >  o In the C-Cookbook you state that "a variable length argument list"
> >    must contain at least one element.  But with the XS interface it is
> >    possible to specify an empty list.  Well, for the moment I have a
> >    workaround but I just wonder if this restriction will stay for ever ?
> 
> To indicate a variable list in C you say something like:
> 
>      int foo(long bar, ...) {
> 
> But (on my compiler at least) this is invalid:
> 
>      int foo(...) {
> 
> And since the XS I generate does the parameter checking, I can't do this 
> and actually pass in values:
> 
>      int foo() {

Well, in my old XS version I have the following code:

   int32
   afs_raise_exception(...)
      CODE:
      {
           int32 flag;

           if (items >1) croak("Usage: AFS::raise_exception(flag)");
           if (items==1) {
              flag = (int)SvIV(ST(0));
              raise_exception = (flag != 0);
           }
           RETVAL = raise_exception;
       }
     OUTPUT:
           RETVAL

and I get this C code:

   XS(XS_AFS_raise_exception)
   {
       dXSARGS;
       {
           int32   RETVAL;
   #line 3964 "AFS.xs"
      {
           int32 flag;

           if (items >1) croak("Usage: AFS::raise_exception(flag)");
           if (items==1) {
              flag = (int)SvIV(ST(0));
              raise_exception = (flag != 0);
           }
           RETVAL = raise_exception;
       }
   #line 6009 "AFS.c"
           ST(0) = sv_newmortal();
           sv_setiv(ST(0), (IV)RETVAL);
       }
       XSRETURN(1);
   }

I never looked very close under the hood of XS.  I just thought if the
"standard" XS code is able to make it, maybe "your" XS code might be
able too   :-)

> The other problem is that I generate special C code when I see '...', to 
> keep the stack pointers correct.
> 
> So what should I do? I guess the best way to fix this would be to always 
> allow stack handling in any function (generate the special code) and 
> turn off the XS parameter check (which I don't know how to do yet. do 
> you?) and allow this syntax to mean 'any number of parameters':
> 
>      int foo() {
> 
> Any other ideas?

I don't know whether all this trouble is it worthwhile at the moment.  I
think there are more important tasks to tackle at the moment.

> >  o If I make use of the possibility to have multiple Inline C sections I
> >    get a problem.  In order to demonstrate it, I have prepared a very
> >    simple test case. In the first section I specify a C function and in
> >    the second section I specify a second C function which is calling the
> >    first function.  I also call that first C function from the Perl
> >    code.  The call from the Perl code is working.  Then I call the
> >    second C function from the Perl code which is finally calling the
> >    first C function.  As soon as the first C function is called from the
> >    second C function I get an error that this function is "an undefined
> >    symbol".  The reason is that each C section is stored in a separate
> >    object library.
> 
> I found this out a long time ago. I call it a 'feature' ;-)
> (It allows you keep your functions seperated from each other.)
> 
> I'd be interested in knowing why you want to do this. Your functions are 
> all available from Perl. Why do they need to access each other? And if 
> they do, why can't they all be in one C section instead of two or more? 
> I'm not doubting you, I just want the rationale. That way I can make 
> better design decisions.

Well, let me explain you my motivation.  I have one C function called
'set_code' which fills the return code from an AFS system call into a
Perl variable like the example in "perlguts", paragraph "Double-Typed
SVs", example 'Perl variable called "dberror"'.  And I have a couple
of AFS Perl modules which call AFS C system calls.  After each system
call I use the C function 'set_code' to store the actual AFS C system
return code.

In the old days, I had one XS module containing this C function
'set_code' and all other C functions for the different AFS Perl
modules. Therefore it was possible that all the different 
"XS C module package" functions called the same C function 'set_code'

But now, using Inline, I would like to split this big XS module and
put the appropriate C parts into its own Perl modules.  This means that
each individual module contains in its C part a call to this function
'set_code'.  Now I have two choices. Either I include the function
'set_code' in each module's C part or I have it in one module and call
it from all the other modules.

I would prefer the second choice, but I don't know how to do this at
the moment   :-(

> I think this is a Dynaloader issue. You need to set certain Dynaloader 
> options to allow functions in separate modules to see each other. 
> (hopefully portably) If you can find out what these Dynaloader flags 
> are, I'll add them to the configuration options. (Try doing a simple 
> example in XS with 2 different modules)

Fine, I will check the Dynaloader docs and try to find out how we can
solve this problem.  

Cheers,

Norbert
-- 

Reply via email to