Wrapping and Linking

codepy.jit – Compilation and Linking of C Source Code

class codepy.jit.Toolchain(*args, **kwargs)

Abstract base class for tools used to link dynamic Python modules.

copy(**kwargs)
get_version()

Return a string describing the exact version of the tools (compilers etc.) involved in this toolchain.

Implemented by subclasses.

abi_id()
Return a picklable Python object that describes the ABI (Python version, compiler versions, etc.) against which a Python module is compiled.
add_library(feature, include_dirs, library_dirs, libraries)

Add include_dirs, library_dirs and libraries describing the library named feature to the toolchain.

Future toolchain invocations will include compiler flags referencing the respective resources.

Duplicate directories are ignored, as will be attempts to add the same feature twice.

build_extension(ext_file, source_files, debug=False)

Create the extension file ext_file from source_files by invoking the toolchain. Raise CompileError in case of error.

If debug is True, print the commands executed.

Implemented by subclasses.

class codepy.jit.GCCToolchain(*args, **kwargs)
Bases: codepy.jit.Toolchain
codepy.jit.guess_toolchain()

Guess and return a Toolchain instance.

Raise ToolchainGuessError if no toolchain could be found.

codepy.jit.extension_file_from_string(toolchain, ext_file, source_string, source_name='module.cpp', debug=False)

Using toolchain, build the extension file named ext_file from the source code in source_string, which is saved to a temporary file named source_name. Raise CompileError in case of error.

If debug is True, show commands involved in the build.

codepy.jit.extension_from_string(toolchain, name, source_string, source_name='module.cpp', cache_dir=None, debug=False, wait_on_error=None, debug_recompile=True)

Return a reference to the extension module name, which can be built from the source code in source_string if necessary. Raise CompileError in case of error.

Compiled code is cached in cache_dir and available immediately if it has been compiled at some point in the past. Compiler and Python API versions as well as versions of include files are taken into account when examining the cache. If cache_dir is None, a default location is assumed. If it is False, no caching is performed. Proper locking is performed on the cache directory. Simultaneous use of the cache by multiple processes works as expected, but may lead to delays because of locking.

The code in source_string will be saved to a temporary file named source_name if it needs to be compiled.

If debug is True, commands involved in the build are printed.

If wait_on_error is True, the full path name of the temporary in which a CompileError occurred is shown and the user is expected to press a key before the temporary file gets deleted. If wait_on_error is None, it is taken to be the same as debug.

If debug_recompile, messages are printed indicating whether a recompilation is taking place.

Errors

exception codepy.jit.CompileError
exception codepy.jit.ToolchainGuessError

codepy.bpl – Support for Boost.Python

Convenience interface for using CodePy with Boost.Python.

class codepy.bpl.BoostPythonModule(name='module', max_arity=None, use_private_namespace=True)
add_function(func)
Add a function to be exposed. func is expected to be a codepy.cgen.FunctionBody.
add_struct(struct, py_name=None, py_member_name_transform=<function <lambda> at 0x43017d0>)
add_to_init(body)
Add the blocks or statements contained in the iterable body to the module initialization function.
add_to_module(body)
Add the codepy.cgen.Generable instances in the iterable body to the body of the module self.
add_to_preamble(pa)
compile(toolchain, **kwargs)
Return the extension module generated from the code described by self. If necessary, build the code using toolchain with codepy.jit.extension_from_string(). Any keyword arguments accept by that latter function may be passed in kwargs.
generate()
Generate (i.e. yield) the source code of the module line-by-line.

Table Of Contents

Previous topic

codepy.cgen – C-Generation Reference Documentation

Next topic

License

This Page