zmc
2023-12-22 9fdbf60165db0400c2e8e6be2dc6e88138ac719a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
U
L±d¨ã@sºddlZddlZddlmZddlmZddlmZzeWn(e    k
rdddl
m Z dd„ZYnXze Wne    k
r†e Z YnXeƒZGd    d
„d
eƒZd d „Zd d„Zdd„ZdS)éNé)Ú allocate_lock)Ú    CDefError)Úmodel)ÚCallablecCs
t|tƒS©N)Ú
isinstancer)Úx©r
ú?d:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\cffi/api.pyÚ<lambda> ór c@sÀeZdZdZdjdd„Zdkdd„Zdldd    „Zdmd
d „Zdnd d„Zdd„Z    dd„Z
dodd„Z dd„Z dd„Z dd„Zdd„Zdpdd„Zdqd d!„Zd"d#„Zdrd%d&„Zd'd(„Zedfd)d*„Zd+d,„Zdsd-d.„Zdtd0d1„Zdud2d3„Zd4d5„Zdvd6d7„Zd8d9„Zd:d;„Zeeedd<ƒZ dwd=d>„Z!d?d@„Z"dAdB„Z#dCdD„Z$dEdF„Z%dGdH„Z&dIdJ„Z'dKdL„Z(dMdN„Z)dOdP„Z*dQdR„Z+dxdTdU„Z,dydVdW„Z-dzdYdZ„Z.d[d\„Z/d]d^„Z0d{d`da„Z1dbdc„Z2ddde„Z3dfdg„Z4dhdi„Z5dS)|ÚFFIa’
    The main top-level class that you instantiate once, or once per module.
 
    Example usage:
 
        ffi = FFI()
        ffi.cdef("""
            int printf(const char *, ...);
        """)
 
        C = ffi.dlopen(None)   # standard library
        -or-
        C = ffi.verify()  # use a C compiler: verify the decl above is right
 
        C.printf("hello, %s!\n", ffi.new("char[]", "world"))
    Nc    Cs¶|dkr^ddl}ddlm}|j|kr^t|dƒrJtd|t|j|jfƒ‚ntd|t|jfƒ‚ddlm}||_tƒ|_    | 
¡|_ i|_ t  d    ¡j|_t  d
¡j|_g|_g|_g|_g|_d|_i|_d|_d|_t |¡|_t|d ƒrô| |¡t|jƒD] }| d ¡rþt ||t!||ƒƒqþ|j    "| "tj#¡|_$| "tj%¡|_&W5QRXt'|t jƒrŠtt(d ƒsª| )|j$d¡t(_*| +¡\t(_,t(_-n | )|j$d¡|_*| +¡\|_,|_-|j.|_.dS)z{Create an FFI instance.  The 'backend' argument is used to
        select a non-default backend, mostly for tests.
        Nrr)Ú __version__Ú__file__zåVersion mismatch: this is the 'cffi' package version %s, located in %r.  When we import the top-level '_cffi_backend' extension module, we get version %s, located in %r.  The two versions should be equal; check your installation.zØVersion mismatch: this is the 'cffi' package version %s, located in %r.  This interpreter comes with a built-in '_cffi_backend' module, which is version %s.  The two versions should be equal; check your installation.)ÚcparserZ parsed_typesZ    new_typesÚset_ffiZRTLD_ÚNULL)/Z _cffi_backendÚrÚhasattrÚ    ExceptionrrÚ_backendrÚ_lockÚParserÚ_parserÚ_cached_btypesÚtypesÚ
ModuleTypeÚ__dict__Ú _parsed_typesZ
_new_typesÚ_function_cachesÚ
_librariesÚ _cdefsourcesÚ_included_ffisÚ_windows_unicodeÚ_init_once_cacheÚ _cdef_versionÚ
_embeddingrZ get_typecacheZ
_typecacherÚlistÚ
startswithÚsetattrÚgetattrÚ_get_cached_btypeZ
voidp_typeÚBVoidPZchar_array_typeÚBCharArrÚcastrZ
_get_typesÚCDataZCTypeÚbuffer)ÚselfÚbackendrrÚnamer
r
r Ú__init__)s^ 
 
þ
ÿ 
 
 
 
 z FFI.__init__FcCs|j||||ddS)a[Parse the given C source.  This registers all declared functions,
        types, and global variables.  The functions and global variables can
        then be accessed via either 'ffi.dlopen()' or 'ffi.verify()'.
        The types can be used in 'ffi.new()' and other functions.
        If 'packed' is specified as True, all structs declared inside this
        cdef are packed, i.e. laid out without any field alignment at all.
        Alternatively, 'pack' can be a small integer, and requests for
        alignment greater than that are ignored (pack=1 is equivalent to
        packed=True).
        )ÚoverrideÚpackedÚpackN)Ú_cdef)r2Úcsourcer6r7r8r
r
r Úcdefes zFFI.cdefcCs&|j|||dd|jdkr"d|_dS)NT)r7r8Z    dllexportr)r9r')r2r:r7r8r
r
r Ú embedding_apirs
zFFI.embedding_apic    Ksªt|tƒs&t|tƒstdƒ‚| d¡}|jttƒ|_|jj    |fd|i|—Ž|j
  |¡|rr|j D] }|  ¡qd|jj}|rœg|j_|D]}| ||¡qŠW5QRXdS)Nz cdef() argument must be a stringÚasciir6)rÚstrÚ
basestringÚ    TypeErrorÚencoderÚobjectr&rÚparser"Úappendr ÚclearZ _recompleteÚfinish_backend_type)r2r:r6ÚoptionsÚcacheÚ
finishlistÚtpr
r
r r9ws 
 
 
 
 
z    FFI._cdefrc    Csdt|tƒs&|dks&t||jƒs&tdƒ‚|j.t|||ƒ\}}|j |¡|j |¡W5QRX|S)aHLoad and return a dynamic library identified by 'name'.
        The standard C library can be loaded by passing None.
        Note that functions and types declared by 'ffi.cdef()' are not
        linked to a particular library, just like C headers; in the
        library we only look for the actual (untyped) symbols.
        NzRdlopen(name): name must be a file name, None, or an already-opened 'void *' handle)    rr?r0r@rÚ_make_ffi_libraryr rDr!)r2r4ÚflagsÚlibZfunction_cacher
r
r Údlopen‰s
ÿ
þ z
FFI.dlopencCst|ƒ |¡dS)z¸Close a library obtained with ffi.dlopen().  After this call,
        access to functions or variables from the library will fail
        (possibly with a segmentation fault).
        N)ÚtypeÚ__cffi_close__)r2rMr
r
r Údlclose›sz FFI.dlclosecCsj|}||jkr|j|St|tƒs,| d¡}|j |¡}|j}|rJ| ¡}| |¡}||f}||j|<|S)Nr=)    rrr>rArZ
parse_typeZis_raw_functionZas_function_pointerr,)r2ÚcdeclÚkeyrOÚreally_a_function_typeÚbtypeÚresultr
r
r Ú_typeof_locked¢s
 
 
 
 
 
zFFI._typeof_lockedc Csbz|j|}Wn0tk
r>|j| |¡}W5QRXYnX|\}}|r^|s^td|fƒ‚|S)Nz>the type %r is a function type, not a pointer-to-function type)rÚKeyErrorrrWr)r2rRÚconsider_function_as_funcptrrVrUrTr
r
r Ú_typeof´sÿz FFI._typeofc
Cs˜t|tƒr| |¡St||jƒr,|j |¡St|tjƒrLt|ƒ}|dk    rL|St|tj    ƒrˆt
|dƒrˆ|j |  |j ¡W5QR£SQRXtt|ƒƒ‚dS)z£Parse the C type given as a string and return the
        corresponding <ctype> object.
        It can also be used on 'cdata' instance to get its C type.
        NÚ_cffi_base_type)rr?rZr0rÚtypeofrÚBuiltinFunctionTypeÚ_builtin_function_typeÚ FunctionTyperrr,r[r@rO)r2rRÚresr
r
r r\Âs
 
    ÿz
FFI.typeofcCs0t|tƒr | |¡}|j |¡S|j |¡SdS)zvReturn the size in bytes of the argument.  It can be a
        string naming a C type, or a 'cdata' instance.
        N)rr?rZrÚsizeof)r2rRÚBTyper
r
r raÕs
 
 z
FFI.sizeofcCs t|tƒr| |¡}|j |¡S)z\Return the natural alignment size in bytes of the C type
        given as a string.
        )rr?rZrÚalignof)r2rRr
r
r rcßs
 
z FFI.alignofcGs(t|tƒr| |¡}|j|f|žŽdS)a3Return the offset of the named field inside the given
        structure or array, which must be given as a C type name.
        You can give several field names in case of nested structures.
        You can also give numeric values which correspond to array
        items, in case of an array type.
        r)rr?rZÚ _typeoffsetof)r2rRÚfields_or_indexesr
r
r Úoffsetofçs
 
z FFI.offsetofcCs"t|tƒr| |¡}|j ||¡S)a¬Allocate an instance according to the specified C type and
        return a pointer to it.  The specified C type must be either a
        pointer or an array: ``new('X *')`` allocates an X and returns
        a pointer to it, whereas ``new('X[n]')`` allocates an array of
        n X'es and returns an array referencing it (which works
        mostly like a pointer, like in C).  You can also use
        ``new('X[]', n)`` to allocate an array of a non-constant
        length n.
 
        The memory is initialized following the rules of declaring a
        global variable in C: by default it is zero-initialized, but
        an explicit initializer can be given which can be used to
        fill all or part of the memory.
 
        When the returned <cdata> object goes out of scope, the memory
        is freed.  In other words the returned <cdata> object has
        ownership of the value of type 'cdecl' that it points to.  This
        means that the raw data can be used as long as this object is
        kept alive, but must not be used for a longer time.  Be careful
        about that when copying the pointer to the memory somewhere
        else, e.g. into another structure.
        )rr?rZrÚnewp)r2rRÚinitr
r
r Únewòs
 
zFFI.newTcs,ˆj ¡}| |||¡‰d‡‡fdd„    }|S)aÇReturn a new allocator, i.e. a function that behaves like ffi.new()
        but uses the provided low-level 'alloc' and 'free' functions.
 
        'alloc' is called with the size as argument.  If it returns NULL, a
        MemoryError is raised.  'free' is called with the result of 'alloc'
        as argument.  Both can be either Python function or directly C
        functions.  If 'free' is None, then no free function is called.
        If both 'alloc' and 'free' are None, the default is used.
 
        If 'should_clear_after_alloc' is set to False, then the memory
        returned by 'alloc' is assumed to be already cleared (or you are
        fine with garbage); otherwise CFFI will clear it.
        Ncst|tƒrˆ |¡}ˆ||ƒSr©rr?rZ)rRrh©Z    allocatorr2r
r Úallocates
 
z#FFI.new_allocator.<locals>.allocate)N)rrÚ new_allocator)r2ZallocÚfreeZshould_clear_after_allocZ compiled_ffirlr
rkr rm s 
ÿzFFI.new_allocatorcCs"t|tƒr| |¡}|j ||¡S)zºSimilar to a C cast: returns an instance of the named C
        type initialized with the given 'source'.  The source is
        casted between integers or pointers of any type.
        )rr?rZrr/)r2rRÚsourcer
r
r r/%s
 
zFFI.castéÿÿÿÿcCs|j ||¡S)aÃReturn a Python string (or unicode string) from the 'cdata'.
        If 'cdata' is a pointer or array of characters or bytes, returns
        the null-terminated string.  The returned string extends until
        the first null character, or at most 'maxlen' characters.  If
        'cdata' is an array then 'maxlen' defaults to its length.
 
        If 'cdata' is a pointer or array of wchar_t, returns a unicode
        string following the same rules.
 
        If 'cdata' is a single character or byte or a wchar_t, returns
        it as a string or unicode string.
 
        If 'cdata' is an enum, returns the value of the enumerator as a
        string, or 'NUMBER' if the value is out of range.
        )rÚstring)r2ÚcdataÚmaxlenr
r
r rq.sz
FFI.stringcCs|j ||¡S)aLUnpack an array of C data of the given length,
        returning a Python string/unicode/list.
 
        If 'cdata' is a pointer to 'char', returns a byte string.
        It does not stop at the first null.  This is equivalent to:
        ffi.buffer(cdata, length)[:]
 
        If 'cdata' is a pointer to 'wchar_t', returns a unicode string.
        'length' is measured in wchar_t's; it is not the size in bytes.
 
        If 'cdata' is a pointer to anything else, returns a list of
        'length' items.  This is a faster equivalent to:
        [cdata[i] for i in range(length)]
        )rÚunpack)r2rrÚlengthr
r
r rt@sz
FFI.unpackcCs:|tkr|j|}}nt|tƒr*| |¡}|j |||¡S)aÙReturn a cdata of the given type pointing to the data of the
        given Python object, which must support the buffer interface.
        Note that this is not meant to be used on the built-in types
        str or unicode (you can build 'char[]' arrays explicitly)
        but only on objects containing large quantities of raw data
        in some other format, like 'array.array' or numpy arrays.
 
        The first argument is optional and default to 'char[]'.
        )Ú _unspecifiedr.rr?rZrÚ from_buffer)r2rRZ python_bufferZrequire_writabler
r
r rw^s 
 
 
ÿzFFI.from_buffercCs|j |||¡S)a_ffi.memmove(dest, src, n) copies n bytes of memory from src to dest.
 
        Like the C function memmove(), the memory areas may overlap;
        apart from that it behaves like the C function memcpy().
 
        'src' can be any cdata ptr or array, or any Python buffer object.
        'dest' can be any cdata ptr or array, or a writable Python buffer
        object.  The size to copy, 'n', is always measured in bytes.
 
        Unlike other methods, this one supports all Python buffer including
        byte strings and bytearrays---but it still does not support
        non-contiguous buffers.
        )rÚmemmove)r2ÚdestÚsrcÚnr
r
r rxpsz FFI.memmovecsB‡‡‡‡fdd„}tˆtƒr*ˆjˆdd‰|dkr6|S||ƒSdS)aReturn a callback object or a decorator making such a
        callback object.  'cdecl' must name a C function pointer type.
        The callback invokes the specified 'python_callable' (which may
        be provided either directly or via a decorator).  Important: the
        callback object must be manually kept alive for as long as the
        callback may be invoked from the C level.
        cs"t|ƒstdƒ‚ˆj ˆ|ˆˆ¡S)Nz.the 'python_callable' argument is not callable)Úcallabler@rÚcallback)Úpython_callable©rRÚerrorÚonerrorr2r
r Úcallback_decorator_wrapˆs 
ÿz-FFI.callback.<locals>.callback_decorator_wrapT)rYNrj)r2rRr~r€rr‚r
rr r}€s 
z FFI.callbackrcCsht|tƒr| |¡}| ¡}| d¡rBd|j |d¡krBd|}n|rZ|ddkrZd|}|j ||¡S)a.Return a string giving the C type 'cdecl', which may be itself
        a string or a <ctype> object.  If 'replace_with' is given, it gives
        extra text to append (or insert for more complicated C types), like
        a variable name, or '*' to get actually the C type 'pointer-to-cdecl'.
        Ú*z&[ú&z(%s)rz[(ú )rr?rZÚstripr)rZgetcname)r2rRZ replace_withr
r
r Úgetctype•s
 
 
ÿ
z FFI.getctypecCs|j |||¡S)a»Return a new cdata object that points to the same
        data.  Later, when this new cdata object is garbage-collected,
        'destructor(old_cdata_object)' will be called.
 
        The optional 'size' gives an estimate of the size, used to
        trigger the garbage collection more eagerly.  So far only used
        on PyPy.  It tells the GC that the returned object keeps alive
        roughly 'size' bytes of external memory.
        )rZgcp)r2rrZ
destructorÚsizer
r
r Úgc¥s
zFFI.gccCsb|j d¡dkst‚z|j|}Wn:tk
r\g}| ||¡}|D]}| ||¡qFYnX|S)NF)rÚacquireÚAssertionErrorrrXZget_cached_btyperF)r2rOrbrIr
r
r r,±s zFFI._get_cached_btypecKsVddlm}m}|jr | |¡|p(|ƒ}||||f|Ž|_|j ¡}|j |¡|S)aÊVerify that the current ffi signatures compile on this
        machine, and return a dynamic library object.  The dynamic
        library can be used to call functions and access global
        variables declared in this 'ffi'.  The library is compiled
        by the C compiler: it gives you C-level API compatibility
        (including calling macros).  This is unlike 'ffi.dlopen()',
        which requires binary compatibility in the signatures.
        r)ÚVerifierÚ_caller_dir_pycache)ÚverifierrŒrr$Ú_apply_windows_unicodeÚ load_libraryr!rD)r2roÚtmpdirÚkwargsrŒrrMr
r
r Úverify½s    
 
 
 z
FFI.verifycCs
|j ¡Sr)rÚ    get_errno©r2r
r
r Ú
_get_errnoÛszFFI._get_errnocCs|j |¡dSr)rÚ    set_errno)r2Úerrnor
r
r Ú
_set_errnoÝszFFI._set_errnoz(the value of 'errno' from/to the C callscCs |j |¡Sr)rÚ getwinerror)r2Úcoder
r
r ršâszFFI.getwinerrorc
Cs*|jt ||¡W5QR£SQRXdSr)rrÚ pointer_cache)r2Úctyper
r
r Ú _pointer_toåszFFI._pointer_tocGs˜z|j |¡}Wn<tk
rLdt|ƒjkrFt|ƒj|f|žŽYS‚YnX|rh|j|f|žŽ\}}n|jdkrztdƒ‚d}| |¡}|j     |||¡S)zêReturn the address of a <cdata 'struct-or-union'>.
        If 'fields_or_indexes' are given, returns the address of that
        field or array item in the structure or array, recursively in
        case of nested structures.
        Ú __addressof__Úpointerzaddressof(pointer)r)
rr\r@rOrrŸrdÚkindržZ rawaddressof)r2rrrerÚoffsetZctypeptrr
r
r Ú    addressofés
 
z FFI.addressofcGs@|j ||¡\}}|D] }|j ||d¡\}}||7}q||fS)Nr)rZ typeoffsetof)r2rZfield_or_indexrer¢Zfield1Zoffset1r
r
r rdþs
 
zFFI._typeoffsetofc
Cs–t|tƒstdt|ƒjfƒ‚||kr.tdƒ‚|jX|jF|j |j¡|j     
d¡|j      |j    ¡|j     
d¡|j  
|¡W5QRXW5QRXdS)aÉIncludes the typedefs, structs, unions and enums defined
        in another FFI instance.  Usage is similar to a #include in C,
        where a part of the program might include types defined in
        another part for its own usage.  Note that the include()
        method has no effect on functions, constants and global
        variables, which must anyway be accessed directly from the
        lib object returned by the original FFI instance.
        zGffi.include() expects an argument that is also of type cffi.FFI, not %rzself.include(self)ú[ú]N) rrr@rOÚ__name__Ú
ValueErrorrrÚincluder"rDÚextendr#)r2Zffi_to_includer
r
r r¨s    
ÿÿ  z FFI.includecCs|j |j|¡Sr)rZ newp_handler-©r2r    r
r
r Ú
new_handleszFFI.new_handlecCs |j |¡Sr)rÚ from_handlerªr
r
r r¬szFFI.from_handlecCs|j |¡dSr)rÚreleaserªr
r
r r­"sz FFI.releasecCs>|jdk    rtdƒ‚t|ƒ}|r*| d¡n
| d¡||_dS)acWindows: if 'enabled_flag' is True, enable the UNICODE and
        _UNICODE defines in C, and declare the types like TCHAR and LPTCSTR
        to be (pointers to) wchar_t.  If 'enabled_flag' is False,
        declare these types to be (pointers to) plain 8-bit characters.
        This is mostly for backward compatibility; you usually want True.
        Nz%set_unicode() can only be called oncezÄtypedef wchar_t TBYTE;typedef wchar_t TCHAR;typedef const wchar_t *LPCTSTR;typedef const wchar_t *PCTSTR;typedef wchar_t *LPTSTR;typedef wchar_t *PTSTR;typedef TBYTE *PTBYTE;typedef TCHAR *PTCHAR;z²typedef char TBYTE;typedef char TCHAR;typedef const char *LPCTSTR;typedef const char *PCTSTR;typedef char *LPTSTR;typedef char *PTSTR;typedef TBYTE *PTBYTE;typedef TCHAR *PTCHAR;)r$r§Úboolr;)r2Z enabled_flagr
r
r Ú set_unicode%s
     
zFFI.set_unicodecCs>| dd¡}t|ttfƒs"tdƒ‚t|ƒddg}||d<dS)NÚ define_macrosr
z''define_macros' must be a list or tuple)ÚUNICODEÚ1)Z_UNICODEr²)Úgetrr(Útupler@)r2ÚkwdsZ    defmacrosr
r
r rCs ÿzFFI._apply_windows_unicodecsr‡fdd„}dtjkr®ddl}tjdkrVd tj¡}ttdƒrŠ|d|j tj    d    ¡ƒn4tjd
krfd }nd }ttdƒrŠ|d|j tj    d ¡ƒttdƒr¬|d|j tj    dd¡ƒn tjdkrÐd}ttdƒrÎ|d7}nLz ddl
}Wn t k
rüddl m
}YnXd}|  d¡r||  d¡7}|tjd?tjd?d@f}ttdƒrN|tj7}|d|ƒtjdkrn|ddƒdS)Ncs"ˆ |g¡}||kr| |¡dSr)Ú
setdefaultrD)rSÚvalueÚlst©rµr
r ÚensureMs z(FFI._apply_embedding_fix.<locals>.ensureZ__pypy__rÚwin32zpython{0[0]}{0[1]}ÚprefixÚ library_dirsZlibs©ézpypy-czpypy3-cÚbinÚpypyZgoalz
python%d%dÚgettotalrefcountZ_d)Ú    sysconfigz python%d.%dZ    DEBUG_EXTéééÿÚabiflagsÚ    librariesÚextra_link_argsz    /MANIFEST)ÚsysÚbuiltin_module_namesÚosÚplatformÚformatÚ version_inforÚpathÚjoinr¼rÃÚ ImportErrorÚ    distutilsÚget_config_varÚ
hexversionrÇ)r2rµrºrÌZ    pythonlibÚtemplaterÃr
r¹r Ú_apply_embedding_fixKsB 
 
 
 
 
 
 
 
 
  ÿ 
 
 zFFI._apply_embedding_fixú.ccKsdddl}t|dƒrtdƒ‚t|tƒs,tdƒ‚|j|ksF|jrN|j|krNtdƒ‚t|ƒ|||f|_    dS)NrÚ_assigned_sourcez:set_source() cannot be called several times per ffi objectz'module_name' must be a stringzY'module_name' must not contain '/': use a dotted name to make a 'package.module' location)
rÌrr§rr?r@ÚsepÚaltsepr>rÙ)r2Ú module_nameroÚsource_extensionrµrÌr
r
r Ú
set_source}s
 
ÿzFFI.set_sourcecKsJddlm}t|tƒstdƒ‚| |¡}| ||¡|j|||f|ŽdS)Nr)Ú    pkgconfigz;the pkgconfig_libs argument must be a list of package names)rrßrr(r@Zflags_from_pkgconfigZ merge_flagsrÞ)r2rÜZpkgconfig_libsrorÝrµrßZkwds2r
r
r Úset_source_pkgconfigŠs  
 
 zFFI.set_source_pkgconfigÚbuildc CsÄddlm}ddlm}t|dƒs>t|dƒr6|j ¡Stdƒ‚|j\}}}}|dkr\t    dƒ‚||ƒ||||f|||d    d
œ|—Ž\}    }
|rÀ|
r¨t
j   d |    j df¡nt
j   d |    j df¡|    S) Nr)Úmkpathr©Ú    recompilerÙrŽz8set_source() must be called before distutils_extension()zadistutils_extension() is only for C extension modules, not for dlopen()-style pure Python modulesF)r‘ZextradirrÝÚcall_c_compilerzregenerated: %r
znot modified: %r
)Údistutils.dir_utilrâÚ
recompilerrärrŽÚ get_extensionr§rÙr@rÊÚstderrÚwriteÚsources) r2r‘ÚverboserârärÜrorÝrµÚextÚupdatedr
r
r Údistutils_extension”s2  
 
 
ÿýý
zFFI.distutils_extensioncCsZddlm}t|dƒstdƒ‚|j\}}}}|dkr<tdƒ‚||||f|ddœ|—ŽdS)NrrãrÙú0set_source() must be called before emit_c_code()zYemit_c_code() is only for C extension modules, not for dlopen()-style pure Python modulesF©Zc_filerå©rçrärr§rÙr@©r2ÚfilenamerärÜrorÝrµr
r
r Ú emit_c_code®s 
 
ÿÿzFFI.emit_c_codecCsZddlm}t|dƒstdƒ‚|j\}}}}|dk    r<tdƒ‚||||f|ddœ|—ŽdS)NrrãrÙrðz^emit_python_code() is only for dlopen()-style pure Python modules, not for C extension modulesFrñròrór
r
r Úemit_python_codeºs 
 
ÿÿzFFI.emit_python_codeÚ.c
CsLddlm}t|dƒstdƒ‚|j\}}}}    ||||f|||||dœ|    —ŽS)a¿The 'target' argument gives the final file name of the
        compiled DLL.  Use '*' to force distutils' choice, suitable for
        regular CPython C API modules.  Use a file name ending in '.*'
        to ask for the system's default extension for dynamic libraries
        (.so/.dll/.dylib).
 
        The default is '*' when building a non-embedded C API extension,
        and (module_name + '.*') when building an embedded library.
        rrãrÙz,set_source() must be called before compile())r‘ÚtargetrÝZcompiler_verboseÚdebug)rçrärr§rÙ)
r2r‘rìrørùrärÜrorÝrµr
r
r ÚcompileÆs
 
 þþz FFI.compilec
Csšz|j|}Wn(tk
r6|j |dtƒf¡}YnX|drH|dS|d@|j|}|drx|dW5QR£S|ƒ}d|f|j|<W5QRX|S)NFrrT)r%rXr¶r)r2ÚfuncÚtagr    rVr
r
r Ú    init_onceÙs
 
z FFI.init_oncecsÎ|jrtdƒ‚ddl}| d|¡}|r6|| ¡d…}| ¡pBdg}| d|d¡ ¡}tdt|ƒƒD],‰|ˆ}|     ¡rf| 
|¡sf|dd…}qzqft|ƒ‰‡fdd    „|Dƒ}d  |¡}t |d
d ƒ||_dS) Nz-embedding_init_code() can only be called oncerz\s*\nrz\s*rrpcsg|]}|ˆd…d‘qS)NÚ
r
)Ú.0Úline©Úir
r Ú
<listcomp>sz+FFI.embedding_init_code.<locals>.<listcomp>Z    cffi_initÚexec) r'r§ÚreÚmatchÚendÚ
splitlinesÚgroupÚrangeÚlenÚrstripr)rÑrú)r2ZpysourcerrÚlinesr¼rr
rr Úembedding_init_codeñs$ 
 
 zFFI.embedding_init_codecOs tdƒ‚dS)Nz:ffi.def_extern() is only available on API-mode FFI objects)r§)r2Úargsrµr
r
r Ú
def_extern szFFI.def_externcCs”g}g}g}|jjD]\}| d¡r6| |dd…¡q| d¡rT| |dd…¡q| d¡r| |dd…¡q| ¡| ¡| ¡|||fS)z¹Returns the user type names known to this FFI instance.
        This returns a tuple containing three lists of names:
        (typedef_names, names_of_structs, names_of_unions)
        ztypedef éNzstruct ézunion é)rÚ _declarationsr)rDÚsort)r2ZtypedefsÚstructsZunionsrSr
r
r Ú
list_typess 
 
 
zFFI.list_types)N)FFN)FN)F)r)F)N)NNT)rp)NNN)r)r)rN)rp)rØ)rØ)ráT)r÷rNN)6r¦Ú
__module__Ú __qualname__Ú__doc__r5r;r<r9rNrQrWrZr\rarcrfrirmr/rqrtrvrwrxr}r‡r‰r,r“r–r™Úpropertyr˜ršržr£rdr¨r«r¬r­r¯rr×rÞràrïrõrörúrýrrrr
r
r
r rsp
<
 
 
 
 
 
 
ÿ
    
ÿ
 
 
 
 
ÿ
2
ÿ
 
 
 
rc    
Csúddl}t|tƒs4tjdks$|dk    r0| ||¡Sd}d}d|ksRd|ksR|j|krˆz| ||¡WStk
r†}z|}W5d}~XYnXddl}|j     
|¡}|dkrî|dkrÈtjdkrÈtj dkrÈtdƒ‚d|f}|dk    ræd    ||f}t|ƒ‚| ||¡S)
Nrr»Úcr÷ú/r¾zXdlopen(None) cannot work on Windows for Python 3 (see http://bugs.python.org/issue23606)zGctypes.util.find_library() did not manage to locate a library called %rz%s.  Additionally, %s) rÌrr?rÊrÍrrÚÚOSErrorÚ ctypes.utilÚutilÚ find_libraryrÏ)    r3r4rLrÌZ first_errorÚeÚctypesrÐÚmsgr
r
r Ú_load_backend_lib$s.
  ÿ r%c    sˆ
j}t|||ƒ‰    ‡    ‡
‡ fdd„‰‡‡    ‡
fdd„‰‡‡    ‡
fdd„‰dd„‰‡
‡ fd    d
„‰i‰d g‰i‰‡‡‡‡‡‡‡
‡ fd d „‰ ‡‡‡
‡ ‡ fdd„‰ G‡‡‡‡    ‡
‡ ‡ ‡ fdd„dtƒ‰t|tƒrøz"t|tƒsÖ| d¡}d|ˆ_Wntk
röYnXˆƒ‰ ˆ ˆ j    fS)Ncs<d|}ˆjj|\}}ˆ |¡}ˆ ||¡}|ˆj|<dS)Nz    function )rrr,Ú load_functionr)r4rSrJÚ_rbr·)Ú
backendlibÚffiÚlibraryr
r Úaccessor_functionBs
 
 z,_make_ffi_library.<locals>.accessor_functioncs\dˆ}ˆjj|\}}ˆ |¡‰ˆj‰ˆj‰tˆˆt‡‡‡fdd„‡‡‡fdd„ƒƒdS)Nú    variable cs
ˆˆˆƒSrr
r•)rbr4Ú read_variabler
r r Pr z>_make_ffi_library.<locals>.accessor_variable.<locals>.<lambda>cs ˆˆˆ|ƒSrr
)r2r·)rbr4Úwrite_variabler
r r Qr )rrr,r-r.r*r)r4rSrJr')Ú
FFILibraryr(r))rbr4r-r.r Úaccessor_variableIs
þz,_make_ffi_library.<locals>.accessor_variablec s’z
ˆ|WStk
rŒˆjZ|ˆkrvd|}ˆjj|\}}ˆ |¡}|jdkrbt ˆ|¡}ˆ ||¡}|ˆ|<W5QRXˆ|YSXdS)Nr,Úarray)    rXrrrr,r¡rrœr&)r4rSrJr'rbÚp)Úaddr_variablesr(r)r
r Ú addressof_varSs
 
 
  z(_make_ffi_library.<locals>.addressof_varcSstd|fƒ‚dS)NzDnon-integer constant '%s' cannot be accessed from a dlopen() library)ÚNotImplementedError©r4r
r
r Úaccessor_constantbsÿz,_make_ffi_library.<locals>.accessor_constantcsˆjj|ˆj|<dSr)rÚ_int_constantsrr6)r)r*r
r Úaccessor_int_constantfsz0_make_ffi_library.<locals>.accessor_int_constantFcsԈdˆjkrdSˆjj ¡D]Œ\}\}}t|tjƒs|| dd¡\}}|dkrXˆˆ|<qª|dkrjˆˆ|<qª|dkrªˆˆ|<qt|j    ƒD]"\}}||f‡fdd„    }|ˆ|<q†qˆjj
D]}ˆ  |ˆ¡q´ˆjˆd<dS)    Nrr…rÚfunctionÚvariableZconstantcs| ¡|j|ˆj|<dSr)Zcheck_not_partialZ
enumvaluesr)r4rJr)r*r
r Ú accessor_enum|szB_make_ffi_library.<locals>.update_accessors.<locals>.accessor_enum) r&rrÚitemsrrZEnumTypeÚsplitÚ    enumerateZ enumeratorsr8r¶)rSrJr'rür4rZenumnamer<)r7r+r9r0Ú    accessorsÚaccessors_versionr)r*r
r Úupdate_accessorsms" 
 
 
  z+_make_ffi_library.<locals>.update_accessorsc    sbˆjR|ˆjks|ˆjkr*W5QR£dS|ˆkrHˆƒ|ˆkrHt|ƒ‚ˆ||ƒW5QRXdSr)rrÚAttributeErrorr6)r/r@r)r*rBr
r Ú make_accessor„sz(_make_ffi_library.<locals>.make_accessorcsReZdZ‡fdd„Z‡fdd„Z‡‡‡fdd„Z‡‡‡‡fdd„Z‡fd    d
„Zd S) z%_make_ffi_library.<locals>.FFILibrarycsˆ|ƒt||ƒSr)r+©r2r4©rDr
r Ú __getattr__sz1_make_ffi_library.<locals>.FFILibrary.__getattr__csJzt|j|ƒ}Wn(tk
r8ˆ|ƒt|||ƒYnX| ||¡dSr)r+Ú    __class__rCr*Ú__set__)r2r4r·rrFr
r Ú __setattr__’s z1_make_ffi_library.<locals>.FFILibrary.__setattr__c
s,ˆjˆƒˆ ¡W5QR£SQRXdSr)rÚkeysr•)r@r)rBr
r Ú__dir__šsz-_make_ffi_library.<locals>.FFILibrary.__dir__csf|ˆjkrˆj|S|ˆjkr&ˆ|ƒSˆ|ƒ|ˆjkrBˆj|S|ˆjkrTˆ|ƒStd|fƒ‚dS)Nz:cffi library has no function or global variable named '%s')rrCrE)r/r4r*rDr
r rŸžs
 
 
 
 
 
ÿz3_make_ffi_library.<locals>.FFILibrary.__addressof__csˆ ¡|j ¡dSr)Z    close_librrEr•)r(r
r rPªsz4_make_ffi_library.<locals>.FFILibrary.__cffi_close__N)r¦rrrGrJrLrŸrPr
)r/r@r4r(r)r*rDrBr
r r/Žs
   r/zutf-8z FFILibrary_%s)
rr%rBrr?r>rAr¦Ú UnicodeErrorr)r)ÚlibnamerLr3r
)r/r7r+r9r0r@rAr3r4r(r)r*rDrBr rK>s, 
 
 
 
rKc
Csrddl}z$|j|j}|j}|j}||}Wntttfk
rHYdSX|j|     |¡W5QR£SQRXdS)Nr)
rÊÚmodulesrZ_cffi_original_ffiZ_cffi_types_of_builtin_funcsrXrCr@rr,)rûrÊÚmoduler)Ztypes_of_builtin_funcsrJr
r
r r^¸s  r^)rÊrÚlockrr€rrrr|Ú    NameErrorÚ collectionsrr?r>rBrvrr%rKr^r
r
r
r Ú<module>s.    
z