Ë
    7Š·jV  ã                   ó„   — 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mZ ddgZdddddœd	„Z		 dd
„Z
d„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)zb
Build a c-extension module on-the-fly in tests.
See build_and_import_extensions for usage hints

é    Né   )Úrun_subprocessÚbuild_and_import_extensionÚcompile_extension_moduleÚ )ÚprologueÚ	build_dirÚinclude_dirsÚ	more_initc                ób  — |€g }|t        || «      z   }d}|st        j                  d«      }|r
|dz  }||z  }|dz  }t        | ||«      }t	        | |||«      }	ddl}
|
j                  j                  | |	«      }|
j                  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')
    Nz›
    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;r   )Ú_make_methodsÚpathlibÚPathÚ_make_sourcer   Úimportlib.utilÚutilÚspec_from_file_locationÚmodule_from_specÚloaderÚexec_module)ÚmodnameÚ	functionsr   r	   r
   r   ÚbodyÚinitÚsource_stringÚmod_soÚ	importlibÚspecÚfoos                úU/root/workspace/.venv/lib/python3.12/site-packages/numpy/testing/_private/extbuild.pyr   r      sÆ   € ðN ÐØˆØ”m I¨wÓ7Ñ7€Dð€Dñ Ü—L‘L Ó%ˆ	ÙØð ñ 	ˆà�	ÑˆØˆOÑ€DÜ  ¨$°Ó5€MÜ%Ø�˜L¨-ó9€FãØ�>‰>×1Ñ1°'¸6ÓB€DØ
�.‰.×
)Ñ
)¨$Ó
/€CØ‡K�K×Ñ˜CÔ Ø€Jó    c                 óº   — | j                  d«      d   }|| z  }|j                  d¬«       t        ||«      }|xs g }|xs g }|xs g }t        |||z  |||¬«      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)Úoutputfilenamer
   Ú	librariesÚlibrary_dirs)ÚsplitÚmkdirÚ_convert_str_to_fileÚ
_c_compile)	ÚnameÚbuilddirr
   r   r(   r)   r   ÚdirnameÚcfiles	            r!   r   r   S   su   € ð* �j‰j˜‹o˜bÑ!€GØ˜‰o€GØ‡M�M˜4€MÔ Ü  °Ó8€EØÒ% 2€LØ’˜R€IØÒ% 2€LäØ˜g¨Ñ/Ø!¨YØ!ô
ð 
r"   c                 ó’   — |dz  }|j                  d«      5 }|j                  t        | «      «       ddd«       |S # 1 sw Y   |S xY w)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)Úsourcer0   ÚfilenameÚfs       r!   r,   r,   w   sF   € ð ˜Ñ#€HØ	�‰�sÓ	ð ˜qØ	�‰”�F“Ô÷à€O÷à€Oús	   —<¼Ac           
      ó
  — g }g }| D ]M  \  }}}|› d|› �}d|v rd}nd}|j                  d|› d|› d|› d�«       d	|› |› d
|› d�}	|j                  |	«       ŒO dj                  |«      }
dj                  |«      d|
› d|› d�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* z
        {
        z
        }
        ú
z*
    static PyMethodDef methods[] = {
    zi
    { NULL }
    };
    static struct PyModuleDef moduledef = {
        PyModuleDef_HEAD_INIT,
        "z�",    /* m_name */
        NULL,           /* m_doc */
        -1,             /* m_size */
        methods,        /* m_methods */
    };
    )ÚappendÚjoin)r   r   Úmethods_tableÚcodesÚfuncnameÚflagsÚcodeÚ	cfuncnameÚ	signatureÚ	func_codeÚmethods_strr   s               r!   r   r   �   sç   € ð €MØ€EØ!*ò  Ñˆ�%˜Ø�i˜q  
Ð+ˆ	Ø˜eÑ#ØL‰Ià:ˆIØ×Ñ˜s 8 *Ð,<¸Y¸KÀrÈ%ÈÐPSÐTÔUðØ#˜ Y Kð 0	à	ˆð 	ðˆ	ð 	�‰�YÕð ð —)‘)˜MÓ*€KØ�9‰9�UÓð #à€Mð 
ð
 ˆð ðñ €Dð €Kr"   c                 ó   — d|› d| › d|› d�}|S )zG Combines the code fragments into source code ready to be compiled
    z
    #include <Python.h>

    z 

    PyMODINIT_FUNC
    PyInit_z(void) {
    z
    }
    © )r.   r   r   rD   s       r!   r   r   ©   s7   € ðð 
€Fð ð ˆ6ð Ø	€Fð ð	€Dð €Kr"   c           	      óÄ   — g }t         j                  dk(  rdg}|j                  d«       n&t         j                  j                  d«      rg d¢}ng }t	        | ||||||«      S )NÚwin32z/we4013z/DEBUGÚlinux)z-O0z-gz%-Werror=implicit-function-declarationz-fPIC)ÚsysÚplatformr>   Ú
startswithÚbuild)r1   r'   r
   r(   r)   Ú
link_extraÚcompile_extras          r!   r-   r-   ¹   sg   € à€JÜ
‡|�|�wÒØ"˜ˆØ×Ñ˜(Õ#Ü	�‰×	 Ñ	  Ô	)òK‰ð ˆäØˆ~Ø�zØ�i ó/ð /r"   c                 ó   — | j                   dz  }t        j                  |d¬«       t        | j                   dz  d«      5 }|D �	cg c]  }	d|	z   ‘Œ	 }
}	|j	                  t        j                  d|j                  d   › d	| j                  d   › d
|› d|
› d|› d�«      «       ddd«       | j                   dz  }t        |d«      5 }|j	                  t        j                  dt        j                  › d�«      «       ddd«       t        j                  dk(  rt        g d¢|«       n't        dddddt        j                  |«      › �g|«       |j                  d   t        «       z   }t        ddg|«       t        j                  t        ||z  «      | j                   |z  «       | j                   |z  S c c}	w # 1 sw Y   �ŒxY w# 1 sw Y   ŒÊxY w)zuse meson to buildrQ   Tr%   zmeson.buildÚwtz-Lz“            project('foo', 'c')
            py = import('python').find_installation(pure: false)
            py.extension_module(
                'r$   z',
                'z',
                c_args: z,
                link_args: z',
                include_directories: z,
            )
        Nz.mesonpy-native-file.iniz-            [binaries]
            python = 'z
'
        rL   )ÚmesonÚsetupz--buildtype=releaseú--vsenvú..rV   rW   rX   rY   z--native-file=Úcompile)ÚparentÚosÚmakedirsr4   r5   ÚtextwrapÚdedentÚpartsrN   Ú
executablerO   r   ÚfspathÚget_so_suffixÚrenamer6   )r1   r'   rS   rR   r
   r(   r)   r	   ÚfidÚdÚ	link_dirsÚnative_file_nameÚso_names                r!   rQ   rQ   Ë   sÜ  € ð —‘˜wÑ&€IÜ‡K�K�	 DÕ)Ü	ˆe�l‰l˜]Ñ*¨DÓ	1ð °SØ'3Ö4 !�T˜A“XÐ4ˆ	Ð4Ø�	‰	”(—/‘/ð 'ð !×&Ñ& rÑ*Ð+ð ,Ø—+‘+˜b‘/Ð"ð #Ø&˜ð (Ø%˜;ð '&Ø&2 ^ð 4	ð
#ó 
ô 
	÷ð —|‘|Ð&@Ñ@ÐÜ	Ð Ó	%ð ¨Ø�	‰	”(—/‘/ð 'ä—~‘~Ð&ð '	ð#ó ô 	÷ô
 ‡|�|�wÒÜò )ð !õ	"ô
 	˜ ¨)Ø ¬r¯y©yÐ9IÓ/JÐ.KÐLðNà ô	"ð ×"Ñ" 2Ñ&¬«Ñ8€GÜ�G˜YÐ'¨Ô3Ü‡I�IŒc�)˜gÑ%Ó&¨¯©°wÑ(>Ô?Ø�<‰<˜'Ñ!Ð!ùò? 5÷ñ ú÷ð ús+   Á F7ÁF2ÁAF7Ã7GÆ2F7Æ7GÇGc                  ó8   — t        j                  d«      } | sJ ‚| S )NÚ
EXT_SUFFIX)Ú	sysconfigÚget_config_var)Úrets    r!   rc   rc   ô   s   € Ü
×
"Ñ
" <Ó
0€CÙ€Jˆ3Ø€Jr"   )NN)Ú__doc__r\   r   rN   rl   r^   Úutilsr   Ú__all__r   r   r,   r   r   r-   rQ   rc   rJ   r"   r!   ú<module>rr      sf   ðñó 
Û Û 
Û Û å !à'Ð)CÐ
D€ð )+°dØ Rô>ðF 59ó!
òHò%òPò /ò$&"óRr"   