summaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/moduleobject.c
diff options
context:
space:
mode:
authorshadchin <[email protected]>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Objects/moduleobject.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
Restoring authorship annotation for <[email protected]>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Objects/moduleobject.c')
-rw-r--r--contrib/tools/python3/src/Objects/moduleobject.c184
1 files changed, 92 insertions, 92 deletions
diff --git a/contrib/tools/python3/src/Objects/moduleobject.c b/contrib/tools/python3/src/Objects/moduleobject.c
index 2707fbed521..ee4ed97588e 100644
--- a/contrib/tools/python3/src/Objects/moduleobject.c
+++ b/contrib/tools/python3/src/Objects/moduleobject.c
@@ -2,16 +2,16 @@
/* Module object implementation */
#include "Python.h"
-#include "pycore_interp.h" // PyInterpreterState.importlib
-#include "pycore_pystate.h" // _PyInterpreterState_GET()
-#include "structmember.h" // PyMemberDef
+#include "pycore_interp.h" // PyInterpreterState.importlib
+#include "pycore_pystate.h" // _PyInterpreterState_GET()
+#include "structmember.h" // PyMemberDef
static Py_ssize_t max_module_number;
-_Py_IDENTIFIER(__doc__);
-_Py_IDENTIFIER(__name__);
-_Py_IDENTIFIER(__spec__);
-
+_Py_IDENTIFIER(__doc__);
+_Py_IDENTIFIER(__name__);
+_Py_IDENTIFIER(__spec__);
+
typedef struct {
PyObject_HEAD
PyObject *md_dict;
@@ -42,8 +42,8 @@ PyModuleDef_Init(struct PyModuleDef* def)
return NULL;
if (def->m_base.m_index == 0) {
max_module_number++;
- Py_SET_REFCNT(def, 1);
- Py_SET_TYPE(def, &PyModuleDef_Type);
+ Py_SET_REFCNT(def, 1);
+ Py_SET_TYPE(def, &PyModuleDef_Type);
def->m_base.m_index = max_module_number;
}
return (PyObject*)def;
@@ -165,11 +165,11 @@ _add_methods_to_object(PyObject *module, PyObject *name, PyMethodDef *functions)
PyObject *
PyModule_Create2(struct PyModuleDef* module, int module_api_version)
{
- if (!_PyImport_IsInitialized(_PyInterpreterState_GET())) {
- PyErr_SetString(PyExc_SystemError,
- "Python import machinery not initialized");
- return NULL;
- }
+ if (!_PyImport_IsInitialized(_PyInterpreterState_GET())) {
+ PyErr_SetString(PyExc_SystemError,
+ "Python import machinery not initialized");
+ return NULL;
+ }
return _PyModule_CreateInitialized(module, module_api_version);
}
@@ -573,24 +573,24 @@ _PyModule_ClearDict(PyObject *d)
Py_ssize_t pos;
PyObject *key, *value;
- int verbose = _Py_GetConfig()->verbose;
-
+ int verbose = _Py_GetConfig()->verbose;
+
/* First, clear only names starting with a single underscore */
pos = 0;
while (PyDict_Next(d, &pos, &key, &value)) {
if (value != Py_None && PyUnicode_Check(key)) {
if (PyUnicode_READ_CHAR(key, 0) == '_' &&
PyUnicode_READ_CHAR(key, 1) != '_') {
- if (verbose > 1) {
+ if (verbose > 1) {
const char *s = PyUnicode_AsUTF8(key);
if (s != NULL)
PySys_WriteStderr("# clear[1] %s\n", s);
else
PyErr_Clear();
}
- if (PyDict_SetItem(d, key, Py_None) != 0) {
- PyErr_WriteUnraisable(NULL);
- }
+ if (PyDict_SetItem(d, key, Py_None) != 0) {
+ PyErr_WriteUnraisable(NULL);
+ }
}
}
}
@@ -602,16 +602,16 @@ _PyModule_ClearDict(PyObject *d)
if (PyUnicode_READ_CHAR(key, 0) != '_' ||
!_PyUnicode_EqualToASCIIString(key, "__builtins__"))
{
- if (verbose > 1) {
+ if (verbose > 1) {
const char *s = PyUnicode_AsUTF8(key);
if (s != NULL)
PySys_WriteStderr("# clear[2] %s\n", s);
else
PyErr_Clear();
}
- if (PyDict_SetItem(d, key, Py_None) != 0) {
- PyErr_WriteUnraisable(NULL);
- }
+ if (PyDict_SetItem(d, key, Py_None) != 0) {
+ PyErr_WriteUnraisable(NULL);
+ }
}
}
}
@@ -660,20 +660,20 @@ module___init___impl(PyModuleObject *self, PyObject *name, PyObject *doc)
static void
module_dealloc(PyModuleObject *m)
{
- int verbose = _Py_GetConfig()->verbose;
-
+ int verbose = _Py_GetConfig()->verbose;
+
PyObject_GC_UnTrack(m);
- if (verbose && m->md_name) {
- PySys_FormatStderr("# destroy %U\n", m->md_name);
+ if (verbose && m->md_name) {
+ PySys_FormatStderr("# destroy %U\n", m->md_name);
}
if (m->md_weaklist != NULL)
PyObject_ClearWeakRefs((PyObject *) m);
- /* bpo-39824: Don't call m_free() if m_size > 0 and md_state=NULL */
- if (m->md_def && m->md_def->m_free
- && (m->md_def->m_size <= 0 || m->md_state != NULL))
- {
+ /* bpo-39824: Don't call m_free() if m_size > 0 and md_state=NULL */
+ if (m->md_def && m->md_def->m_free
+ && (m->md_def->m_size <= 0 || m->md_state != NULL))
+ {
m->md_def->m_free(m);
- }
+ }
Py_XDECREF(m->md_dict);
Py_XDECREF(m->md_name);
if (m->md_state != NULL)
@@ -684,32 +684,32 @@ module_dealloc(PyModuleObject *m)
static PyObject *
module_repr(PyModuleObject *m)
{
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
return PyObject_CallMethod(interp->importlib, "_module_repr", "O", m);
}
-/* Check if the "_initializing" attribute of the module spec is set to true.
- Clear the exception and return 0 if spec is NULL.
- */
-int
-_PyModuleSpec_IsInitializing(PyObject *spec)
-{
- if (spec != NULL) {
- _Py_IDENTIFIER(_initializing);
- PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing);
- if (value != NULL) {
- int initializing = PyObject_IsTrue(value);
- Py_DECREF(value);
- if (initializing >= 0) {
- return initializing;
- }
- }
- }
- PyErr_Clear();
- return 0;
-}
-
+/* Check if the "_initializing" attribute of the module spec is set to true.
+ Clear the exception and return 0 if spec is NULL.
+ */
+int
+_PyModuleSpec_IsInitializing(PyObject *spec)
+{
+ if (spec != NULL) {
+ _Py_IDENTIFIER(_initializing);
+ PyObject *value = _PyObject_GetAttrId(spec, &PyId__initializing);
+ if (value != NULL) {
+ int initializing = PyObject_IsTrue(value);
+ Py_DECREF(value);
+ if (initializing >= 0) {
+ return initializing;
+ }
+ }
+ }
+ PyErr_Clear();
+ return 0;
+}
+
static PyObject*
module_getattro(PyModuleObject *m, PyObject *name)
{
@@ -723,27 +723,27 @@ module_getattro(PyModuleObject *m, PyObject *name)
_Py_IDENTIFIER(__getattr__);
getattr = _PyDict_GetItemId(m->md_dict, &PyId___getattr__);
if (getattr) {
- return PyObject_CallOneArg(getattr, name);
+ return PyObject_CallOneArg(getattr, name);
}
mod_name = _PyDict_GetItemId(m->md_dict, &PyId___name__);
if (mod_name && PyUnicode_Check(mod_name)) {
- Py_INCREF(mod_name);
- PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__);
- Py_XINCREF(spec);
- if (_PyModuleSpec_IsInitializing(spec)) {
- PyErr_Format(PyExc_AttributeError,
- "partially initialized "
- "module '%U' has no attribute '%U' "
- "(most likely due to a circular import)",
- mod_name, name);
- }
- else {
- PyErr_Format(PyExc_AttributeError,
- "module '%U' has no attribute '%U'",
- mod_name, name);
- }
- Py_XDECREF(spec);
- Py_DECREF(mod_name);
+ Py_INCREF(mod_name);
+ PyObject *spec = _PyDict_GetItemId(m->md_dict, &PyId___spec__);
+ Py_XINCREF(spec);
+ if (_PyModuleSpec_IsInitializing(spec)) {
+ PyErr_Format(PyExc_AttributeError,
+ "partially initialized "
+ "module '%U' has no attribute '%U' "
+ "(most likely due to a circular import)",
+ mod_name, name);
+ }
+ else {
+ PyErr_Format(PyExc_AttributeError,
+ "module '%U' has no attribute '%U'",
+ mod_name, name);
+ }
+ Py_XDECREF(spec);
+ Py_DECREF(mod_name);
return NULL;
}
}
@@ -755,10 +755,10 @@ module_getattro(PyModuleObject *m, PyObject *name)
static int
module_traverse(PyModuleObject *m, visitproc visit, void *arg)
{
- /* bpo-39824: Don't call m_traverse() if m_size > 0 and md_state=NULL */
- if (m->md_def && m->md_def->m_traverse
- && (m->md_def->m_size <= 0 || m->md_state != NULL))
- {
+ /* bpo-39824: Don't call m_traverse() if m_size > 0 and md_state=NULL */
+ if (m->md_def && m->md_def->m_traverse
+ && (m->md_def->m_size <= 0 || m->md_state != NULL))
+ {
int res = m->md_def->m_traverse((PyObject*)m, visit, arg);
if (res)
return res;
@@ -770,17 +770,17 @@ module_traverse(PyModuleObject *m, visitproc visit, void *arg)
static int
module_clear(PyModuleObject *m)
{
- /* bpo-39824: Don't call m_clear() if m_size > 0 and md_state=NULL */
- if (m->md_def && m->md_def->m_clear
- && (m->md_def->m_size <= 0 || m->md_state != NULL))
- {
+ /* bpo-39824: Don't call m_clear() if m_size > 0 and md_state=NULL */
+ if (m->md_def && m->md_def->m_clear
+ && (m->md_def->m_size <= 0 || m->md_state != NULL))
+ {
int res = m->md_def->m_clear((PyObject*)m);
- if (PyErr_Occurred()) {
- PySys_FormatStderr("Exception ignored in m_clear of module%s%V\n",
- m->md_name ? " " : "",
- m->md_name, "");
- PyErr_WriteUnraisable(NULL);
- }
+ if (PyErr_Occurred()) {
+ PySys_FormatStderr("Exception ignored in m_clear of module%s%V\n",
+ m->md_name ? " " : "",
+ m->md_name, "");
+ PyErr_WriteUnraisable(NULL);
+ }
if (res)
return res;
}
@@ -792,17 +792,17 @@ static PyObject *
module_dir(PyObject *self, PyObject *args)
{
_Py_IDENTIFIER(__dict__);
- _Py_IDENTIFIER(__dir__);
+ _Py_IDENTIFIER(__dir__);
PyObject *result = NULL;
PyObject *dict = _PyObject_GetAttrId(self, &PyId___dict__);
if (dict != NULL) {
if (PyDict_Check(dict)) {
- PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__);
+ PyObject *dirfunc = _PyDict_GetItemIdWithError(dict, &PyId___dir__);
if (dirfunc) {
result = _PyObject_CallNoArg(dirfunc);
}
- else if (!PyErr_Occurred()) {
+ else if (!PyErr_Occurred()) {
result = PyDict_Keys(dict);
}
}
@@ -831,10 +831,10 @@ PyTypeObject PyModule_Type = {
sizeof(PyModuleObject), /* tp_basicsize */
0, /* tp_itemsize */
(destructor)module_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
(reprfunc)module_repr, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */