Writing C Modules with XS
  // free glist passed into function
  g_list_free(list);
  // return a reference to the new array
  return sv_2mortal(newRV_noinc((SV *)av));
}
The code for the function should be easy enough to understand. It simply 
takes a GList* and adds each data item contained inside to an array, returning a 
new mortal reference to the array constructed. Notice that the function also frees 
the GList*:
  // free glist passed into function
  g_list_free(list);
This could just as well have been done in a CLEANUP block, but putting it in the 
typemap function provides the cleanest access for the XSUB.
With this XSUB in place, the test code is updated to use the new interface:
# test get_keys and get_value
$keys = Gnome::MIME::get_keys("image/gif");
isa_ok($keys,  ARRAY , "get_keys return");
foreach $key (@$keys) {
  ok(Gnome::MIME::get_value("image/gif", $key), "got value for \"$key\"");
}
The best way to learn to program typemaps is to examine the typemaps that 
come with Perl. You'll find them in a file called typemap in the library directory 
where the ExtUtils modules are installed. On my system, the path to typemap is 
/usr/lib/perl5/5.6.1/ExtUtils/typemap, but different platforms will place the file 
in different locations.
Learning More about XS
The examples in this chapter have explored many useful XS programming tech 
niques. However, there are many useful commands and options that I didn't have 
space to cover. Included with Perl is perlxstut, a tutorial that covers much the 
same ground as this chapter. Also included with Perl is perlxs, an exhaustive ref 
erence to all of XS.
23
235
5






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