Coverage Report

Created: 2025-07-11 06:59

/src/Python-3.8.3/Python/clinic/import.c.h
Line
Count
Source (jump to first uncovered line)
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 *
20
_imp_lock_held(PyObject *module, PyObject *Py_UNUSED(ignored))
21
0
{
22
0
    return _imp_lock_held_impl(module);
23
0
}
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 *
41
_imp_acquire_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
42
1.71k
{
43
1.71k
    return _imp_acquire_lock_impl(module);
44
1.71k
}
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 *
61
_imp_release_lock(PyObject *module, PyObject *Py_UNUSED(ignored))
62
1.71k
{
63
1.71k
    return _imp_release_lock_impl(module);
64
1.71k
}
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 *
85
_imp__fix_co_filename(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
86
235
{
87
235
    PyObject *return_value = NULL;
88
235
    PyCodeObject *code;
89
235
    PyObject *path;
90
91
235
    if (!_PyArg_CheckPositional("_fix_co_filename", nargs, 2, 2)) {
92
0
        goto exit;
93
0
    }
94
235
    if (!PyObject_TypeCheck(args[0], &PyCode_Type)) {
95
0
        _PyArg_BadArgument("_fix_co_filename", "argument 1", (&PyCode_Type)->tp_name, args[0]);
96
0
        goto exit;
97
0
    }
98
235
    code = (PyCodeObject *)args[0];
99
235
    if (!PyUnicode_Check(args[1])) {
100
0
        _PyArg_BadArgument("_fix_co_filename", "argument 2", "str", args[1]);
101
0
        goto exit;
102
0
    }
103
235
    if (PyUnicode_READY(args[1]) == -1) {
104
0
        goto exit;
105
0
    }
106
235
    path = args[1];
107
235
    return_value = _imp__fix_co_filename_impl(module, code, path);
108
109
235
exit:
110
235
    return return_value;
111
235
}
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 *
135
_imp_extension_suffixes(PyObject *module, PyObject *Py_UNUSED(ignored))
136
28
{
137
28
    return _imp_extension_suffixes_impl(module);
138
28
}
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 *
153
_imp_init_frozen(PyObject *module, PyObject *arg)
154
0
{
155
0
    PyObject *return_value = NULL;
156
0
    PyObject *name;
157
158
0
    if (!PyUnicode_Check(arg)) {
159
0
        _PyArg_BadArgument("init_frozen", "argument", "str", arg);
160
0
        goto exit;
161
0
    }
162
0
    if (PyUnicode_READY(arg) == -1) {
163
0
        goto exit;
164
0
    }
165
0
    name = arg;
166
0
    return_value = _imp_init_frozen_impl(module, name);
167
168
0
exit:
169
0
    return return_value;
170
0
}
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 *
185
_imp_get_frozen_object(PyObject *module, PyObject *arg)
186
28
{
187
28
    PyObject *return_value = NULL;
188
28
    PyObject *name;
189
190
28
    if (!PyUnicode_Check(arg)) {
191
0
        _PyArg_BadArgument("get_frozen_object", "argument", "str", arg);
192
0
        goto exit;
193
0
    }
194
28
    if (PyUnicode_READY(arg) == -1) {
195
0
        goto exit;
196
0
    }
197
28
    name = arg;
198
28
    return_value = _imp_get_frozen_object_impl(module, name);
199
200
28
exit:
201
28
    return return_value;
202
28
}
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 *
217
_imp_is_frozen_package(PyObject *module, PyObject *arg)
218
28
{
219
28
    PyObject *return_value = NULL;
220
28
    PyObject *name;
221
222
28
    if (!PyUnicode_Check(arg)) {
223
0
        _PyArg_BadArgument("is_frozen_package", "argument", "str", arg);
224
0
        goto exit;
225
0
    }
226
28
    if (PyUnicode_READY(arg) == -1) {
227
0
        goto exit;
228
0
    }
229
28
    name = arg;
230
28
    return_value = _imp_is_frozen_package_impl(module, name);
231
232
28
exit:
233
28
    return return_value;
234
28
}
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 *
249
_imp_is_builtin(PyObject *module, PyObject *arg)
250
417
{
251
417
    PyObject *return_value = NULL;
252
417
    PyObject *name;
253
254
417
    if (!PyUnicode_Check(arg)) {
255
0
        _PyArg_BadArgument("is_builtin", "argument", "str", arg);
256
0
        goto exit;
257
0
    }
258
417
    if (PyUnicode_READY(arg) == -1) {
259
0
        goto exit;
260
0
    }
261
417
    name = arg;
262
417
    return_value = _imp_is_builtin_impl(module, name);
263
264
417
exit:
265
417
    return return_value;
266
417
}
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 *
281
_imp_is_frozen(PyObject *module, PyObject *arg)
282
368
{
283
368
    PyObject *return_value = NULL;
284
368
    PyObject *name;
285
286
368
    if (!PyUnicode_Check(arg)) {
287
0
        _PyArg_BadArgument("is_frozen", "argument", "str", arg);
288
0
        goto exit;
289
0
    }
290
368
    if (PyUnicode_READY(arg) == -1) {
291
0
        goto exit;
292
0
    }
293
368
    name = arg;
294
368
    return_value = _imp_is_frozen_impl(module, name);
295
296
368
exit:
297
368
    return return_value;
298
368
}
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 *
315
_imp_create_dynamic(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
316
0
{
317
0
    PyObject *return_value = NULL;
318
0
    PyObject *spec;
319
0
    PyObject *file = NULL;
320
321
0
    if (!_PyArg_CheckPositional("create_dynamic", nargs, 1, 2)) {
322
0
        goto exit;
323
0
    }
324
0
    spec = args[0];
325
0
    if (nargs < 2) {
326
0
        goto skip_optional;
327
0
    }
328
0
    file = args[1];
329
0
skip_optional:
330
0
    return_value = _imp_create_dynamic_impl(module, spec, file);
331
332
0
exit:
333
0
    return return_value;
334
0
}
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 *
353
_imp_exec_dynamic(PyObject *module, PyObject *mod)
354
0
{
355
0
    PyObject *return_value = NULL;
356
0
    int _return_value;
357
358
0
    _return_value = _imp_exec_dynamic_impl(module, mod);
359
0
    if ((_return_value == -1) && PyErr_Occurred()) {
360
0
        goto exit;
361
0
    }
362
0
    return_value = PyLong_FromLong((long)_return_value);
363
364
0
exit:
365
0
    return return_value;
366
0
}
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 *
383
_imp_exec_builtin(PyObject *module, PyObject *mod)
384
176
{
385
176
    PyObject *return_value = NULL;
386
176
    int _return_value;
387
388
176
    _return_value = _imp_exec_builtin_impl(module, mod);
389
176
    if ((_return_value == -1) && PyErr_Occurred()) {
390
0
        goto exit;
391
0
    }
392
176
    return_value = PyLong_FromLong((long)_return_value);
393
394
176
exit:
395
176
    return return_value;
396
176
}
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 *
410
_imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
411
0
{
412
0
    PyObject *return_value = NULL;
413
0
    static const char * const _keywords[] = {"key", "source", NULL};
414
0
    static _PyArg_Parser _parser = {NULL, _keywords, "source_hash", 0};
415
0
    PyObject *argsbuf[2];
416
0
    long key;
417
0
    Py_buffer source = {NULL, NULL};
418
419
0
    args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
420
0
    if (!args) {
421
0
        goto exit;
422
0
    }
423
0
    if (PyFloat_Check(args[0])) {
424
0
        PyErr_SetString(PyExc_TypeError,
425
0
                        "integer argument expected, got float" );
426
0
        goto exit;
427
0
    }
428
0
    key = PyLong_AsLong(args[0]);
429
0
    if (key == -1 && PyErr_Occurred()) {
430
0
        goto exit;
431
0
    }
432
0
    if (PyObject_GetBuffer(args[1], &source, PyBUF_SIMPLE) != 0) {
433
0
        goto exit;
434
0
    }
435
0
    if (!PyBuffer_IsContiguous(&source, 'C')) {
436
0
        _PyArg_BadArgument("source_hash", "argument 'source'", "contiguous buffer", args[1]);
437
0
        goto exit;
438
0
    }
439
0
    return_value = _imp_source_hash_impl(module, key, &source);
440
441
0
exit:
442
    /* Cleanup for source */
443
0
    if (source.obj) {
444
0
       PyBuffer_Release(&source);
445
0
    }
446
447
0
    return return_value;
448
0
}
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]*/