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  {
      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 *
      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 *
      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_CAST(_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  {
      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 *
     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 *
     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_find_frozen__doc__,
     173  "find_frozen($module, name, /, *, withdata=False)\n"
     174  "--\n"
     175  "\n"
     176  "Return info about the corresponding frozen module (if there is one) or None.\n"
     177  "\n"
     178  "The returned info (a 2-tuple):\n"
     179  "\n"
     180  " * data         the raw marshalled bytes\n"
     181  " * is_package   whether or not it is a package\n"
     182  " * origname     the originally frozen module\'s name, or None if not\n"
     183  "                a stdlib module (this will usually be the same as\n"
     184  "                the module\'s current name)");
     185  
     186  #define _IMP_FIND_FROZEN_METHODDEF    \
     187      {"find_frozen", _PyCFunction_CAST(_imp_find_frozen), METH_FASTCALL|METH_KEYWORDS, _imp_find_frozen__doc__},
     188  
     189  static PyObject *
     190  _imp_find_frozen_impl(PyObject *module, PyObject *name, int withdata);
     191  
     192  static PyObject *
     193  _imp_find_frozen(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     194  {
     195      PyObject *return_value = NULL;
     196      static const char * const _keywords[] = {"", "withdata", NULL};
     197      static _PyArg_Parser _parser = {NULL, _keywords, "find_frozen", 0};
     198      PyObject *argsbuf[2];
     199      Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
     200      PyObject *name;
     201      int withdata = 0;
     202  
     203      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
     204      if (!args) {
     205          goto exit;
     206      }
     207      if (!PyUnicode_Check(args[0])) {
     208          _PyArg_BadArgument("find_frozen", "argument 1", "str", args[0]);
     209          goto exit;
     210      }
     211      if (PyUnicode_READY(args[0]) == -1) {
     212          goto exit;
     213      }
     214      name = args[0];
     215      if (!noptargs) {
     216          goto skip_optional_kwonly;
     217      }
     218      withdata = PyObject_IsTrue(args[1]);
     219      if (withdata < 0) {
     220          goto exit;
     221      }
     222  skip_optional_kwonly:
     223      return_value = _imp_find_frozen_impl(module, name, withdata);
     224  
     225  exit:
     226      return return_value;
     227  }
     228  
     229  PyDoc_STRVAR(_imp_get_frozen_object__doc__,
     230  "get_frozen_object($module, name, data=None, /)\n"
     231  "--\n"
     232  "\n"
     233  "Create a code object for a frozen module.");
     234  
     235  #define _IMP_GET_FROZEN_OBJECT_METHODDEF    \
     236      {"get_frozen_object", _PyCFunction_CAST(_imp_get_frozen_object), METH_FASTCALL, _imp_get_frozen_object__doc__},
     237  
     238  static PyObject *
     239  _imp_get_frozen_object_impl(PyObject *module, PyObject *name,
     240                              PyObject *dataobj);
     241  
     242  static PyObject *
     243  _imp_get_frozen_object(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     244  {
     245      PyObject *return_value = NULL;
     246      PyObject *name;
     247      PyObject *dataobj = Py_None;
     248  
     249      if (!_PyArg_CheckPositional("get_frozen_object", nargs, 1, 2)) {
     250          goto exit;
     251      }
     252      if (!PyUnicode_Check(args[0])) {
     253          _PyArg_BadArgument("get_frozen_object", "argument 1", "str", args[0]);
     254          goto exit;
     255      }
     256      if (PyUnicode_READY(args[0]) == -1) {
     257          goto exit;
     258      }
     259      name = args[0];
     260      if (nargs < 2) {
     261          goto skip_optional;
     262      }
     263      dataobj = args[1];
     264  skip_optional:
     265      return_value = _imp_get_frozen_object_impl(module, name, dataobj);
     266  
     267  exit:
     268      return return_value;
     269  }
     270  
     271  PyDoc_STRVAR(_imp_is_frozen_package__doc__,
     272  "is_frozen_package($module, name, /)\n"
     273  "--\n"
     274  "\n"
     275  "Returns True if the module name is of a frozen package.");
     276  
     277  #define _IMP_IS_FROZEN_PACKAGE_METHODDEF    \
     278      {"is_frozen_package", (PyCFunction)_imp_is_frozen_package, METH_O, _imp_is_frozen_package__doc__},
     279  
     280  static PyObject *
     281  _imp_is_frozen_package_impl(PyObject *module, PyObject *name);
     282  
     283  static PyObject *
     284  _imp_is_frozen_package(PyObject *module, PyObject *arg)
     285  {
     286      PyObject *return_value = NULL;
     287      PyObject *name;
     288  
     289      if (!PyUnicode_Check(arg)) {
     290          _PyArg_BadArgument("is_frozen_package", "argument", "str", arg);
     291          goto exit;
     292      }
     293      if (PyUnicode_READY(arg) == -1) {
     294          goto exit;
     295      }
     296      name = arg;
     297      return_value = _imp_is_frozen_package_impl(module, name);
     298  
     299  exit:
     300      return return_value;
     301  }
     302  
     303  PyDoc_STRVAR(_imp_is_builtin__doc__,
     304  "is_builtin($module, name, /)\n"
     305  "--\n"
     306  "\n"
     307  "Returns True if the module name corresponds to a built-in module.");
     308  
     309  #define _IMP_IS_BUILTIN_METHODDEF    \
     310      {"is_builtin", (PyCFunction)_imp_is_builtin, METH_O, _imp_is_builtin__doc__},
     311  
     312  static PyObject *
     313  _imp_is_builtin_impl(PyObject *module, PyObject *name);
     314  
     315  static PyObject *
     316  _imp_is_builtin(PyObject *module, PyObject *arg)
     317  {
     318      PyObject *return_value = NULL;
     319      PyObject *name;
     320  
     321      if (!PyUnicode_Check(arg)) {
     322          _PyArg_BadArgument("is_builtin", "argument", "str", arg);
     323          goto exit;
     324      }
     325      if (PyUnicode_READY(arg) == -1) {
     326          goto exit;
     327      }
     328      name = arg;
     329      return_value = _imp_is_builtin_impl(module, name);
     330  
     331  exit:
     332      return return_value;
     333  }
     334  
     335  PyDoc_STRVAR(_imp_is_frozen__doc__,
     336  "is_frozen($module, name, /)\n"
     337  "--\n"
     338  "\n"
     339  "Returns True if the module name corresponds to a frozen module.");
     340  
     341  #define _IMP_IS_FROZEN_METHODDEF    \
     342      {"is_frozen", (PyCFunction)_imp_is_frozen, METH_O, _imp_is_frozen__doc__},
     343  
     344  static PyObject *
     345  _imp_is_frozen_impl(PyObject *module, PyObject *name);
     346  
     347  static PyObject *
     348  _imp_is_frozen(PyObject *module, PyObject *arg)
     349  {
     350      PyObject *return_value = NULL;
     351      PyObject *name;
     352  
     353      if (!PyUnicode_Check(arg)) {
     354          _PyArg_BadArgument("is_frozen", "argument", "str", arg);
     355          goto exit;
     356      }
     357      if (PyUnicode_READY(arg) == -1) {
     358          goto exit;
     359      }
     360      name = arg;
     361      return_value = _imp_is_frozen_impl(module, name);
     362  
     363  exit:
     364      return return_value;
     365  }
     366  
     367  PyDoc_STRVAR(_imp__frozen_module_names__doc__,
     368  "_frozen_module_names($module, /)\n"
     369  "--\n"
     370  "\n"
     371  "Returns the list of available frozen modules.");
     372  
     373  #define _IMP__FROZEN_MODULE_NAMES_METHODDEF    \
     374      {"_frozen_module_names", (PyCFunction)_imp__frozen_module_names, METH_NOARGS, _imp__frozen_module_names__doc__},
     375  
     376  static PyObject *
     377  _imp__frozen_module_names_impl(PyObject *module);
     378  
     379  static PyObject *
     380  _imp__frozen_module_names(PyObject *module, PyObject *Py_UNUSED(ignored))
     381  {
     382      return _imp__frozen_module_names_impl(module);
     383  }
     384  
     385  PyDoc_STRVAR(_imp__override_frozen_modules_for_tests__doc__,
     386  "_override_frozen_modules_for_tests($module, override, /)\n"
     387  "--\n"
     388  "\n"
     389  "(internal-only) Override PyConfig.use_frozen_modules.\n"
     390  "\n"
     391  "(-1: \"off\", 1: \"on\", 0: no override)\n"
     392  "See frozen_modules() in Lib/test/support/import_helper.py.");
     393  
     394  #define _IMP__OVERRIDE_FROZEN_MODULES_FOR_TESTS_METHODDEF    \
     395      {"_override_frozen_modules_for_tests", (PyCFunction)_imp__override_frozen_modules_for_tests, METH_O, _imp__override_frozen_modules_for_tests__doc__},
     396  
     397  static PyObject *
     398  _imp__override_frozen_modules_for_tests_impl(PyObject *module, int override);
     399  
     400  static PyObject *
     401  _imp__override_frozen_modules_for_tests(PyObject *module, PyObject *arg)
     402  {
     403      PyObject *return_value = NULL;
     404      int override;
     405  
     406      override = _PyLong_AsInt(arg);
     407      if (override == -1 && PyErr_Occurred()) {
     408          goto exit;
     409      }
     410      return_value = _imp__override_frozen_modules_for_tests_impl(module, override);
     411  
     412  exit:
     413      return return_value;
     414  }
     415  
     416  #if defined(HAVE_DYNAMIC_LOADING)
     417  
     418  PyDoc_STRVAR(_imp_create_dynamic__doc__,
     419  "create_dynamic($module, spec, file=<unrepresentable>, /)\n"
     420  "--\n"
     421  "\n"
     422  "Create an extension module.");
     423  
     424  #define _IMP_CREATE_DYNAMIC_METHODDEF    \
     425      {"create_dynamic", _PyCFunction_CAST(_imp_create_dynamic), METH_FASTCALL, _imp_create_dynamic__doc__},
     426  
     427  static PyObject *
     428  _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file);
     429  
     430  static PyObject *
     431  _imp_create_dynamic(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
     432  {
     433      PyObject *return_value = NULL;
     434      PyObject *spec;
     435      PyObject *file = NULL;
     436  
     437      if (!_PyArg_CheckPositional("create_dynamic", nargs, 1, 2)) {
     438          goto exit;
     439      }
     440      spec = args[0];
     441      if (nargs < 2) {
     442          goto skip_optional;
     443      }
     444      file = args[1];
     445  skip_optional:
     446      return_value = _imp_create_dynamic_impl(module, spec, file);
     447  
     448  exit:
     449      return return_value;
     450  }
     451  
     452  #endif /* defined(HAVE_DYNAMIC_LOADING) */
     453  
     454  #if defined(HAVE_DYNAMIC_LOADING)
     455  
     456  PyDoc_STRVAR(_imp_exec_dynamic__doc__,
     457  "exec_dynamic($module, mod, /)\n"
     458  "--\n"
     459  "\n"
     460  "Initialize an extension module.");
     461  
     462  #define _IMP_EXEC_DYNAMIC_METHODDEF    \
     463      {"exec_dynamic", (PyCFunction)_imp_exec_dynamic, METH_O, _imp_exec_dynamic__doc__},
     464  
     465  static int
     466  _imp_exec_dynamic_impl(PyObject *module, PyObject *mod);
     467  
     468  static PyObject *
     469  _imp_exec_dynamic(PyObject *module, PyObject *mod)
     470  {
     471      PyObject *return_value = NULL;
     472      int _return_value;
     473  
     474      _return_value = _imp_exec_dynamic_impl(module, mod);
     475      if ((_return_value == -1) && PyErr_Occurred()) {
     476          goto exit;
     477      }
     478      return_value = PyLong_FromLong((long)_return_value);
     479  
     480  exit:
     481      return return_value;
     482  }
     483  
     484  #endif /* defined(HAVE_DYNAMIC_LOADING) */
     485  
     486  PyDoc_STRVAR(_imp_exec_builtin__doc__,
     487  "exec_builtin($module, mod, /)\n"
     488  "--\n"
     489  "\n"
     490  "Initialize a built-in module.");
     491  
     492  #define _IMP_EXEC_BUILTIN_METHODDEF    \
     493      {"exec_builtin", (PyCFunction)_imp_exec_builtin, METH_O, _imp_exec_builtin__doc__},
     494  
     495  static int
     496  _imp_exec_builtin_impl(PyObject *module, PyObject *mod);
     497  
     498  static PyObject *
     499  _imp_exec_builtin(PyObject *module, PyObject *mod)
     500  {
     501      PyObject *return_value = NULL;
     502      int _return_value;
     503  
     504      _return_value = _imp_exec_builtin_impl(module, mod);
     505      if ((_return_value == -1) && PyErr_Occurred()) {
     506          goto exit;
     507      }
     508      return_value = PyLong_FromLong((long)_return_value);
     509  
     510  exit:
     511      return return_value;
     512  }
     513  
     514  PyDoc_STRVAR(_imp_source_hash__doc__,
     515  "source_hash($module, /, key, source)\n"
     516  "--\n"
     517  "\n");
     518  
     519  #define _IMP_SOURCE_HASH_METHODDEF    \
     520      {"source_hash", _PyCFunction_CAST(_imp_source_hash), METH_FASTCALL|METH_KEYWORDS, _imp_source_hash__doc__},
     521  
     522  static PyObject *
     523  _imp_source_hash_impl(PyObject *module, long key, Py_buffer *source);
     524  
     525  static PyObject *
     526  _imp_source_hash(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
     527  {
     528      PyObject *return_value = NULL;
     529      static const char * const _keywords[] = {"key", "source", NULL};
     530      static _PyArg_Parser _parser = {NULL, _keywords, "source_hash", 0};
     531      PyObject *argsbuf[2];
     532      long key;
     533      Py_buffer source = {NULL, NULL};
     534  
     535      args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
     536      if (!args) {
     537          goto exit;
     538      }
     539      key = PyLong_AsLong(args[0]);
     540      if (key == -1 && PyErr_Occurred()) {
     541          goto exit;
     542      }
     543      if (PyObject_GetBuffer(args[1], &source, PyBUF_SIMPLE) != 0) {
     544          goto exit;
     545      }
     546      if (!PyBuffer_IsContiguous(&source, 'C')) {
     547          _PyArg_BadArgument("source_hash", "argument 'source'", "contiguous buffer", args[1]);
     548          goto exit;
     549      }
     550      return_value = _imp_source_hash_impl(module, key, &source);
     551  
     552  exit:
     553      /* Cleanup for source */
     554      if (source.obj) {
     555         PyBuffer_Release(&source);
     556      }
     557  
     558      return return_value;
     559  }
     560  
     561  #ifndef _IMP_CREATE_DYNAMIC_METHODDEF
     562      #define _IMP_CREATE_DYNAMIC_METHODDEF
     563  #endif /* !defined(_IMP_CREATE_DYNAMIC_METHODDEF) */
     564  
     565  #ifndef _IMP_EXEC_DYNAMIC_METHODDEF
     566      #define _IMP_EXEC_DYNAMIC_METHODDEF
     567  #endif /* !defined(_IMP_EXEC_DYNAMIC_METHODDEF) */
     568  /*[clinic end generated code: output=8d0f4305b1d0714b input=a9049054013a1b77]*/