§
    ÈÁ³gª  ã                   óŒ   — d Z ddlZddlZddlZddlZddlZddlZddgZddg ddœd„Zg g fd„Z	d	„ Z
d
„ Zd„ Zg g g fd„Zd„ Zd„ ZdS )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                óº  — |t          || ¦  «        z   }d}|st          j        d¦  «        }|r
|dz  }||z  }|dz  }t          | ||¦  «        }	 t	          | |||¦  «        }	n&# t
          $ r}
t          d|› d�¦  «        |
‚d}
~
ww xY wdd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('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                 ú]/var/www/html/mpstechhub/venv/lib/python3.11/site-packages/numpy/testing/_private/extbuild.pyr   r      s)  € ð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 Â Bc                 óì   — |                       d¦  «        d         }|| z  }|                     d¬¦  «         t          ||¦  «        }|t          j        d¦  «        gz   }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   T   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                 ó®   — |dz  }|                      d¦  «        5 }|                     t          | ¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   |S )zHelper 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   s�   € ð ˜Ñ#€HØ	�Š�sÑ	Ô	ð ˜qØ	�Š•�F‘”ÑÔÐðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð à€Os   ›#A
Á
AÁAc           
      óR  — g }g }| D ]b\  }}}|›d|›�}d|v rd}nd}|                      d|›d|›d|›d�¦  «         d	                     |||¬
¦  «        }	|                      |	¦  «         Œcd                     |¦  «        dt          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   — dt          | ||¬¦  «        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        dk    r2dg}dt          j                             t           j        d¦  «        z   g}n+t           j                             d¦  «        rg d¢}g }ng x}}	 t           j        dk    r|dgz   }t           j        dk    r‡d	D ]„}|d
z   |vr:t          j                             |d
z   ¦  «        r|                     |d
z   ¦  «         |dz   |vr:t          j                             |dz   ¦  «        r|                     |dz   ¦  «         Œ…| 	                    t          ¦   «         ¦  «        }t          | ||||||¦  «         |S )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   ¹   sn  € å
„|�wÒÐØ"˜ˆØ!¥B¤G§L¢Lµ´À&Ñ$IÔ$IÑIÐJˆ
ˆ
Ý	Œ×	 Ò	  Ñ	)Ô	)ð ðKð Kð Kˆàˆ
ˆ
à%'Ð'ˆ˜
ØÝ
„|�wÒÐØ 8 *Ñ,ˆ
Ý
„|�xÒÐà(ð 	/ð 	/ˆAØ�I‘ \Ð1Ð1ÝœŸš q¨9¡}Ñ5Ô5ð 2à×#Ò# A¨	¡MÑ2Ô2Ð2Ø�5‰y Ð,Ð,µ´·²ÀÀEÁ	Ñ1JÔ1JÐ,Ø×#Ò# A¨¡IÑ.Ô.Ð.øà#×/Ò/µ±´Ñ@Ô@€NÝ	Øˆ~Ø�zØ�i ñ/ô /ð /ð Ðr6   c                 ó’  — | j         dz  }t          j        |d¬¦  «         |j        d         }t	          | j         dz  d¦  «        5 }	d„ |D ¦   «         }
d„ |D ¦   «         }|	                     t          j        d	|› d
| j        d         › d|
› d|› d|› d|› d|› d�¦  «        ¦  «         ddd¦  «         n# 1 swxY w Y   t          j	        dk    rt          j        g d¢|¬¦  «         nt          j        g d¢|¬¦  «         t          j        ddg|¬¦  «         t          j        t          ||z  ¦  «        dz   | j         |z  ¦  «         dS )zuse meson to buildra   Tr&   r%   zmeson.buildÚwtc                 ó   — g | ]}d |z   ‘ŒS )z-I© ©Ú.0Úds     r#   ú
<listcomp>zbuild.<locals>.<listcomp>à   s   € Ð3Ð3Ð3 �D˜1‘HÐ3Ð3Ð3r6   c                 ó   — g | ]}d |z   ‘ŒS )z-Lrh   ri   s     r#   rl   zbuild.<locals>.<listcomp>á   s   € Ð4Ð4Ð4 !�T˜A‘XÐ4Ð4Ð4r6   z;            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)rn   ro   rp   rq   rn   Úcompilez.dummy)ÚparentrZ   ÚmakedirsÚpartsr9   r:   ÚtextwrapÚdedentrX   rY   Ú
subprocessÚ
check_callÚrenamer;   )r5   r)   rb   rc   r   r*   r+   r   Úso_nameÚfidÚincludesÚ	link_dirss               r#   ra   ra   Ø   s  € ð ”˜wÑ&€IÝ„K�	 DÐ)Ñ)Ô)Ð)ØÔ" 2Ô&€GÝ	ˆeŒl˜]Ñ*¨DÑ	1Ô	1ð °SØ3Ð3 lÐ3Ñ3Ô3ˆØ4Ð4 |Ð4Ñ4Ô4ˆ	Ø�	Š	•(”/ð 	#à#ð	#ð 	#à).¬°R¬ð	#ð 	#ð "ð	#ð 	#ð '4ð	#ð 	#ð &ð		#ð 	#ð +5ð		#ð 	#ð
 &ð	#ð 	#ð 	#ñ 	ô 	ñ 		ô 		ð 		ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð õ „|�wÒÐÝÔð 0ð 0ð 0ð #,ð	 ñ 	 ô 	 ð 	 ð 	 õ 	ÔÐAÐAÐAØ"+ð	 ñ 	 ô 	 ð 	 õ Ô˜7 IÐ.°IÐ>Ñ>Ô>Ð>Ý„I�c�)˜gÑ%Ñ&Ô&¨Ñ1°5´<À'Ñ3IÑJÔJÐJÐJÐJs   ÁA!B3Â3B7Â:B7c                  ó6   — t          j        d¦  «        } | sJ ‚| S )NÚ
EXT_SUFFIX)r/   r0   )Úrets    r#   r`   r`   ù   s    € Ý
Ô
" <Ñ
0Ô
0€CØ€J€J€JØ€Jr6   )Ú__doc__rZ   r   ry   rX   r/   rw   Ú__all__r   r   r.   r   r   r1   ra   r`   rh   r6   r#   ú<module>r…      s  ððð ð 
€	€	€	Ø €€€Ø Ð Ð Ð Ø 
€
€
€
Ø Ð Ð Ð Ø €€€à'Ð)CÐ
D€ð )+°dØ 2ð@ð @ð @ð @ð @ðJ "$°"ð
ð 
ð 
ð 
ðBð ð ð%ð %ð %ðPð ð ð$ 46ÀØðð ð ð ð>Kð Kð KðBð ð ð ð r6   