Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 5th, 2013, 04:24 AM
zby zby is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: Prague, Czech Republic
Posts: 867 zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 23 h 41 m 23 sec
Reputation Power: 69
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.

Reply With Quote
  #2  
Old February 5th, 2013, 06:45 AM
zby zby is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Jul 2003
Location: Prague, Czech Republic
Posts: 867 zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level)zby User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 23 h 41 m 23 sec
Reputation Power: 69
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Perl XS and null argument values

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap