xsubpp
Compile Perl XS code to C
SYNOPSIS
xsubpp [options] input.xs > output.c
PARAMETERS
-typemap file
Specifies a typemap file to use. Typemaps define the mappings between Perl data types and C data types.
-noprototypes
Suppresses the generation of C prototypes for the XS functions.
-known_typedef typedef
Declares a known typedef that xsubpp should not try to redefine.
-modules module_list
Specifies the Perl modules to include.
-blib
Adds the directories in @INC to the list of include directories.
-output file
Specifies the output file name instead of using standard output.
-package package_name
Sets the package name for the XS module.
DESCRIPTION
The xsubpp command is a preprocessor that converts Perl XS code into C code suitable for compilation and linking into Perl modules. It is a crucial part of the process for extending Perl's functionality with C code, allowing developers to create modules that provide access to system resources or optimized algorithms. xsubpp parses the XS file, extracts the subroutine definitions, and generates the necessary C code for Perl to interface with those subroutines. This includes argument parsing, data type conversion between Perl and C, and the necessary glue code to make the C functions callable from Perl. The generated C code can then be compiled and linked into a dynamically loadable Perl module (a .so or .dll file), which can be loaded and used within Perl scripts. xsubpp simplifies the process of writing Perl extensions, allowing developers to focus on the core C functionality rather than the boilerplate code required for the Perl interface.
XS FILE FORMAT
An XS file typically contains the package declaration, C code snippets, and the definition of the XS functions. The XS functions define the interface between Perl and the C code. xsubpp processes this file to generate the corresponding C code.
TYPEMAPS
Typemaps are essential for defining the mappings between Perl's data types (like SCALAR, ARRAY, HASH) and their C equivalents (e.g., int, char*, SV*). They allow for automatic conversion of data between Perl and C, simplifying the development of Perl extensions.
It's necessary to use compatible data types and have good error handling to prevent segfaults.
SEE ALSO
perlxs(1), perlxstut(1)