#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    Prague, Czech Republic
    Posts
    868
    Rep Power
    70

    Perl XS and null argument values


    I need to write an interface to a tiny C library provided a collegue of mine.
    I began to write the code like this:
    Code:
    int
    verify(char *datafile,char *signfile,char *cacert);
        CODE:
              RETVAL=CLIB_verify(datafile,signfile,cacert);
        RETURN:
              RETVAL;
    The trouble is with the NULL argument values which are not passed as NULL, but rather as empty (zero length).

    1. How can I pass NULL argument values to the C function of CLIB_verify?
    2. Is there a way to convert such zero length values to NULL centrally. Eg. in a typemap or do I have to declare/convert in every function where required?

    Thank you.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2003
    Location
    Prague, Czech Republic
    Posts
    868
    Rep Power
    70
    I have found a (so far) working solution like this:
    Code:
    int
    verify(datafile,signfile,cacert);
        char * datafile = SvOK(ST(0)) ? SvPV_nolen(ST(0)) : NULL;
        char * signfile = SvOK(ST(1)) ? SvPV_nolen(ST(1)) : NULL;
        char * cacert = SvOK(ST(2)) ? SvPV_nolen(ST(2)) : NULL;
        CODE:
              RETVAL=CLIB_verify(datafile,signfile,cacert);
        RETURN:
              RETVAL;
    Someone having another and better solution, please reply to this. I'll glad.
    Thank you.

IMN logo majestic logo threadwatch logo seochat tools logo