1 /*[clinic input]
2 preserve
3 [clinic start generated code]*/
4
5 PyDoc_STRVAR(_imp_lock_held__doc__,
6 "lock_held($module, /)\n"
7 "--\n"
8 "\n"
9 "Return True if the import lock is currently held, else False.\n"
10 "\n"
11 "On platforms without threads, return False.");
12
13 #define _IMP_LOCK_HELD_METHODDEF \
14 {"lock_held", (PyCFunction)_imp_lock_held, METH_NOARGS, _imp_lock_held__doc__},
15
16 static PyObject *
17 _imp_lock_held_impl(PyObject *module);
18
19 static PyObject *
_imp_lock_held(PyObject * module,PyObject * Py_UNUSED (ignored))20 _imp_lock_held(PyObject *module, PyObject *Py_UNUSED(ignored))
21 {
22 return _imp_lock_held_impl(module);
23 }
24
25 PyDoc_STRVAR(_imp_acquire_lock__doc__,
26 "acquire_lock($module, /)\n"
27 "--\n"
28 "\n"
29 "Acquires the interpreter\'s import lock for the current thread.\n"
30 "\n"
31 "This lock should be used by import hooks to ensure thread-safety when importing\n"
32 "modules. On platforms without threads, this function does nothing.");
33
34 #define _IMP_ACQUIRE_LOCK_METHODDEF \
35 {"acquire_lock", (PyCFunction)_imp_acquire_lock, METH_NOARGS, _imp_acquire_lock__doc__},
36
37 static PyObject *
38 _imp_acquire_lock_impl(PyObject *module);
39
40 static PyObject *
_imp_acquire_lock(PyObject * module,PyObject * Py_UNUSED (ignored))41 _imp_acquire_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
42 {
43 return _imp_acquire_lock_impl(module);
44 }
45
46 PyDoc_STRVAR(_imp_release_lock__doc__,
47 "release_lock($module, /)\n"
48 "--\n"
49 "\n"
50 "Release the interpreter\'s import lock.\n"
51 "\n"
52 "On platforms without threads, this function does nothing.");
53
54 #define _IMP_RELEASE_LOCK_METHODDEF \
55 {"release_lock", (PyCFunction)_imp_release_lock, METH_NOARGS, _imp_release_lock__doc__},
56
57 static PyObject *
58 _imp_release_lock_impl(PyObject *module);
59
60 static PyObject *
_imp_release_lock(PyObject * module,PyObject * Py_UNUSED (ignored))61 _imp_release_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
62 {
63 return _imp_release_lock_impl(module);
64 }
65
66 PyDoc_STRVAR(_imp__fix_co_filename__doc__,
67 "_fix_co_filename($module, code, path, /)\n"
68 "--\n"
69 "\n"
70 "Changes code.co_filename to specify the passed-in file path.\n"
71 "\n"
72 " code\n"
73 " Code object to change.\n"
74 " path\n"
75 " File path to use.");
76
77 #define _IMP__FIX_CO_FILENAME_METHODDEF \
78 {"_fix_co_filename", (PyCFunction)(void(*)(void))_imp__fix_co_filename, METH_FASTCALL, _imp__fix_co_filename__doc__},
79
80 static PyObject *
81 _imp__fix_co_filename_impl(PyObject *module, PyCodeObject *code,
82 PyObject *path);
83
84 static PyObject *
_imp__fix_co_filename(PyObject * module,PyObject * const * args,Py_ssize_t nargs)85 _imp__fix_co_filename(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
86 {
87 PyObject *return_value = NULL;
88 PyCodeObject *code;
89 PyObject *path;
90
91 if (!_PyArg_CheckPositional("_fix_co_filename", nargs, 2, 2)) {
92 goto exit;
93 }
94 if (!PyObject_TypeCheck(args[0], &PyCode_Type)) {
95 _PyArg_BadArgument("_fix_co_filename", "argument 1", (&PyCode_Type)->tp_name, args[0]);
96 goto exit;
97 }
98 code = (PyCodeObject *)args[0];
99 if (!PyUnicode_Check(args[1])) {
100 _PyArg_BadArgument("_fix_co_filename", "argument 2", "str", args[1]);
101 goto exit;
102 }
103 if (PyUnicode_READY(args[1]) == -1) {
104 goto exit;
105 }
106 path = args[1];
107 return_value = _imp__fix_co_filename_impl(module, code, path);
108
109 exit:
110 return return_value;
111 }
112
113 PyDoc_STRVAR(_imp_create_builtin__doc__,
114 "create_builtin($module, spec, /)\n"
115 "--\n"
116 "\n"
117 "Create an extension module.");
118
119 #define _IMP_CREATE_BUILTIN_METHODDEF \
120 {"create_builtin", (PyCFunction)_imp_create_builtin, METH_O, _imp_create_builtin__doc__},
121
122 PyDoc_STRVAR(_imp_extension_suffixes__doc__,
123 "extension_suffixes($module, /)\n"
124 "--\n"
125 "\n"
126 "Returns the list of file suffixes used to identify extension modules.");
127
128 #define _IMP_EXTENSION_SUFFIXES_METHODDEF \
129 {"extension_suffixes", (PyCFunction)_imp_extension_suffixes, METH_NOARGS, _imp_extension_suffixes__doc__},
130
131 static PyObject *
132 _imp_extension_suffixes_impl(PyObject *module);
133
134 static PyObject *
_imp_extension_suffixes(PyObject * module,PyObject * Py_UNUSED (ignored))135 _imp_extension_suffixes(PyObject *module, PyObject *Py_UNUSED(ignored))
136 {
137 return _imp_extension_suffixes_impl(module);
138 }
139
140 PyDoc_STRVAR(_imp_init_frozen__doc__,
141 "init_frozen($module, name, /)\n"
142 "--\n"
143 "\n"
144 "Initializes a frozen module.");
145
146 #define _IMP_INIT_FROZEN_METHODDEF \
147 {"init_frozen", (PyCFunction)_imp_init_frozen, METH_O, _imp_init_frozen__doc__},
148
149 static PyObject *
150 _imp_init_frozen_impl(PyObject *module, PyObject *name);
151
152 static PyObject *
_imp_init_frozen(PyObject * module,PyObject * arg)153 _imp_init_frozen(PyObject *module, PyObject *arg)
154 {
155 PyObject *return_value = NULL;
156 PyObject *name;
157
158 if (!PyUnicode_Check(arg)) {
159 _PyArg_BadArgument("init_frozen", "argument", "str", arg);
160 goto exit;
161 }
162 if (PyUnicode_READY(arg) == -1) {
163 goto exit;
164 }
165 name = arg;
166 return_value = _imp_init_frozen_impl(module, name);
167
168 exit:
169 return return_value;
170 }
171
172 PyDoc_STRVAR(_imp_get_frozen_object__doc__,
173 "get_frozen_object($module, name, /)\n"
174 "--\n"
175 "\n"
176 "Create a code object for a frozen module.");
177
178 #define _IMP_GET_FROZEN_OBJECT_METHODDEF \
179 {"get_frozen_object", (PyCFunction)_imp_get_frozen_object, METH_O, _imp_get_frozen_object__doc__},
180
181 static PyObject *
182 _imp_get_frozen_object_impl(PyObject *module, PyObject *name);
183
184 static PyObject *
_imp_get_frozen_object(PyObject * module,PyObject * arg)185 _imp_get_frozen_object(PyObject *module, PyObject *arg)
186 {
187 PyObject *return_value = NULL;
188 PyObject *name;
189
190 if (!PyUnicode_Check(arg)) {
191 _PyArg_BadArgument("get_frozen_object", "argument", "str", arg);
192 goto exit;
193 }
194 if (PyUnicode_READY(arg) == -1) {
195 goto exit;
196 }
197 name = arg;
198 return_value = _imp_get_frozen_object_impl(module, name);
199
200 exit:
201 return return_value;
202 }
203
204 PyDoc_STRVAR(_imp_is_frozen_package__doc__,
205 "is_frozen_package($module, name, /)\n"
206 "--\n"
207 "\n"
208 "Returns True if the module name is of a frozen package.");
209
210 #define _IMP_IS_FROZEN_PACKAGE_METHODDEF \
211 {"is_frozen_package", (PyCFunction)_imp_is_frozen_package, METH_O, _imp_is_frozen_package__doc__},
212
213 static PyObject *
214 _imp_is_frozen_package_impl(PyObject *module, PyObject *name);
215
216 static PyObject *
_imp_is_frozen_package(PyObject * module,PyObject * arg)217 _imp_is_frozen_package(PyObject *module, PyObject *arg)
218 {
219 PyObject *return_value = NULL;
220 PyObject *name;
221
222 if (!PyUnicode_Check(arg)) {
223 _PyArg_BadArgument("is_frozen_package", "argument", "str", arg);
224 goto exit;
225 }
226 if (PyUnicode_READY(arg) == -1) {
227 goto exit;
228 }
229 name = arg;
230 return_value = _imp_is_frozen_package_impl(module, name);
231
232 exit:
233 return return_value;
234 }
235
236 PyDoc_STRVAR(_imp_is_builtin__doc__,
237 "is_builtin($module, name, /)\n"
238 "--\n"
239 "\n"
240 "Returns True if the module name corresponds to a built-in module.");
241
242 #define _IMP_IS_BUILTIN_METHODDEF \
243 {"is_builtin", (PyCFunction)_imp_is_builtin, METH_O, _imp_is_builtin__doc__},
244
245 static PyObject *
246 _imp_is_builtin_impl(PyObject *module, PyObject *name);
247
248 static PyObject *
_imp_is_builtin(PyObject * module,PyObject * arg)249 _imp_is_builtin(PyObject *module, PyObject *arg)
250 {
251 PyObject *return_value = NULL;
252 PyObject *name;
253
254 if (!PyUnicode_Check(arg)) {
255 _PyArg_BadArgument("is_builtin", "argument", "str", arg);
256 goto exit;
257 }
258 if (PyUnicode_READY(arg) == -1) {
259 goto exit;
260 }
261 name = arg;
262 return_value = _imp_is_builtin_impl(module, name);
263
264 exit:
265 return return_value;
266 }
267
268 PyDoc_STRVAR(_imp_is_frozen__doc__,
269 "is_frozen($module, name, /)\n"
270 "--\n"
271 "\n"
272 "Returns True if the module name corresponds to a frozen module.");
273
274 #define _IMP_IS_FROZEN_METHODDEF \
275 {"is_frozen", (PyCFunction)_imp_is_frozen, METH_O, _imp_is_frozen__doc__},
276
277 static PyObject *
278 _imp_is_frozen_impl(PyObject *module, PyObject *name);
279
280 static PyObject *
_imp_is_frozen(PyObject * module,PyObject * arg)281 _imp_is_frozen(PyObject *module, PyObject *arg)
282 {
283 PyObject *return_value = NULL;
284 PyObject *name;
285
286 if (!PyUnicode_Check(arg)) {
287 _PyArg_BadArgument("is_frozen", "argument", "str", arg);
288 goto exit;
289 }
290 if (PyUnicode_READY(arg) == -1) {
291 goto exit;
292 }
293 name = arg;
294 return_value = _imp_is_frozen_impl(module, name);
295
296 exit:
297 return return_value;
298 }
299
300 #if defined(HAVE_DYNAMIC_LOADING)
301
302 PyDoc_STRVAR(_imp_create_dynamic__doc__,
303 "create_dynamic($module, spec, file=<unrepresentable>, /)\n"
304 "--\n"
305 "\n"
306 "Create an extension module.");
307
308 #define _IMP_CREATE_DYNAMIC_METHODDEF \
309 {"create_dynamic", (PyCFunction)(void(*)(void))_imp_create_dynamic, METH_FASTCALL, _imp_create_dynamic__doc__},
310
311 static PyObject *
312 _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file);
313
314 static PyObject *
_imp_create_dynamic(PyObject * module,PyObject * const * args,Py_ssize_t nargs)315 _imp_create_dynamic(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
316 {
317 PyObject *return_value = NULL;
318 PyObject *spec;
319 PyObject *file = NULL;
320
321 if (!_PyArg_CheckPositional("create_dynamic", nargs, 1, 2)) {
322 goto exit;
323 }
324 spec = args[0];
325 if (nargs < 2) {
326 goto skip_optional;
327 }
328 file = args[1];
329 skip_optional:
330 return_value = _imp_create_dynamic_impl(module, spec, file);
331
332 exit:
333 return return_value;
334 }
335
336 #endif /* defined(HAVE_DYNAMIC_LOADING) */
337
338 #if defined(HAVE_DYNAMIC_LOADING)
339
340 PyDoc_STRVAR(_imp_exec_dynamic__doc__,
341 "exec_dynamic($module, mod, /)\n"
342 "--\n"
343 "\n"
344 "Initialize an extension module.");
345
346 #define _IMP_EXEC_DYNAMIC_METHODDEF \
347 {"exec_dynamic", (PyCFunction)_imp_exec_dynamic, METH_O, _imp_exec_dynamic__doc__},
348
349 static int
350 _imp_exec_dynamic_impl(PyObject *module, PyObject *mod);
351
352 static PyObject *
_imp_exec_dynamic(PyObject * module,PyObject * mod)353 _imp_exec_dynamic(PyObject *module, PyObject *mod)
354 {
355 PyObject *return_value = NULL;
356 int _return_value;
357
358 _return_value = _imp_exec_dynamic_impl(module, mod);
359 if ((_return_value == -1) && PyErr_Occurred()) {
360 goto exit;
361 }
362 return_value = PyLong_FromLong((long)_return_value);
363
364 exit:
365 return return_value;
366 }
367
368 #endif /* defined(HAVE_DYNAMIC_LOADING) */
369
370 PyDoc_STRVAR(_imp_exec_builtin__doc__,
371 "exec_builtin($module, mod, /)\n"
372 "--\n"
373 "\n"
374 "Initialize a built-in module.");
375
376 #define _IMP_EXEC_BUILTIN_METHODDEF \
377 {"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, _imp_exec_builtin__doc__},
378
379 static int
380 _imp_exec_builtin_impl(PyObject *module, PyObject *mod);
381
382 static PyObject *
_imp_exec_builtin(PyObject * module,PyObject * mod)383 _imp_exec_builtin(PyObject *module, PyObject *mod)
384 {
385 PyObject *return_value = NULL;
386 int _return_value;
387
388 _return_value = _imp_exec_builtin_impl(module, mod);
389 if ((_return_value == -1) && PyErr_Occurred()) {
390 goto exit;
391 }
392 return_value = PyLong_FromLong((long)_return_value);
393
394 exit:
395 return return_value;
396 }
397
398 PyDoc_STRVAR(_imp_source_hash__doc__,
399 "source_hash($module, /, key, source)\n"
400 "--\n"
401 "\n");
402
403 #define _IMP_SOURCE_HASH_METHODDEF \
404 {"source_hash", (PyCFunction)(void(*)(void))_imp_source_hash, METH_FASTCALL|METH_KEYWORDS, _imp_source_hash__doc__},
405
406 static PyObject *
407 _imp_source_hash_impl(PyObject *module, long key, Py_buffer *source);
408
409 static PyObject *
_imp_source_hash(PyObject * module,PyObject * const * args,Py_ssize_t nargs,PyObject * kwnames)410 _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
411 {
412 PyObject *return_value = NULL;
413 static const char * const _keywords[] = {"key", "source", NULL};
414 static _PyArg_Parser _parser = {NULL, _keywords, "source_hash", 0};
415 PyObject *argsbuf[2];
416 long key;
417 Py_buffer source = {NULL, NULL};
418
419 args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
420 if (!args) {
421 goto exit;
422 }
423 if (PyFloat_Check(args[0])) {
424 PyErr_SetString(PyExc_TypeError,
425 "integer argument expected, got float" );
426 goto exit;
427 }
428 key = PyLong_AsLong(args[0]);
429 if (key == -1 && PyErr_Occurred()) {
430 goto exit;
431 }
432 if (PyObject_GetBuffer(args[1], &source, PyBUF_SIMPLE) != 0) {
433 goto exit;
434 }
435 if (!PyBuffer_IsContiguous(&source, 'C')) {
436 _PyArg_BadArgument("source_hash", "argument 'source'", "contiguous buffer", args[1]);
437 goto exit;
438 }
439 return_value = _imp_source_hash_impl(module, key, &source);
440
441 exit:
442 /* Cleanup for source */
443 if (source.obj) {
444 PyBuffer_Release(&source);
445 }
446
447 return return_value;
448 }
449
450 #ifndef _IMP_CREATE_DYNAMIC_METHODDEF
451 #define _IMP_CREATE_DYNAMIC_METHODDEF
452 #endif /* !defined(_IMP_CREATE_DYNAMIC_METHODDEF) */
453
454 #ifndef _IMP_EXEC_DYNAMIC_METHODDEF
455 #define _IMP_EXEC_DYNAMIC_METHODDEF
456 #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
457 /*[clinic end generated code: output=3dc495e9c64d944e input=a9049054013a1b77]*/
458