Writing C Modules with XS
    // store the key/value pair in
    hv_store(hv, key, strlen(key), value, 0);
  }
  // return a reference to the new hash
  RETVAL = newRV_noinc((SV *)hv);
OUTPUT:
  RETVAL
CLEANUP:
  g_list_free(keys);
The XSUB starts with a return type of SV:
SV *
type_data(type)
  const gchar * type
Since the subroutine will return a reference to a hash, the return type must be 
SV*. Next, several local variables are declared in a PREINIT block, including two 
GLists. The GList type is the Gnome API's linked list type. The CODE body starts by 
initializing the HV that will be returned to the user:
  // initialize hash
  hv = newHV();
Next, I call gnome_mime_get_keys() and begin iterating over the GList:
  // get GList of keys for this type
  keys = gnome_mime_get_keys(type);
  // iterate through keys
  for (iter = keys; iter; iter = iter >next) {
    // get the key from the iterator
    key = iter >data;
If keys returns a NULL pointer, then this loop won't be executed, and an empty hash 
will be returned to the user. Next, the key value pairs are stored in the HV:
    // create a new SV and load it with the value for this key
    value = newSVpv(gnome_mime_get_value(type, key), 0);
   
    // store the key/value pair in
    hv_store(hv, key, strlen(key), value, 0);
22
227
7






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