
    Kh                         S r SSKrSSKrSSKrSSKrSSKrSSKrSS/rSS/ SS.S jr/ / 4S jr	S	 r
S
 rS r/ / / 4S jrS rS rg)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                   U[        X5      -   nSnU(       d  [        R                  " S5      nU(       a	  US-  nXu-  nUS-  n[        XU5      n [	        XXH5      n	SSKnUR                  R                  X	5      nUR                  R                  U5      nUR                  R                  U5        U$ ! [
         a  n
[        SU S35      U
eSn
A
ff = f)	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('abc')
>>> assert mod.test_bytes(b'abc')
z
    PyObject *mod = PyModule_Create(&moduledef);
    #ifdef Py_GIL_DISABLED
    PyUnstable_Module_SetGIL(mod, Py_MOD_GIL_NOT_USED);
    #endif
           .z.#define INITERROR return NULL
                z
return mod;zcould not compile in :Nr   )_make_methodspathlibPath_make_sourcer   	ExceptionRuntimeErrorimportlib.utilutilspec_from_file_locationmodule_from_specloaderexec_module)modname	functionsr   r   r   r	   bodyinitsource_stringmod_soe	importlibspecfoos                 Q/var/www/html/env/lib/python3.13/site-packages/numpy/testing/_private/extbuild.pyr   r      s    N mI77DD LL%	  	OD 5MH)=
 >>11'BD
..
)
)$
/CKKC J  H29+Q?@aGHs   B3 3
C=CCc                     U R                  S5      S   nX-  nUR                  SS9  [        X75      nU[        R                  " S5      /-   n[        XU-  U/ / S9$ )a  
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   T   si    * jjob!GoGMM4M  8E9#;#;K#H"IIL/!Rb
 
    c                     US-  nUR                  S5       nUR                  [        U 5      5        SSS5        U$ ! , (       d  f       U$ = f)zwHelper function to create a file ``source.c`` in `dirname` that contains
the string in `source`. Returns the file name
zsource.cwN)openwritestr)sourcer4   filenamefs       r#   r.   r.   u   sD     #H	s	q	F 
O 
	Os	   <
Ac           
      (   / n/ nU  HY  u  pEnU< SU< 3nSU;   a  SnOSnUR                  SU< SU< SU< S35        S	R                  XxUS
9n	UR                  U	5        M[     SR                  U5      S[        SR                  U5      US9-  -   n
U
$ )zTurns 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!*&1	e#LI:I08)UK	M
 FY$FG 	 	Y "+  99U  tyy/
AB BD Kr6   c                      S[        XUS9-  nU$ )zFCombines 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      s$    	 4D Kr6   c           	         [         R                  S:X  a6  S/nS[        R                  R	                  [         R
                  S5      -   /nO/[         R                  R                  S5      (       a  / SQn/ nO/ =pV [         R                  S:X  a  US/-   n[         R                  S:X  a  S	 H  nUS
-   U;  a;  [        R                  R                  US
-   5      (       a  UR                  US
-   5        US-   U;  d  MR  [        R                  R                  US-   5      (       d  M{  UR                  US-   5        M     UR                  [        5       5      n[        XXVX#U5        U$ )Nwin32z/we4013z	/LIBPATH:libslinux)z-O0z-gz%-Werror=implicit-function-declarationz-fPICz/DEBUGdarwin)z/sw/z/opt/local/includelib)sysplatformospathrI   base_prefix
startswithexistsrG   with_suffixget_so_suffixbuild)r5   r)   r   r*   r+   compile_extra
link_extrass           r#   r1   r1      s(   
||w"!BGGLL&$IIJ
		 	 	)	)K
%''
||w8*,

||x(AI\1q9}55##A	M25y,E	1J1J##AI. ) $//@N	/ r6   c                    U R                   S-  n[        R                  " USS9  UR                  S   n[	        U R                   S-  S5       n	U V
s/ s H  n
SU
-   PM
     nn
U V
s/ s H  n
SU
-   PM
     nn
U	R                  [        R                  " S	U S
U R                  S    SU SU SU SU SU S35      5        SSS5        [        R                  S:X  a  [        R                  " / SQUS9  O[        R                  " / SQUS9  [        R                  " SS/US9  [        R                  " [        Xx-  5      S-   U R                   U-  5        gs  sn
f s  sn
f ! , (       d  f       N= f)zuse meson to buildra   Tr&   r%   zmeson.buildwtz-Iz-Lz;            project('foo', 'c')
            shared_module('z', 'z',
                c_args: z + z,
                link_args: z,
                link_with: z_,
                name_prefix: '',
                name_suffix: 'dummy',
            )
        NrR   )mesonsetupz--buildtype=release--vsenv..)cwd)rg   rh   ri   rj   rg   compilez.dummy)parentrZ   makedirspartsr9   r:   textwrapdedentrX   rY   
subprocess
check_callrenamer;   )r5   r)   rb   rc   r   r*   r+   r   so_namefiddincludes	link_dirss                r#   ra   ra      sf    w&IKK	D)""2&G	ell]*D	1S&23lD1Hl3'34|!TAX|	4		(// '#9DR(9 :!
#m_ 5%;c* 6%; '		# 	 		 
2 ||w 0 #,	  	A"+	  7I.I>IIc)%&15<<'3IJ/ 44 
2	1s+   EE!E'E6A
E
E
E-c                  D    [         R                  " S5      n U (       d   eU $ )N
EXT_SUFFIX)r/   r0   )rets    r#   r`   r`      s    

"
"<
0CJ3Jr6   )__doc__rZ   r   rr   rX   r/   rp   __all__r   r   r.   r   r   r1   ra   r`    r6   r#   <module>r      st    
   
  ')C
D )+d2@J "$"
B%P$ 46>KBr6   