Chapter 9
Listing 9 5. C Function Generated by xsubpp for gnome_mime_type() XSUB
XS(XS_Gnome__MIME_gnome_mime_type)
{
    dXSARGS;
    if (items != 1)
               Perl_croak(aTHX_ "Usage: Gnome::MIME::gnome_mime_type(filename)");
    {
               char *         filename = (char *)SvPV(ST(0),PL_na);
               char *         RETVAL;
               dXSTARG;
               RETVAL = gnome_mime_type(filename);
      sv_setpv(TARG, RETVAL); XSprePUSH; PUSHTARG;
    }
    XSRETURN(1);
}
XSUB Techniques
The XSUB shown earlier is about as simple as an XSUB can be. However, there are 
many useful changes that can be made to enhance the usability and functionality 
of XSUBs.
Types and Typemaps
You might have noticed that the types used in the gnome_mime_type() XSUB 
are subtly different from those used in the actual function signature. In the 
gnome_mime_type() function, the return type is a const char * and the filename 
argument type is const gchar *, whereas the XSUB used char * for both. This was 
done because XS comes with a typemap for char *, but doesn't know anything 
about const char * and const gchar *. A typemap is a description of how to map 
Perl types to and from C types.
If you try to use the real types in an XSUB as follows:
const char *
gnome_mime_type(filename)
     const gchar *filename
216






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

web hosting perl

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved