| Server IP : 217.160.0.135 / Your IP : 216.73.217.37 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/numpy/testing/_private/__pycache__/ |
Upload File : |
�
���c� � �| � 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 �A/usr/lib/python3/dist-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 <Python.h>
%(body)s
PyMODINIT_FUNC
PyInit_%(name)s(void) {
%(init)s
}
)r2 r r )rJ )r2 r r rD s r$ r r � s0 � � � �
��4�� � ��D� �Kr6 c � � t j dk r2dg}dt j � t j d� � z g}n+t j � d� � rg d�}d }nd x}} t j dk r|dgz }t j dk r�d D ]�}|d
z |vr:t j � |d
z � � r|� |d
z � � |dz |vr:t j � |dz � � r|� |dz � � ��|� t � � � � }t j � � � } t | ||||||� � |� � � D ]7\ } }
t j � | � � |
k r|
t j | <