module documentation
Build a c-extension module on-the-fly in tests. See build_and_import_extensions for usage hints
Function | build |
cd into the directory where the cfile is, use distutils to build |
Function | build |
Build and imports a c-extension module modname from a list of function fragments functions . |
Function | compile |
Build an extension module and return the filename of the resulting native code file. |
Function | get |
Undocumented |
Function | _c |
Undocumented |
Function | _convert |
Helper function to create a file source.c in dirname that contains the string in source . Returns the file name |
Function | _make |
Turns the name, signature, code in functions into complete functions and lists them in a methods_table. Then turns the methods_table into a PyMethodDef structure and returns the resulting code fragment ready for compilation... |
Function | _make |
Combines the code fragments into source code ready to be compiled |
def build(cfile, outputfilename, compile_extra, link_extra, include_dirs, libraries, library_dirs):
(source)
¶
cd into the directory where the cfile is, use distutils to build
def build_and_import_extension(modname, functions, *, prologue='', build_dir=None, include_dirs=[], more_init=''):
(source)
¶
Build and imports a c-extension module modname
from a list of function
fragments functions
.
Examples
>>> functions = [("test_bytes", "METH_O", """ if ( !PyBytesCheck(args)) { Py_RETURN_FALSE; } Py_RETURN_TRUE; """)] >>> mod = build_and_import_extension("testme", functions) >>> assert not mod.test_bytes(u'abc') >>> assert mod.test_bytes(b'abc')
Parameters | |
modname | Undocumented |
functions:list of fragments | Each fragment is a sequence of func_name, calling convention, snippet. |
prologue:string | Code to precede the rest, usually extra #include or #define macros. |
buildpathlib.Path | Where to build the module, usually a temporary directory |
includelist | Extra directories to find include files when compiling |
morestring | Code to appear in the module PyMODINIT_FUNC |
Returns | |
module | out - The module will have been loaded and is ready for use |
def compile_extension_module(name, builddir, include_dirs, source_string, libraries=[], library_dirs=[]):
(source)
¶
Build an extension module and return the filename of the resulting native code file.
Parameters | |
name:string | name of the module, possibly including dots if it is a module inside a package. |
builddir:pathlib.Path | Where to build the module, usually a temporary directory |
includelist | Extra directories to find include files when compiling |
source | Undocumented |
libraries:list | Libraries to link into the extension module |
librarylist | Where to find the libraries, -L passed to the linker |
Helper function to create a file source.c in dirname
that contains
the string in source
. Returns the file name