§
y<ˆjˆ ã ó| — d Z ddlZddlZddlZddlZddgZddg ddœd„Zg g fd„Zd „ Zd
„ Z d„ Z
g g g fd„Zd
„ Zd„ Z
dS )zb
Build a c-extension module on-the-fly in tests.
See build_and_import_extensions for usage hints
é NÚbuild_and_import_extensionÚcompile_extension_moduleÚ )ÚprologueÚ build_dirÚinclude_dirsÚ more_initc ó¼ — ddl m} |t || ¦ « z }d}|st j d¦ « }|r
|dz
}||z
}|dz
}t | ||¦ « } t
| ||| ¦ « }
n!# |$ r}t d|› d�¦ « |‚d }~ww xY wdd l}|j
| |
¦ « }
|j |
¦ « }|
j
|¦ « |S )
a
Build and imports a c-extension module `modname` from a list of function
fragments `functions`.
Parameters
----------
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.
build_dir : pathlib.Path
Where to build the module, usually a temporary directory
include_dirs : list
Extra directories to find include files when compiling
more_init : string
Code to appear in the module PyMODINIT_FUNC
Returns
-------
out: module
The module will have been loaded and is ready for use
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')
r )ÚCompileErrorz8PyObject *mod = PyModule_Create(&moduledef);
ú.z.#define INITERROR return NULL
z
return mod;zcould not compile in ú:N)Údistutils.errorsr Ú
_make_methodsÚpathlibÚPathÚ_make_sourcer ÚRuntimeErrorÚimportlib.utilÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_module)ÚmodnameÚ functionsr r r r r ÚbodyÚinitÚ
source_stringÚmod_soÚeÚ importlibÚspecÚfoos ús/builddir/build/BUILD/cloudlinux-venv-1.0.12/venv/lib64/python3.11/site-packages/numpy/testing/_private/extbuild.pyr r s9 € ðN .Ð-Ð-Ð-Ð-Ð-à•m I¨wÑ7Ô7Ñ7€Dð€Dàð &Ý”L Ñ%Ô%ˆ Øð Øð ñ ˆà� ш؈OÑ€DÝ ¨$°Ñ5Ô5€MðHÝ)Ø�Y ¨mñ=ô =ˆˆøàð Hð Hð HåÐ?°9Ð?Ð?Ð?Ñ@Ô@ÀaÐGøøøøðHøøøð ÐÐÐØŒ>×1Ò1°'¸6ÑBÔB€DØ
Œ.×
)Ò
)¨$Ñ
/Ô
/€CØ„K×Ò˜CÑ Ô Ð Ø€Js ÁA( Á(BÁ-BÂBc óì — | d¦ « d }|| z }| d¬¦ « t ||¦ « }|t j d¦ « gz }t |||z |g g ¬¦ « S )aH
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
include_dirs : list
Extra directories to find include files when compiling
libraries : list
Libraries to link into the extension module
library_dirs: list
Where to find the libraries, ``-L`` passed to the linker
r éÿÿÿÿT)Úexist_okÚ INCLUDEPY)Úoutputfilenamer Ú librariesÚlibrary_dirs)ÚsplitÚmkdirÚ_convert_str_to_fileÚ sysconfigÚget_config_varÚ
_c_compile) ÚnameÚbuilddirr r r* r+ r ÚdirnameÚcfiles r$ r r P s„ € ð* �jŠj˜‰oŒo˜bÔ!€Gؘ‰o€G؇M‚M˜4€MÑ Ô Ð Ý °Ñ8Ô8€EØ¥9Ô#;¸KÑ#HÔ#HÐ"IÑI€LåØ
˜g¨Ñ/Ø!¨R¸bð
ñ
ô
ð
ó c ó® — |dz }| d¦ « 5 }| t | ¦ « ¦ « ddd¦ « n# 1 swxY w Y |S )zHelper function to create a file ``source.c`` in `dirname` that contains
the string in `source`. Returns the file name
zsource.cÚwN)ÚopenÚwriteÚstr)Úsourcer4 ÚfilenameÚfs r$ r. r. q s� € ð ˜Ñ#€HØ �Š�sÑ Ô ð ˜qØ �Š•�F‘”ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à€Os ›#A
Á
AÁAc
óR — g }g }| D ]b\ }}}|›d|›�}d|v rd}nd}| d|›d|›d|›d�¦ « d |||¬
¦ « } | | ¦ « Œcd |¦ « dt d |¦ « |¬
¦ « z z }
|
S )zõ 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
Ú_Ú
METH_KEYWORDSz2(PyObject *self, PyObject *args, PyObject *kwargs)z (PyObject *self, PyObject *args)z{"z", (PyCFunction)z, z},z^
static PyObject* {cfuncname}{signature}
{{
{code}
}}
)Ú cfuncnameÚ signatureÚcodeú
a6
static PyMethodDef methods[] = {
%(methods)s
{ NULL }
};
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"%(modname)s", /* m_name */
NULL, /* m_doc */
-1, /* m_size */
methods, /* m_methods */
};
)Úmethodsr )ÚappendÚformatÚjoinÚdict)r r Ú
methods_tableÚcodesÚfuncnameÚflagsrD rB rC Ú func_coder s r$ r r { sü € ð €MØ€EØ!*ð ð ш�%˜Ø&˜w˜w¨¨Ð1ˆ ؘeÐ#Ð#ØLˆIˆIà:ˆIØ×ÒÐØ08°°¸)¸)¸)ÀUÀUÀUÐKñ Mô Mð Mð÷
ŠF˜Y°)À$ˆFÑGÔGð ð �Š�YÑÔÐÐà�9Š9�UÑÔð õ �t—y’y Ñ/Ô/¸Ð
AÑ
AÔ
AñBñ B€Dð €Kr6 c ó0 — dt | ||¬¦ « z }|S )zG Combines the code fragments into source code ready to be compiled
zn
#include