You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

452 lines
12 KiB

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