@pairling/runtime-darwin-x64 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (159) hide show
  1. package/README.md +1 -1
  2. package/bin/pairling-connectd +0 -0
  3. package/manifest.json +4 -4
  4. package/package.json +3 -3
  5. package/python/bin/python3 +0 -0
  6. package/python/bin/python3.12 +0 -0
  7. package/python/lib/libpython3.12.dylib +0 -0
  8. package/python/lib/python3.12/lib-dynload/_crypt.cpython-312-darwin.so +0 -0
  9. package/python/lib/python3.12/lib-dynload/_dbm.cpython-312-darwin.so +0 -0
  10. package/python/lib/python3.12/site-packages/_cffi_backend.cpython-312-darwin.so +0 -0
  11. package/python/lib/python3.12/site-packages/cffi/__init__.py +14 -0
  12. package/python/lib/python3.12/site-packages/cffi/_cffi_errors.h +149 -0
  13. package/python/lib/python3.12/site-packages/cffi/_cffi_include.h +389 -0
  14. package/python/lib/python3.12/site-packages/cffi/_embedding.h +550 -0
  15. package/python/lib/python3.12/site-packages/cffi/_imp_emulation.py +83 -0
  16. package/python/lib/python3.12/site-packages/cffi/_shimmed_dist_utils.py +45 -0
  17. package/python/lib/python3.12/site-packages/cffi/api.py +967 -0
  18. package/python/lib/python3.12/site-packages/cffi/backend_ctypes.py +1121 -0
  19. package/python/lib/python3.12/site-packages/cffi/cffi_opcode.py +187 -0
  20. package/python/lib/python3.12/site-packages/cffi/commontypes.py +82 -0
  21. package/python/lib/python3.12/site-packages/cffi/cparser.py +1015 -0
  22. package/python/lib/python3.12/site-packages/cffi/error.py +31 -0
  23. package/python/lib/python3.12/site-packages/cffi/ffiplatform.py +113 -0
  24. package/python/lib/python3.12/site-packages/cffi/lock.py +30 -0
  25. package/python/lib/python3.12/site-packages/cffi/model.py +618 -0
  26. package/python/lib/python3.12/site-packages/cffi/parse_c_type.h +181 -0
  27. package/python/lib/python3.12/site-packages/cffi/pkgconfig.py +121 -0
  28. package/python/lib/python3.12/site-packages/cffi/recompiler.py +1598 -0
  29. package/python/lib/python3.12/site-packages/cffi/setuptools_ext.py +216 -0
  30. package/python/lib/python3.12/site-packages/cffi/vengine_cpy.py +1084 -0
  31. package/python/lib/python3.12/site-packages/cffi/vengine_gen.py +679 -0
  32. package/python/lib/python3.12/site-packages/cffi/verifier.py +306 -0
  33. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/INSTALLER +1 -0
  34. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/LICENSE +26 -0
  35. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/METADATA +40 -0
  36. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/RECORD +30 -0
  37. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/WHEEL +5 -0
  38. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/entry_points.txt +2 -0
  39. package/python/lib/python3.12/site-packages/cffi-1.17.1.dist-info/top_level.txt +2 -0
  40. package/python/lib/python3.12/site-packages/cryptography/__about__.py +17 -0
  41. package/python/lib/python3.12/site-packages/cryptography/__init__.py +26 -0
  42. package/python/lib/python3.12/site-packages/cryptography/exceptions.py +52 -0
  43. package/python/lib/python3.12/site-packages/cryptography/fernet.py +224 -0
  44. package/python/lib/python3.12/site-packages/cryptography/hazmat/__init__.py +13 -0
  45. package/python/lib/python3.12/site-packages/cryptography/hazmat/_oid.py +348 -0
  46. package/python/lib/python3.12/site-packages/cryptography/hazmat/backends/__init__.py +13 -0
  47. package/python/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/__init__.py +9 -0
  48. package/python/lib/python3.12/site-packages/cryptography/hazmat/backends/openssl/backend.py +308 -0
  49. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/__init__.py +3 -0
  50. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/__init__.pyi +37 -0
  51. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/_openssl.pyi +8 -0
  52. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/asn1.pyi +7 -0
  53. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/exceptions.pyi +17 -0
  54. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/ocsp.pyi +117 -0
  55. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/__init__.pyi +75 -0
  56. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/aead.pyi +107 -0
  57. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ciphers.pyi +38 -0
  58. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/cmac.pyi +18 -0
  59. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dh.pyi +51 -0
  60. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/dsa.pyi +41 -0
  61. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ec.pyi +52 -0
  62. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed25519.pyi +13 -0
  63. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/ed448.pyi +13 -0
  64. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hashes.pyi +28 -0
  65. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/hmac.pyi +22 -0
  66. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/kdf.pyi +49 -0
  67. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/keys.pyi +34 -0
  68. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/poly1305.pyi +15 -0
  69. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/rsa.pyi +55 -0
  70. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x25519.pyi +13 -0
  71. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/openssl/x448.pyi +13 -0
  72. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs12.pyi +52 -0
  73. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/pkcs7.pyi +50 -0
  74. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/test_support.pyi +23 -0
  75. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust/x509.pyi +313 -0
  76. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/_rust.abi3.so +0 -0
  77. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/__init__.py +3 -0
  78. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/_conditional.py +191 -0
  79. package/python/lib/python3.12/site-packages/cryptography/hazmat/bindings/openssl/binding.py +122 -0
  80. package/python/lib/python3.12/site-packages/cryptography/hazmat/decrepit/__init__.py +5 -0
  81. package/python/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/__init__.py +5 -0
  82. package/python/lib/python3.12/site-packages/cryptography/hazmat/decrepit/ciphers/algorithms.py +112 -0
  83. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/__init__.py +3 -0
  84. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/_asymmetric.py +19 -0
  85. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/_cipheralgorithm.py +60 -0
  86. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/_serialization.py +168 -0
  87. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/__init__.py +3 -0
  88. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dh.py +147 -0
  89. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/dsa.py +167 -0
  90. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ec.py +447 -0
  91. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed25519.py +129 -0
  92. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/ed448.py +131 -0
  93. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/padding.py +113 -0
  94. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py +277 -0
  95. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/types.py +111 -0
  96. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/utils.py +24 -0
  97. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x25519.py +122 -0
  98. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/asymmetric/x448.py +125 -0
  99. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/__init__.py +27 -0
  100. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/aead.py +23 -0
  101. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/algorithms.py +183 -0
  102. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/base.py +146 -0
  103. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/ciphers/modes.py +268 -0
  104. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/cmac.py +10 -0
  105. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/constant_time.py +14 -0
  106. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/hashes.py +246 -0
  107. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/hmac.py +13 -0
  108. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/__init__.py +23 -0
  109. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/argon2.py +13 -0
  110. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/concatkdf.py +125 -0
  111. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/hkdf.py +101 -0
  112. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/kbkdf.py +305 -0
  113. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/pbkdf2.py +62 -0
  114. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/scrypt.py +19 -0
  115. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/kdf/x963kdf.py +61 -0
  116. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/keywrap.py +177 -0
  117. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/padding.py +69 -0
  118. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/poly1305.py +11 -0
  119. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/__init__.py +65 -0
  120. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/base.py +14 -0
  121. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs12.py +176 -0
  122. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/pkcs7.py +411 -0
  123. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/serialization/ssh.py +1619 -0
  124. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/__init__.py +9 -0
  125. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/hotp.py +101 -0
  126. package/python/lib/python3.12/site-packages/cryptography/hazmat/primitives/twofactor/totp.py +56 -0
  127. package/python/lib/python3.12/site-packages/cryptography/py.typed +0 -0
  128. package/python/lib/python3.12/site-packages/cryptography/utils.py +139 -0
  129. package/python/lib/python3.12/site-packages/cryptography/x509/__init__.py +270 -0
  130. package/python/lib/python3.12/site-packages/cryptography/x509/base.py +848 -0
  131. package/python/lib/python3.12/site-packages/cryptography/x509/certificate_transparency.py +35 -0
  132. package/python/lib/python3.12/site-packages/cryptography/x509/extensions.py +2528 -0
  133. package/python/lib/python3.12/site-packages/cryptography/x509/general_name.py +281 -0
  134. package/python/lib/python3.12/site-packages/cryptography/x509/name.py +477 -0
  135. package/python/lib/python3.12/site-packages/cryptography/x509/ocsp.py +379 -0
  136. package/python/lib/python3.12/site-packages/cryptography/x509/oid.py +37 -0
  137. package/python/lib/python3.12/site-packages/cryptography/x509/verification.py +34 -0
  138. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/INSTALLER +1 -0
  139. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/METADATA +139 -0
  140. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/RECORD +106 -0
  141. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/REQUESTED +0 -0
  142. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/WHEEL +4 -0
  143. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/licenses/LICENSE +3 -0
  144. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/licenses/LICENSE.APACHE +202 -0
  145. package/python/lib/python3.12/site-packages/cryptography-45.0.7.dist-info/licenses/LICENSE.BSD +27 -0
  146. package/python/lib/python3.12/site-packages/pycparser/__init__.py +99 -0
  147. package/python/lib/python3.12/site-packages/pycparser/_ast_gen.py +355 -0
  148. package/python/lib/python3.12/site-packages/pycparser/_c_ast.cfg +195 -0
  149. package/python/lib/python3.12/site-packages/pycparser/ast_transforms.py +174 -0
  150. package/python/lib/python3.12/site-packages/pycparser/c_ast.py +1341 -0
  151. package/python/lib/python3.12/site-packages/pycparser/c_generator.py +573 -0
  152. package/python/lib/python3.12/site-packages/pycparser/c_lexer.py +706 -0
  153. package/python/lib/python3.12/site-packages/pycparser/c_parser.py +2376 -0
  154. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/INSTALLER +1 -0
  155. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/METADATA +244 -0
  156. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/RECORD +14 -0
  157. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/WHEEL +5 -0
  158. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/licenses/LICENSE +27 -0
  159. package/python/lib/python3.12/site-packages/pycparser-3.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,618 @@
1
+ import types
2
+ import weakref
3
+
4
+ from .lock import allocate_lock
5
+ from .error import CDefError, VerificationError, VerificationMissing
6
+
7
+ # type qualifiers
8
+ Q_CONST = 0x01
9
+ Q_RESTRICT = 0x02
10
+ Q_VOLATILE = 0x04
11
+
12
+ def qualify(quals, replace_with):
13
+ if quals & Q_CONST:
14
+ replace_with = ' const ' + replace_with.lstrip()
15
+ if quals & Q_VOLATILE:
16
+ replace_with = ' volatile ' + replace_with.lstrip()
17
+ if quals & Q_RESTRICT:
18
+ # It seems that __restrict is supported by gcc and msvc.
19
+ # If you hit some different compiler, add a #define in
20
+ # _cffi_include.h for it (and in its copies, documented there)
21
+ replace_with = ' __restrict ' + replace_with.lstrip()
22
+ return replace_with
23
+
24
+
25
+ class BaseTypeByIdentity(object):
26
+ is_array_type = False
27
+ is_raw_function = False
28
+
29
+ def get_c_name(self, replace_with='', context='a C file', quals=0):
30
+ result = self.c_name_with_marker
31
+ assert result.count('&') == 1
32
+ # some logic duplication with ffi.getctype()... :-(
33
+ replace_with = replace_with.strip()
34
+ if replace_with:
35
+ if replace_with.startswith('*') and '&[' in result:
36
+ replace_with = '(%s)' % replace_with
37
+ elif not replace_with[0] in '[(':
38
+ replace_with = ' ' + replace_with
39
+ replace_with = qualify(quals, replace_with)
40
+ result = result.replace('&', replace_with)
41
+ if '$' in result:
42
+ raise VerificationError(
43
+ "cannot generate '%s' in %s: unknown type name"
44
+ % (self._get_c_name(), context))
45
+ return result
46
+
47
+ def _get_c_name(self):
48
+ return self.c_name_with_marker.replace('&', '')
49
+
50
+ def has_c_name(self):
51
+ return '$' not in self._get_c_name()
52
+
53
+ def is_integer_type(self):
54
+ return False
55
+
56
+ def get_cached_btype(self, ffi, finishlist, can_delay=False):
57
+ try:
58
+ BType = ffi._cached_btypes[self]
59
+ except KeyError:
60
+ BType = self.build_backend_type(ffi, finishlist)
61
+ BType2 = ffi._cached_btypes.setdefault(self, BType)
62
+ assert BType2 is BType
63
+ return BType
64
+
65
+ def __repr__(self):
66
+ return '<%s>' % (self._get_c_name(),)
67
+
68
+ def _get_items(self):
69
+ return [(name, getattr(self, name)) for name in self._attrs_]
70
+
71
+
72
+ class BaseType(BaseTypeByIdentity):
73
+
74
+ def __eq__(self, other):
75
+ return (self.__class__ == other.__class__ and
76
+ self._get_items() == other._get_items())
77
+
78
+ def __ne__(self, other):
79
+ return not self == other
80
+
81
+ def __hash__(self):
82
+ return hash((self.__class__, tuple(self._get_items())))
83
+
84
+
85
+ class VoidType(BaseType):
86
+ _attrs_ = ()
87
+
88
+ def __init__(self):
89
+ self.c_name_with_marker = 'void&'
90
+
91
+ def build_backend_type(self, ffi, finishlist):
92
+ return global_cache(self, ffi, 'new_void_type')
93
+
94
+ void_type = VoidType()
95
+
96
+
97
+ class BasePrimitiveType(BaseType):
98
+ def is_complex_type(self):
99
+ return False
100
+
101
+
102
+ class PrimitiveType(BasePrimitiveType):
103
+ _attrs_ = ('name',)
104
+
105
+ ALL_PRIMITIVE_TYPES = {
106
+ 'char': 'c',
107
+ 'short': 'i',
108
+ 'int': 'i',
109
+ 'long': 'i',
110
+ 'long long': 'i',
111
+ 'signed char': 'i',
112
+ 'unsigned char': 'i',
113
+ 'unsigned short': 'i',
114
+ 'unsigned int': 'i',
115
+ 'unsigned long': 'i',
116
+ 'unsigned long long': 'i',
117
+ 'float': 'f',
118
+ 'double': 'f',
119
+ 'long double': 'f',
120
+ '_cffi_float_complex_t': 'j',
121
+ '_cffi_double_complex_t': 'j',
122
+ '_Bool': 'i',
123
+ # the following types are not primitive in the C sense
124
+ 'wchar_t': 'c',
125
+ 'char16_t': 'c',
126
+ 'char32_t': 'c',
127
+ 'int8_t': 'i',
128
+ 'uint8_t': 'i',
129
+ 'int16_t': 'i',
130
+ 'uint16_t': 'i',
131
+ 'int32_t': 'i',
132
+ 'uint32_t': 'i',
133
+ 'int64_t': 'i',
134
+ 'uint64_t': 'i',
135
+ 'int_least8_t': 'i',
136
+ 'uint_least8_t': 'i',
137
+ 'int_least16_t': 'i',
138
+ 'uint_least16_t': 'i',
139
+ 'int_least32_t': 'i',
140
+ 'uint_least32_t': 'i',
141
+ 'int_least64_t': 'i',
142
+ 'uint_least64_t': 'i',
143
+ 'int_fast8_t': 'i',
144
+ 'uint_fast8_t': 'i',
145
+ 'int_fast16_t': 'i',
146
+ 'uint_fast16_t': 'i',
147
+ 'int_fast32_t': 'i',
148
+ 'uint_fast32_t': 'i',
149
+ 'int_fast64_t': 'i',
150
+ 'uint_fast64_t': 'i',
151
+ 'intptr_t': 'i',
152
+ 'uintptr_t': 'i',
153
+ 'intmax_t': 'i',
154
+ 'uintmax_t': 'i',
155
+ 'ptrdiff_t': 'i',
156
+ 'size_t': 'i',
157
+ 'ssize_t': 'i',
158
+ }
159
+
160
+ def __init__(self, name):
161
+ assert name in self.ALL_PRIMITIVE_TYPES
162
+ self.name = name
163
+ self.c_name_with_marker = name + '&'
164
+
165
+ def is_char_type(self):
166
+ return self.ALL_PRIMITIVE_TYPES[self.name] == 'c'
167
+ def is_integer_type(self):
168
+ return self.ALL_PRIMITIVE_TYPES[self.name] == 'i'
169
+ def is_float_type(self):
170
+ return self.ALL_PRIMITIVE_TYPES[self.name] == 'f'
171
+ def is_complex_type(self):
172
+ return self.ALL_PRIMITIVE_TYPES[self.name] == 'j'
173
+
174
+ def build_backend_type(self, ffi, finishlist):
175
+ return global_cache(self, ffi, 'new_primitive_type', self.name)
176
+
177
+
178
+ class UnknownIntegerType(BasePrimitiveType):
179
+ _attrs_ = ('name',)
180
+
181
+ def __init__(self, name):
182
+ self.name = name
183
+ self.c_name_with_marker = name + '&'
184
+
185
+ def is_integer_type(self):
186
+ return True
187
+
188
+ def build_backend_type(self, ffi, finishlist):
189
+ raise NotImplementedError("integer type '%s' can only be used after "
190
+ "compilation" % self.name)
191
+
192
+ class UnknownFloatType(BasePrimitiveType):
193
+ _attrs_ = ('name', )
194
+
195
+ def __init__(self, name):
196
+ self.name = name
197
+ self.c_name_with_marker = name + '&'
198
+
199
+ def build_backend_type(self, ffi, finishlist):
200
+ raise NotImplementedError("float type '%s' can only be used after "
201
+ "compilation" % self.name)
202
+
203
+
204
+ class BaseFunctionType(BaseType):
205
+ _attrs_ = ('args', 'result', 'ellipsis', 'abi')
206
+
207
+ def __init__(self, args, result, ellipsis, abi=None):
208
+ self.args = args
209
+ self.result = result
210
+ self.ellipsis = ellipsis
211
+ self.abi = abi
212
+ #
213
+ reprargs = [arg._get_c_name() for arg in self.args]
214
+ if self.ellipsis:
215
+ reprargs.append('...')
216
+ reprargs = reprargs or ['void']
217
+ replace_with = self._base_pattern % (', '.join(reprargs),)
218
+ if abi is not None:
219
+ replace_with = replace_with[:1] + abi + ' ' + replace_with[1:]
220
+ self.c_name_with_marker = (
221
+ self.result.c_name_with_marker.replace('&', replace_with))
222
+
223
+
224
+ class RawFunctionType(BaseFunctionType):
225
+ # Corresponds to a C type like 'int(int)', which is the C type of
226
+ # a function, but not a pointer-to-function. The backend has no
227
+ # notion of such a type; it's used temporarily by parsing.
228
+ _base_pattern = '(&)(%s)'
229
+ is_raw_function = True
230
+
231
+ def build_backend_type(self, ffi, finishlist):
232
+ raise CDefError("cannot render the type %r: it is a function "
233
+ "type, not a pointer-to-function type" % (self,))
234
+
235
+ def as_function_pointer(self):
236
+ return FunctionPtrType(self.args, self.result, self.ellipsis, self.abi)
237
+
238
+
239
+ class FunctionPtrType(BaseFunctionType):
240
+ _base_pattern = '(*&)(%s)'
241
+
242
+ def build_backend_type(self, ffi, finishlist):
243
+ result = self.result.get_cached_btype(ffi, finishlist)
244
+ args = []
245
+ for tp in self.args:
246
+ args.append(tp.get_cached_btype(ffi, finishlist))
247
+ abi_args = ()
248
+ if self.abi == "__stdcall":
249
+ if not self.ellipsis: # __stdcall ignored for variadic funcs
250
+ try:
251
+ abi_args = (ffi._backend.FFI_STDCALL,)
252
+ except AttributeError:
253
+ pass
254
+ return global_cache(self, ffi, 'new_function_type',
255
+ tuple(args), result, self.ellipsis, *abi_args)
256
+
257
+ def as_raw_function(self):
258
+ return RawFunctionType(self.args, self.result, self.ellipsis, self.abi)
259
+
260
+
261
+ class PointerType(BaseType):
262
+ _attrs_ = ('totype', 'quals')
263
+
264
+ def __init__(self, totype, quals=0):
265
+ self.totype = totype
266
+ self.quals = quals
267
+ extra = " *&"
268
+ if totype.is_array_type:
269
+ extra = "(%s)" % (extra.lstrip(),)
270
+ extra = qualify(quals, extra)
271
+ self.c_name_with_marker = totype.c_name_with_marker.replace('&', extra)
272
+
273
+ def build_backend_type(self, ffi, finishlist):
274
+ BItem = self.totype.get_cached_btype(ffi, finishlist, can_delay=True)
275
+ return global_cache(self, ffi, 'new_pointer_type', BItem)
276
+
277
+ voidp_type = PointerType(void_type)
278
+
279
+ def ConstPointerType(totype):
280
+ return PointerType(totype, Q_CONST)
281
+
282
+ const_voidp_type = ConstPointerType(void_type)
283
+
284
+
285
+ class NamedPointerType(PointerType):
286
+ _attrs_ = ('totype', 'name')
287
+
288
+ def __init__(self, totype, name, quals=0):
289
+ PointerType.__init__(self, totype, quals)
290
+ self.name = name
291
+ self.c_name_with_marker = name + '&'
292
+
293
+
294
+ class ArrayType(BaseType):
295
+ _attrs_ = ('item', 'length')
296
+ is_array_type = True
297
+
298
+ def __init__(self, item, length):
299
+ self.item = item
300
+ self.length = length
301
+ #
302
+ if length is None:
303
+ brackets = '&[]'
304
+ elif length == '...':
305
+ brackets = '&[/*...*/]'
306
+ else:
307
+ brackets = '&[%s]' % length
308
+ self.c_name_with_marker = (
309
+ self.item.c_name_with_marker.replace('&', brackets))
310
+
311
+ def length_is_unknown(self):
312
+ return isinstance(self.length, str)
313
+
314
+ def resolve_length(self, newlength):
315
+ return ArrayType(self.item, newlength)
316
+
317
+ def build_backend_type(self, ffi, finishlist):
318
+ if self.length_is_unknown():
319
+ raise CDefError("cannot render the type %r: unknown length" %
320
+ (self,))
321
+ self.item.get_cached_btype(ffi, finishlist) # force the item BType
322
+ BPtrItem = PointerType(self.item).get_cached_btype(ffi, finishlist)
323
+ return global_cache(self, ffi, 'new_array_type', BPtrItem, self.length)
324
+
325
+ char_array_type = ArrayType(PrimitiveType('char'), None)
326
+
327
+
328
+ class StructOrUnionOrEnum(BaseTypeByIdentity):
329
+ _attrs_ = ('name',)
330
+ forcename = None
331
+
332
+ def build_c_name_with_marker(self):
333
+ name = self.forcename or '%s %s' % (self.kind, self.name)
334
+ self.c_name_with_marker = name + '&'
335
+
336
+ def force_the_name(self, forcename):
337
+ self.forcename = forcename
338
+ self.build_c_name_with_marker()
339
+
340
+ def get_official_name(self):
341
+ assert self.c_name_with_marker.endswith('&')
342
+ return self.c_name_with_marker[:-1]
343
+
344
+
345
+ class StructOrUnion(StructOrUnionOrEnum):
346
+ fixedlayout = None
347
+ completed = 0
348
+ partial = False
349
+ packed = 0
350
+
351
+ def __init__(self, name, fldnames, fldtypes, fldbitsize, fldquals=None):
352
+ self.name = name
353
+ self.fldnames = fldnames
354
+ self.fldtypes = fldtypes
355
+ self.fldbitsize = fldbitsize
356
+ self.fldquals = fldquals
357
+ self.build_c_name_with_marker()
358
+
359
+ def anonymous_struct_fields(self):
360
+ if self.fldtypes is not None:
361
+ for name, type in zip(self.fldnames, self.fldtypes):
362
+ if name == '' and isinstance(type, StructOrUnion):
363
+ yield type
364
+
365
+ def enumfields(self, expand_anonymous_struct_union=True):
366
+ fldquals = self.fldquals
367
+ if fldquals is None:
368
+ fldquals = (0,) * len(self.fldnames)
369
+ for name, type, bitsize, quals in zip(self.fldnames, self.fldtypes,
370
+ self.fldbitsize, fldquals):
371
+ if (name == '' and isinstance(type, StructOrUnion)
372
+ and expand_anonymous_struct_union):
373
+ # nested anonymous struct/union
374
+ for result in type.enumfields():
375
+ yield result
376
+ else:
377
+ yield (name, type, bitsize, quals)
378
+
379
+ def force_flatten(self):
380
+ # force the struct or union to have a declaration that lists
381
+ # directly all fields returned by enumfields(), flattening
382
+ # nested anonymous structs/unions.
383
+ names = []
384
+ types = []
385
+ bitsizes = []
386
+ fldquals = []
387
+ for name, type, bitsize, quals in self.enumfields():
388
+ names.append(name)
389
+ types.append(type)
390
+ bitsizes.append(bitsize)
391
+ fldquals.append(quals)
392
+ self.fldnames = tuple(names)
393
+ self.fldtypes = tuple(types)
394
+ self.fldbitsize = tuple(bitsizes)
395
+ self.fldquals = tuple(fldquals)
396
+
397
+ def get_cached_btype(self, ffi, finishlist, can_delay=False):
398
+ BType = StructOrUnionOrEnum.get_cached_btype(self, ffi, finishlist,
399
+ can_delay)
400
+ if not can_delay:
401
+ self.finish_backend_type(ffi, finishlist)
402
+ return BType
403
+
404
+ def finish_backend_type(self, ffi, finishlist):
405
+ if self.completed:
406
+ if self.completed != 2:
407
+ raise NotImplementedError("recursive structure declaration "
408
+ "for '%s'" % (self.name,))
409
+ return
410
+ BType = ffi._cached_btypes[self]
411
+ #
412
+ self.completed = 1
413
+ #
414
+ if self.fldtypes is None:
415
+ pass # not completing it: it's an opaque struct
416
+ #
417
+ elif self.fixedlayout is None:
418
+ fldtypes = [tp.get_cached_btype(ffi, finishlist)
419
+ for tp in self.fldtypes]
420
+ lst = list(zip(self.fldnames, fldtypes, self.fldbitsize))
421
+ extra_flags = ()
422
+ if self.packed:
423
+ if self.packed == 1:
424
+ extra_flags = (8,) # SF_PACKED
425
+ else:
426
+ extra_flags = (0, self.packed)
427
+ ffi._backend.complete_struct_or_union(BType, lst, self,
428
+ -1, -1, *extra_flags)
429
+ #
430
+ else:
431
+ fldtypes = []
432
+ fieldofs, fieldsize, totalsize, totalalignment = self.fixedlayout
433
+ for i in range(len(self.fldnames)):
434
+ fsize = fieldsize[i]
435
+ ftype = self.fldtypes[i]
436
+ #
437
+ if isinstance(ftype, ArrayType) and ftype.length_is_unknown():
438
+ # fix the length to match the total size
439
+ BItemType = ftype.item.get_cached_btype(ffi, finishlist)
440
+ nlen, nrest = divmod(fsize, ffi.sizeof(BItemType))
441
+ if nrest != 0:
442
+ self._verification_error(
443
+ "field '%s.%s' has a bogus size?" % (
444
+ self.name, self.fldnames[i] or '{}'))
445
+ ftype = ftype.resolve_length(nlen)
446
+ self.fldtypes = (self.fldtypes[:i] + (ftype,) +
447
+ self.fldtypes[i+1:])
448
+ #
449
+ BFieldType = ftype.get_cached_btype(ffi, finishlist)
450
+ if isinstance(ftype, ArrayType) and ftype.length is None:
451
+ assert fsize == 0
452
+ else:
453
+ bitemsize = ffi.sizeof(BFieldType)
454
+ if bitemsize != fsize:
455
+ self._verification_error(
456
+ "field '%s.%s' is declared as %d bytes, but is "
457
+ "really %d bytes" % (self.name,
458
+ self.fldnames[i] or '{}',
459
+ bitemsize, fsize))
460
+ fldtypes.append(BFieldType)
461
+ #
462
+ lst = list(zip(self.fldnames, fldtypes, self.fldbitsize, fieldofs))
463
+ ffi._backend.complete_struct_or_union(BType, lst, self,
464
+ totalsize, totalalignment)
465
+ self.completed = 2
466
+
467
+ def _verification_error(self, msg):
468
+ raise VerificationError(msg)
469
+
470
+ def check_not_partial(self):
471
+ if self.partial and self.fixedlayout is None:
472
+ raise VerificationMissing(self._get_c_name())
473
+
474
+ def build_backend_type(self, ffi, finishlist):
475
+ self.check_not_partial()
476
+ finishlist.append(self)
477
+ #
478
+ return global_cache(self, ffi, 'new_%s_type' % self.kind,
479
+ self.get_official_name(), key=self)
480
+
481
+
482
+ class StructType(StructOrUnion):
483
+ kind = 'struct'
484
+
485
+
486
+ class UnionType(StructOrUnion):
487
+ kind = 'union'
488
+
489
+
490
+ class EnumType(StructOrUnionOrEnum):
491
+ kind = 'enum'
492
+ partial = False
493
+ partial_resolved = False
494
+
495
+ def __init__(self, name, enumerators, enumvalues, baseinttype=None):
496
+ self.name = name
497
+ self.enumerators = enumerators
498
+ self.enumvalues = enumvalues
499
+ self.baseinttype = baseinttype
500
+ self.build_c_name_with_marker()
501
+
502
+ def force_the_name(self, forcename):
503
+ StructOrUnionOrEnum.force_the_name(self, forcename)
504
+ if self.forcename is None:
505
+ name = self.get_official_name()
506
+ self.forcename = '$' + name.replace(' ', '_')
507
+
508
+ def check_not_partial(self):
509
+ if self.partial and not self.partial_resolved:
510
+ raise VerificationMissing(self._get_c_name())
511
+
512
+ def build_backend_type(self, ffi, finishlist):
513
+ self.check_not_partial()
514
+ base_btype = self.build_baseinttype(ffi, finishlist)
515
+ return global_cache(self, ffi, 'new_enum_type',
516
+ self.get_official_name(),
517
+ self.enumerators, self.enumvalues,
518
+ base_btype, key=self)
519
+
520
+ def build_baseinttype(self, ffi, finishlist):
521
+ if self.baseinttype is not None:
522
+ return self.baseinttype.get_cached_btype(ffi, finishlist)
523
+ #
524
+ if self.enumvalues:
525
+ smallest_value = min(self.enumvalues)
526
+ largest_value = max(self.enumvalues)
527
+ else:
528
+ import warnings
529
+ try:
530
+ # XXX! The goal is to ensure that the warnings.warn()
531
+ # will not suppress the warning. We want to get it
532
+ # several times if we reach this point several times.
533
+ __warningregistry__.clear()
534
+ except NameError:
535
+ pass
536
+ warnings.warn("%r has no values explicitly defined; "
537
+ "guessing that it is equivalent to 'unsigned int'"
538
+ % self._get_c_name())
539
+ smallest_value = largest_value = 0
540
+ if smallest_value < 0: # needs a signed type
541
+ sign = 1
542
+ candidate1 = PrimitiveType("int")
543
+ candidate2 = PrimitiveType("long")
544
+ else:
545
+ sign = 0
546
+ candidate1 = PrimitiveType("unsigned int")
547
+ candidate2 = PrimitiveType("unsigned long")
548
+ btype1 = candidate1.get_cached_btype(ffi, finishlist)
549
+ btype2 = candidate2.get_cached_btype(ffi, finishlist)
550
+ size1 = ffi.sizeof(btype1)
551
+ size2 = ffi.sizeof(btype2)
552
+ if (smallest_value >= ((-1) << (8*size1-1)) and
553
+ largest_value < (1 << (8*size1-sign))):
554
+ return btype1
555
+ if (smallest_value >= ((-1) << (8*size2-1)) and
556
+ largest_value < (1 << (8*size2-sign))):
557
+ return btype2
558
+ raise CDefError("%s values don't all fit into either 'long' "
559
+ "or 'unsigned long'" % self._get_c_name())
560
+
561
+ def unknown_type(name, structname=None):
562
+ if structname is None:
563
+ structname = '$%s' % name
564
+ tp = StructType(structname, None, None, None)
565
+ tp.force_the_name(name)
566
+ tp.origin = "unknown_type"
567
+ return tp
568
+
569
+ def unknown_ptr_type(name, structname=None):
570
+ if structname is None:
571
+ structname = '$$%s' % name
572
+ tp = StructType(structname, None, None, None)
573
+ return NamedPointerType(tp, name)
574
+
575
+
576
+ global_lock = allocate_lock()
577
+ _typecache_cffi_backend = weakref.WeakValueDictionary()
578
+
579
+ def get_typecache(backend):
580
+ # returns _typecache_cffi_backend if backend is the _cffi_backend
581
+ # module, or type(backend).__typecache if backend is an instance of
582
+ # CTypesBackend (or some FakeBackend class during tests)
583
+ if isinstance(backend, types.ModuleType):
584
+ return _typecache_cffi_backend
585
+ with global_lock:
586
+ if not hasattr(type(backend), '__typecache'):
587
+ type(backend).__typecache = weakref.WeakValueDictionary()
588
+ return type(backend).__typecache
589
+
590
+ def global_cache(srctype, ffi, funcname, *args, **kwds):
591
+ key = kwds.pop('key', (funcname, args))
592
+ assert not kwds
593
+ try:
594
+ return ffi._typecache[key]
595
+ except KeyError:
596
+ pass
597
+ try:
598
+ res = getattr(ffi._backend, funcname)(*args)
599
+ except NotImplementedError as e:
600
+ raise NotImplementedError("%s: %r: %s" % (funcname, srctype, e))
601
+ # note that setdefault() on WeakValueDictionary is not atomic
602
+ # and contains a rare bug (http://bugs.python.org/issue19542);
603
+ # we have to use a lock and do it ourselves
604
+ cache = ffi._typecache
605
+ with global_lock:
606
+ res1 = cache.get(key)
607
+ if res1 is None:
608
+ cache[key] = res
609
+ return res
610
+ else:
611
+ return res1
612
+
613
+ def pointer_cache(ffi, BType):
614
+ return global_cache('?', ffi, 'new_pointer_type', BType)
615
+
616
+ def attach_exception_info(e, name):
617
+ if e.args and type(e.args[0]) is str:
618
+ e.args = ('%s: %s' % (name, e.args[0]),) + e.args[1:]