Writing C Modules with Inline::C
  // call the appropriate function based on arguments
  if (read_file && default_type != NULL)
    return gnome_mime_type_or_default_of_file(filename, default_type);
  if (read_file)
    return gnome_mime_type_of_file(filename);
  if (default_type != NULL)
    return gnome_mime_type_or_default(filename, default_type);
  return gnome_mime_type(filename);
}
This function is very similar to the XS implementation introduced earlier, but 
there are some significant differences. First, the function's signature is different:
char * file_type (SV *dummy, ...) {
The dummy argument is required by Inline::C; due to the way it compiles C code to 
XS, it won't allow an argument list of ( . . . ) like the XS implementation uses. 
This makes it impossible to create an Inline::C function that can take zero or more 
parameters. I expect this limitation to be removed in a future version of Inline::C.
Next, a special Inline::C macro is used to initialize some temporary variables 
employed by the other Inline::C stack macros:
  Inline_Stack_Vars;         // get access to the Inline stack macros
These macros are included in the block of code following the variable 
declarations:
  // loop over args by pairs and fill in parameters
  for (x = 0; x < Inline_Stack_Items; x+=2) {
    char *key = SvPV(Inline_Stack_Item(x), PL_na);
    if (strEQ(key, "filename")) {
      filename = SvPV(Inline_Stack_Item(x+1), PL_na);
    } else if (strEQ(key, "default_type")) {
This block of code uses Inline_Stack_Items where the XS code used items, and 
Inline_Stack_Item where the XS code used ST. Their meaning is the same though, 
and they can be used interchangeably in Inline::C code.
The final change is that with the absence of the RETVAL special variable the 
control flow in the final section is simplified. The function simply returns when it 
has found the correct function to call:
  // call the appropriate function based on arguments
  if (read_file && default_type != NULL)
    return gnome_mime_type_or_default_of_file(filename, default_type);
24
247
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