moduleobject.c.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(module___init____doc__,
  9. "module(name, doc=None)\n"
  10. "--\n"
  11. "\n"
  12. "Create a module object.\n"
  13. "\n"
  14. "The name must be a string; the optional doc argument can have any type.");
  15. static int
  16. module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc);
  17. static int
  18. module___init__(PyObject *self, PyObject *args, PyObject *kwargs)
  19. {
  20. int return_value = -1;
  21. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  22. #define NUM_KEYWORDS 2
  23. static struct {
  24. PyGC_Head _this_is_not_used;
  25. PyObject_VAR_HEAD
  26. PyObject *ob_item[NUM_KEYWORDS];
  27. } _kwtuple = {
  28. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  29. .ob_item = { &_Py_ID(name), &_Py_ID(doc), },
  30. };
  31. #undef NUM_KEYWORDS
  32. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  33. #else // !Py_BUILD_CORE
  34. # define KWTUPLE NULL
  35. #endif // !Py_BUILD_CORE
  36. static const char * const _keywords[] = {"name", "doc", NULL};
  37. static _PyArg_Parser _parser = {
  38. .keywords = _keywords,
  39. .fname = "module",
  40. .kwtuple = KWTUPLE,
  41. };
  42. #undef KWTUPLE
  43. PyObject *argsbuf[2];
  44. PyObject * const *fastargs;
  45. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  46. Py_ssize_t noptargs = nargs + (kwargs ? PyDict_GET_SIZE(kwargs) : 0) - 1;
  47. PyObject *name;
  48. PyObject *doc = Py_None;
  49. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 2, 0, argsbuf);
  50. if (!fastargs) {
  51. goto exit;
  52. }
  53. if (!PyUnicode_Check(fastargs[0])) {
  54. _PyArg_BadArgument("module", "argument 'name'", "str", fastargs[0]);
  55. goto exit;
  56. }
  57. if (PyUnicode_READY(fastargs[0]) == -1) {
  58. goto exit;
  59. }
  60. name = fastargs[0];
  61. if (!noptargs) {
  62. goto skip_optional_pos;
  63. }
  64. doc = fastargs[1];
  65. skip_optional_pos:
  66. return_value = module___init___impl((PyModuleObject *)self, name, doc);
  67. exit:
  68. return return_value;
  69. }
  70. /*[clinic end generated code: output=2f897c9e4721f03f input=a9049054013a1b77]*/