--- /dev/null
+Use inline function to replace extension modules' get_module_state macros.
\ No newline at end of file
long field_limit; /* max parsed field size */
} _csvstate;
-#define _csvstate(o) ((_csvstate *)PyModule_GetState(o))
+static inline _csvstate*
+get_csv_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_csvstate *)state;
+}
static int
_csv_clear(PyObject *m)
{
- Py_CLEAR(_csvstate(m)->error_obj);
- Py_CLEAR(_csvstate(m)->dialects);
+ Py_CLEAR(get_csv_state(m)->error_obj);
+ Py_CLEAR(get_csv_state(m)->dialects);
return 0;
}
static int
_csv_traverse(PyObject *m, visitproc visit, void *arg)
{
- Py_VISIT(_csvstate(m)->error_obj);
- Py_VISIT(_csvstate(m)->dialects);
+ Py_VISIT(get_csv_state(m)->error_obj);
+ Py_VISIT(get_csv_state(m)->dialects);
return 0;
}
return NULL;
/* Set the field limit */
- _csvstate(module)->field_limit = 128 * 1024;
+ get_csv_state(module)->field_limit = 128 * 1024;
/* Do I still need to add this var to the Module Dict? */
/* Add _dialects dictionary */
- _csvstate(module)->dialects = PyDict_New();
- if (_csvstate(module)->dialects == NULL)
+ get_csv_state(module)->dialects = PyDict_New();
+ if (get_csv_state(module)->dialects == NULL)
return NULL;
- Py_INCREF(_csvstate(module)->dialects);
- if (PyModule_AddObject(module, "_dialects", _csvstate(module)->dialects))
+ Py_INCREF(get_csv_state(module)->dialects);
+ if (PyModule_AddObject(module, "_dialects", get_csv_state(module)->dialects))
return NULL;
/* Add quote styles into dictionary */
return NULL;
/* Add the CSV exception object to the module. */
- _csvstate(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
- if (_csvstate(module)->error_obj == NULL)
+ get_csv_state(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
+ if (get_csv_state(module)->error_obj == NULL)
return NULL;
- Py_INCREF(_csvstate(module)->error_obj);
- PyModule_AddObject(module, "Error", _csvstate(module)->error_obj);
+ Py_INCREF(get_csv_state(module)->error_obj);
+ PyModule_AddObject(module, "Error", get_csv_state(module)->error_obj);
return module;
}
PyObject *PyCursesPanel_Type;
} _curses_panelstate;
-#define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o))
+static inline _curses_panelstate*
+get_curses_panelstate(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_curses_panelstate *)state;
+}
static int
_curses_panel_clear(PyObject *m)
{
- Py_CLEAR(_curses_panelstate(m)->PyCursesError);
+ Py_CLEAR(get_curses_panelstate(m)->PyCursesError);
return 0;
}
static int
_curses_panel_traverse(PyObject *m, visitproc visit, void *arg)
{
- Py_VISIT(_curses_panelstate(m)->PyCursesError);
+ Py_VISIT(get_curses_panelstate(m)->PyCursesError);
return 0;
}
if (v == NULL)
goto fail;
((PyTypeObject *)v)->tp_new = NULL;
- _curses_panelstate(m)->PyCursesPanel_Type = v;
+ get_curses_panelstate(m)->PyCursesPanel_Type = v;
import_curses();
if (PyErr_Occurred())
goto fail;
/* For exception _curses_panel.error */
- _curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
- PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError);
+ get_curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);
+ PyDict_SetItemString(d, "error", get_curses_panelstate(m)->PyCursesError);
/* Make the version available */
v = PyUnicode_FromString(PyCursesVersion);
PyDict_SetItemString(d, "__version__", v);
Py_DECREF(v);
- Py_INCREF(_curses_panelstate(m)->PyCursesPanel_Type);
- PyModule_AddObject(m, "panel", (PyObject *)_curses_panelstate(m)->PyCursesPanel_Type);
+ Py_INCREF(get_curses_panelstate(m)->PyCursesPanel_Type);
+ PyModule_AddObject(m, "panel",
+ (PyObject *)get_curses_panelstate(m)->PyCursesPanel_Type);
return m;
fail:
Py_XDECREF(m);
/* Given a module object (assumed to be _elementtree), get its per-module
* state.
*/
-#define ET_STATE(mod) ((elementtreestate *) PyModule_GetState(mod))
+static inline elementtreestate*
+get_elementtree_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (elementtreestate *)state;
+}
/* Find the module instance imported in the currently running sub-interpreter
* and get its state.
static int
elementtree_clear(PyObject *m)
{
- elementtreestate *st = ET_STATE(m);
+ elementtreestate *st = get_elementtree_state(m);
Py_CLEAR(st->parseerror_obj);
Py_CLEAR(st->deepcopy_obj);
Py_CLEAR(st->elementpath_obj);
static int
elementtree_traverse(PyObject *m, visitproc visit, void *arg)
{
- elementtreestate *st = ET_STATE(m);
+ elementtreestate *st = get_elementtree_state(m);
Py_VISIT(st->parseerror_obj);
Py_VISIT(st->deepcopy_obj);
Py_VISIT(st->elementpath_obj);
m = PyModule_Create(&elementtreemodule);
if (!m)
return NULL;
- st = ET_STATE(m);
+ st = get_elementtree_state(m);
if (!(temp = PyImport_ImportModule("copy")))
return NULL;
PyTypeObject *EVPtype;
} _hashlibstate;
-#define _hashlibstate(o) ((_hashlibstate *)PyModule_GetState(o))
+static inline _hashlibstate*
+get_hashlib_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_hashlibstate *)state;
+}
+
#define _hashlibstate_global ((_hashlibstate *)PyModule_GetState(PyState_FindModule(&_hashlibmodule)))
static int
hashlib_traverse(PyObject *m, visitproc visit, void *arg)
{
- _hashlibstate *state = _hashlibstate(m);
+ _hashlibstate *state = get_hashlib_state(m);
Py_VISIT(state->EVPtype);
return 0;
}
static int
hashlib_clear(PyObject *m)
{
- _hashlibstate *state = _hashlibstate(m);
+ _hashlibstate *state = get_hashlib_state(m);
Py_CLEAR(state->EVPtype);
return 0;
}
PyTypeObject *EVPtype = (PyTypeObject *)PyType_FromSpec(&EVPtype_spec);
if (EVPtype == NULL)
return NULL;
- _hashlibstate(m)->EVPtype = EVPtype;
+ get_hashlib_state(m)->EVPtype = EVPtype;
openssl_md_meth_names = generate_hash_name_list();
if (openssl_md_meth_names == NULL) {
return NULL;
}
- Py_INCREF((PyObject *)_hashlibstate(m)->EVPtype);
- PyModule_AddObject(m, "HASH", (PyObject *)_hashlibstate(m)->EVPtype);
+ Py_INCREF((PyObject *)get_hashlib_state(m)->EVPtype);
+ PyModule_AddObject(m, "HASH", (PyObject *)get_hashlib_state(m)->EVPtype);
PyState_AddModule(m, &_hashlibmodule);
return m;
return result;
}
+static inline _PyIO_State*
+get_io_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_PyIO_State *)state;
+}
_PyIO_State *
_PyIO_get_module_state(void)
{
PyObject *mod = PyState_FindModule(&_PyIO_Module);
_PyIO_State *state;
- if (mod == NULL || (state = IO_MOD_STATE(mod)) == NULL) {
+ if (mod == NULL || (state = get_io_state(mod)) == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"could not find io module state "
"(interpreter shutdown?)");
static int
iomodule_traverse(PyObject *mod, visitproc visit, void *arg) {
- _PyIO_State *state = IO_MOD_STATE(mod);
+ _PyIO_State *state = get_io_state(mod);
if (!state->initialized)
return 0;
if (state->locale_module != NULL) {
static int
iomodule_clear(PyObject *mod) {
- _PyIO_State *state = IO_MOD_STATE(mod);
+ _PyIO_State *state = get_io_state(mod);
if (!state->initialized)
return 0;
if (state->locale_module != NULL)
_PyIO_State *state = NULL;
if (m == NULL)
return NULL;
- state = IO_MOD_STATE(m);
+ state = get_io_state(m);
state->initialized = 0;
#define ADD_TYPE(type, name) \
static struct PyModuleDef _posixsubprocessmodule;
-#define _posixsubprocessstate(o) ((_posixsubprocessstate *)PyModule_GetState(o))
-#define _posixsubprocessstate_global _posixsubprocessstate(PyState_FindModule(&_posixsubprocessmodule))
+static inline _posixsubprocessstate*
+get_posixsubprocess_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_posixsubprocessstate *)state;
+}
+
+#define _posixsubprocessstate_global get_posixsubprocess_state(PyState_FindModule(&_posixsubprocessmodule))
/* If gc was disabled, call gc.enable(). Return 0 on success. */
static int
static int _posixsubprocess_traverse(PyObject *m, visitproc visit, void *arg) {
- Py_VISIT(_posixsubprocessstate(m)->disable);
- Py_VISIT(_posixsubprocessstate(m)->enable);
- Py_VISIT(_posixsubprocessstate(m)->isenabled);
+ Py_VISIT(get_posixsubprocess_state(m)->disable);
+ Py_VISIT(get_posixsubprocess_state(m)->enable);
+ Py_VISIT(get_posixsubprocess_state(m)->isenabled);
return 0;
}
static int _posixsubprocess_clear(PyObject *m) {
- Py_CLEAR(_posixsubprocessstate(m)->disable);
- Py_CLEAR(_posixsubprocessstate(m)->enable);
- Py_CLEAR(_posixsubprocessstate(m)->isenabled);
+ Py_CLEAR(get_posixsubprocess_state(m)->disable);
+ Py_CLEAR(get_posixsubprocess_state(m)->enable);
+ Py_CLEAR(get_posixsubprocess_state(m)->isenabled);
return 0;
}
return NULL;
}
- _posixsubprocessstate(m)->disable = PyUnicode_InternFromString("disable");
- _posixsubprocessstate(m)->enable = PyUnicode_InternFromString("enable");
- _posixsubprocessstate(m)->isenabled = PyUnicode_InternFromString("isenabled");
+ get_posixsubprocess_state(m)->disable = PyUnicode_InternFromString("disable");
+ get_posixsubprocess_state(m)->enable = PyUnicode_InternFromString("enable");
+ get_posixsubprocess_state(m)->isenabled = PyUnicode_InternFromString("isenabled");
PyState_AddModule(m, &_posixsubprocessmodule);
return m;
PyObject *Long___abs__;
} _randomstate;
-#define _randomstate(o) ((_randomstate *)PyModule_GetState(o))
+static inline _randomstate*
+get_random_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_randomstate *)state;
+}
static struct PyModuleDef _randommodule;
-#define _randomstate_global _randomstate(PyState_FindModule(&_randommodule))
+#define _randomstate_global get_random_state(PyState_FindModule(&_randommodule))
typedef struct {
PyObject_HEAD
static int
_random_traverse(PyObject *module, visitproc visit, void *arg)
{
- Py_VISIT(_randomstate(module)->Random_Type);
+ Py_VISIT(get_random_state(module)->Random_Type);
return 0;
}
static int
_random_clear(PyObject *module)
{
- Py_CLEAR(_randomstate(module)->Random_Type);
- Py_CLEAR(_randomstate(module)->Long___abs__);
+ Py_CLEAR(get_random_state(module)->Random_Type);
+ Py_CLEAR(get_random_state(module)->Long___abs__);
return 0;
}
Py_DECREF(Random_Type);
return NULL;
}
- _randomstate(m)->Random_Type = Random_Type;
+ get_random_state(m)->Random_Type = Random_Type;
Py_INCREF(Random_Type);
PyModule_AddObject(m, "Random", Random_Type);
Py_DECREF(longtype);
Py_DECREF(longval);
- _randomstate(m)->Long___abs__ = abs;
+ get_random_state(m)->Long___abs__ = abs;
return m;
PyObject *StructError;
} _structmodulestate;
-#define _structmodulestate(o) ((_structmodulestate *)PyModule_GetState(o))
+static inline _structmodulestate*
+get_struct_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_structmodulestate *)state;
+}
static struct PyModuleDef _structmodule;
-#define _structmodulestate_global _structmodulestate(PyState_FindModule(&_structmodule))
+#define _structmodulestate_global get_struct_state(PyState_FindModule(&_structmodule))
/* The translation function for each format character is table driven */
typedef struct _formatdef {
static int
_structmodule_traverse(PyObject *module, visitproc visit, void *arg)
{
- Py_VISIT(_structmodulestate(module)->PyStructType);
- Py_VISIT(_structmodulestate(module)->unpackiter_type);
- Py_VISIT(_structmodulestate(module)->StructError);
+ _structmodulestate *state = (_structmodulestate *)PyModule_GetState(module);
+ if (state) {
+ Py_VISIT(state->PyStructType);
+ Py_VISIT(state->unpackiter_type);
+ Py_VISIT(state->StructError);
+ }
return 0;
}
static int
_structmodule_clear(PyObject *module)
{
- Py_CLEAR(_structmodulestate(module)->PyStructType);
- Py_CLEAR(_structmodulestate(module)->unpackiter_type);
- Py_CLEAR(_structmodulestate(module)->StructError);
+ _structmodulestate *state = (_structmodulestate *)PyModule_GetState(module);
+ if (state) {
+ Py_CLEAR(state->PyStructType);
+ Py_CLEAR(state->unpackiter_type);
+ Py_CLEAR(state->StructError);
+ }
return 0;
}
}
Py_INCREF(PyStructType);
PyModule_AddObject(m, "Struct", PyStructType);
- _structmodulestate(m)->PyStructType = PyStructType;
+ get_struct_state(m)->PyStructType = PyStructType;
PyObject *unpackiter_type = PyType_FromSpec(&unpackiter_type_spec);
if (unpackiter_type == NULL) {
return NULL;
}
- _structmodulestate(m)->unpackiter_type = unpackiter_type;
+ get_struct_state(m)->unpackiter_type = unpackiter_type;
/* Check endian and swap in faster functions */
{
return NULL;
Py_INCREF(StructError);
PyModule_AddObject(m, "error", StructError);
- _structmodulestate(m)->StructError = StructError;
+ get_struct_state(m)->StructError = StructError;
return m;
}
int callback_len;
} atexitmodule_state;
-#define GET_ATEXIT_STATE(mod) ((atexitmodule_state*)PyModule_GetState(mod))
+static inline atexitmodule_state*
+get_atexit_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (atexitmodule_state *)state;
+}
static void
if (module == NULL)
return;
- modstate = GET_ATEXIT_STATE(module);
+ modstate = get_atexit_state(module);
if (modstate->ncallbacks == 0)
return;
atexit_callback *new_callback;
PyObject *func = NULL;
- modstate = GET_ATEXIT_STATE(self);
+ modstate = get_atexit_state(self);
if (modstate->ncallbacks >= modstate->callback_len) {
atexit_callback **r;
static PyObject *
atexit_clear(PyObject *self, PyObject *unused)
{
- atexit_cleanup(GET_ATEXIT_STATE(self));
+ atexit_cleanup(get_atexit_state(self));
Py_RETURN_NONE;
}
{
atexitmodule_state *modstate;
- modstate = GET_ATEXIT_STATE(self);
+ modstate = get_atexit_state(self);
return PyLong_FromSsize_t(modstate->ncallbacks);
}
int i;
atexitmodule_state *modstate;
- modstate = GET_ATEXIT_STATE(self);
+ modstate = (atexitmodule_state *)PyModule_GetState(self);
if (modstate != NULL) {
for (i = 0; i < modstate->ncallbacks; i++) {
atexit_callback *cb = modstate->atexit_callbacks[i];
atexit_m_clear(PyObject *self)
{
atexitmodule_state *modstate;
- modstate = GET_ATEXIT_STATE(self);
+ modstate = (atexitmodule_state *)PyModule_GetState(self);
if (modstate != NULL) {
atexit_cleanup(modstate);
}
atexit_free(PyObject *m)
{
atexitmodule_state *modstate;
- modstate = GET_ATEXIT_STATE(m);
+ modstate = (atexitmodule_state *)PyModule_GetState(m);
if (modstate != NULL) {
atexit_cleanup(modstate);
PyMem_Free(modstate->atexit_callbacks);
atexit_callback *cb;
int i, eq;
- modstate = GET_ATEXIT_STATE(self);
+ modstate = get_atexit_state(self);
for (i = 0; i < modstate->ncallbacks; i++)
{
atexit_exec(PyObject *m) {
atexitmodule_state *modstate;
- modstate = GET_ATEXIT_STATE(m);
+ modstate = get_atexit_state(m);
modstate->callback_len = 32;
modstate->ncallbacks = 0;
modstate->atexit_callbacks = PyMem_New(atexit_callback*,
typedef struct {
PyTypeObject *StructGrpType;
} grpmodulestate;
-#define modulestate(o) ((grpmodulestate *)PyModule_GetState(o))
-#define modulestate_global modulestate(PyState_FindModule(&grpmodule))
+
+static inline grpmodulestate*
+get_grp_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (grpmodulestate *)state;
+}
+
+#define modulestate_global get_grp_state(PyState_FindModule(&grpmodule))
static struct PyModuleDef grpmodule;
complete membership information.)");
static int grpmodule_traverse(PyObject *m, visitproc visit, void *arg) {
- Py_VISIT(modulestate(m)->StructGrpType);
+ Py_VISIT(get_grp_state(m)->StructGrpType);
return 0;
}
static int grpmodule_clear(PyObject *m) {
- Py_CLEAR(modulestate(m)->StructGrpType);
+ Py_CLEAR(get_grp_state(m)->StructGrpType);
return 0;
}
static struct PyModuleDef posixmodule;
-#define _posixstate(o) ((_posixstate *)PyModule_GetState(o))
+static inline _posixstate*
+get_posix_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_posixstate *)state;
+}
+
#define _posixstate_global ((_posixstate *)PyModule_GetState(PyState_FindModule(&posixmodule)))
/*
static int
_posix_clear(PyObject *module)
{
- Py_CLEAR(_posixstate(module)->billion);
- Py_CLEAR(_posixstate(module)->DirEntryType);
- Py_CLEAR(_posixstate(module)->ScandirIteratorType);
+ Py_CLEAR(get_posix_state(module)->billion);
+ Py_CLEAR(get_posix_state(module)->DirEntryType);
+ Py_CLEAR(get_posix_state(module)->ScandirIteratorType);
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)
- Py_CLEAR(_posixstate(module)->SchedParamType);
+ Py_CLEAR(get_posix_state(module)->SchedParamType);
#endif
- Py_CLEAR(_posixstate(module)->StatResultType);
- Py_CLEAR(_posixstate(module)->StatVFSResultType);
- Py_CLEAR(_posixstate(module)->TerminalSizeType);
- Py_CLEAR(_posixstate(module)->TimesResultType);
- Py_CLEAR(_posixstate(module)->UnameResultType);
+ Py_CLEAR(get_posix_state(module)->StatResultType);
+ Py_CLEAR(get_posix_state(module)->StatVFSResultType);
+ Py_CLEAR(get_posix_state(module)->TerminalSizeType);
+ Py_CLEAR(get_posix_state(module)->TimesResultType);
+ Py_CLEAR(get_posix_state(module)->UnameResultType);
#if defined(HAVE_WAITID) && !defined(__APPLE__)
- Py_CLEAR(_posixstate(module)->WaitidResultType);
+ Py_CLEAR(get_posix_state(module)->WaitidResultType);
#endif
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
- Py_CLEAR(_posixstate(module)->struct_rusage);
+ Py_CLEAR(get_posix_state(module)->struct_rusage);
#endif
- Py_CLEAR(_posixstate(module)->st_mode);
+ Py_CLEAR(get_posix_state(module)->st_mode);
return 0;
}
static int
_posix_traverse(PyObject *module, visitproc visit, void *arg)
{
- Py_VISIT(_posixstate(module)->billion);
- Py_VISIT(_posixstate(module)->DirEntryType);
- Py_VISIT(_posixstate(module)->ScandirIteratorType);
+ Py_VISIT(get_posix_state(module)->billion);
+ Py_VISIT(get_posix_state(module)->DirEntryType);
+ Py_VISIT(get_posix_state(module)->ScandirIteratorType);
#if defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)
- Py_VISIT(_posixstate(module)->SchedParamType);
+ Py_VISIT(get_posix_state(module)->SchedParamType);
#endif
- Py_VISIT(_posixstate(module)->StatResultType);
- Py_VISIT(_posixstate(module)->StatVFSResultType);
- Py_VISIT(_posixstate(module)->TerminalSizeType);
- Py_VISIT(_posixstate(module)->TimesResultType);
- Py_VISIT(_posixstate(module)->UnameResultType);
+ Py_VISIT(get_posix_state(module)->StatResultType);
+ Py_VISIT(get_posix_state(module)->StatVFSResultType);
+ Py_VISIT(get_posix_state(module)->TerminalSizeType);
+ Py_VISIT(get_posix_state(module)->TimesResultType);
+ Py_VISIT(get_posix_state(module)->UnameResultType);
#if defined(HAVE_WAITID) && !defined(__APPLE__)
- Py_VISIT(_posixstate(module)->WaitidResultType);
+ Py_VISIT(get_posix_state(module)->WaitidResultType);
#endif
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
- Py_VISIT(_posixstate(module)->struct_rusage);
+ Py_VISIT(get_posix_state(module)->struct_rusage);
#endif
- Py_VISIT(_posixstate(module)->st_mode);
+ Py_VISIT(get_posix_state(module)->st_mode);
return 0;
}
if (res < 0)
return posix_error();
- PyObject *UnameResultType = _posixstate(module)->UnameResultType;
+ PyObject *UnameResultType = get_posix_state(module)->UnameResultType;
value = PyStructSequence_New((PyTypeObject *)UnameResultType);
if (value == NULL)
return NULL;
if (si.si_pid == 0)
Py_RETURN_NONE;
- PyObject *WaitidResultType = _posixstate(module)->WaitidResultType;
+ PyObject *WaitidResultType = get_posix_state(module)->WaitidResultType;
result = PyStructSequence_New((PyTypeObject *)WaitidResultType);
if (!result)
return NULL;
}
#endif /* TERMSIZE_USE_CONIO */
- PyObject *TerminalSizeType = _posixstate(self)->TerminalSizeType;
+ PyObject *TerminalSizeType = get_posix_state(self)->TerminalSizeType;
termsize = PyStructSequence_New((PyTypeObject *)TerminalSizeType);
if (termsize == NULL)
return NULL;
return NULL;
}
- PyObject *ScandirIteratorType = _posixstate(module)->ScandirIteratorType;
+ PyObject *ScandirIteratorType = get_posix_state(module)->ScandirIteratorType;
iterator = PyObject_New(ScandirIterator, (PyTypeObject *)ScandirIteratorType);
if (!iterator)
return NULL;
}
Py_INCREF(WaitidResultType);
PyModule_AddObject(m, "waitid_result", WaitidResultType);
- _posixstate(m)->WaitidResultType = WaitidResultType;
+ get_posix_state(m)->WaitidResultType = WaitidResultType;
#endif
stat_result_desc.name = "os.stat_result"; /* see issue #19209 */
}
Py_INCREF(StatResultType);
PyModule_AddObject(m, "stat_result", StatResultType);
- _posixstate(m)->StatResultType = StatResultType;
+ get_posix_state(m)->StatResultType = StatResultType;
structseq_new = ((PyTypeObject *)StatResultType)->tp_new;
((PyTypeObject *)StatResultType)->tp_new = statresult_new;
}
Py_INCREF(StatVFSResultType);
PyModule_AddObject(m, "statvfs_result", StatVFSResultType);
- _posixstate(m)->StatVFSResultType = StatVFSResultType;
+ get_posix_state(m)->StatVFSResultType = StatVFSResultType;
#ifdef NEED_TICKS_PER_SECOND
# if defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
ticks_per_second = sysconf(_SC_CLK_TCK);
}
Py_INCREF(SchedParamType);
PyModule_AddObject(m, "sched_param", SchedParamType);
- _posixstate(m)->SchedParamType = SchedParamType;
+ get_posix_state(m)->SchedParamType = SchedParamType;
((PyTypeObject *)SchedParamType)->tp_new = os_sched_param;
#endif
}
Py_INCREF(TerminalSizeType);
PyModule_AddObject(m, "terminal_size", TerminalSizeType);
- _posixstate(m)->TerminalSizeType = TerminalSizeType;
+ get_posix_state(m)->TerminalSizeType = TerminalSizeType;
/* initialize scandir types */
PyObject *ScandirIteratorType = PyType_FromSpec(&ScandirIteratorType_spec);
if (ScandirIteratorType == NULL) {
return NULL;
}
- _posixstate(m)->ScandirIteratorType = ScandirIteratorType;
+ get_posix_state(m)->ScandirIteratorType = ScandirIteratorType;
PyObject *DirEntryType = PyType_FromSpec(&DirEntryType_spec);
if (DirEntryType == NULL) {
}
Py_INCREF(DirEntryType);
PyModule_AddObject(m, "DirEntry", DirEntryType);
- _posixstate(m)->DirEntryType = DirEntryType;
+ get_posix_state(m)->DirEntryType = DirEntryType;
times_result_desc.name = MODNAME ".times_result";
PyObject *TimesResultType = (PyObject *)PyStructSequence_NewType(×_result_desc);
}
Py_INCREF(TimesResultType);
PyModule_AddObject(m, "times_result", TimesResultType);
- _posixstate(m)->TimesResultType = TimesResultType;
+ get_posix_state(m)->TimesResultType = TimesResultType;
PyTypeObject *UnameResultType = PyStructSequence_NewType(&uname_result_desc);
if (UnameResultType == NULL) {
}
Py_INCREF(UnameResultType);
PyModule_AddObject(m, "uname_result", (PyObject *)UnameResultType);
- _posixstate(m)->UnameResultType = (PyObject *)UnameResultType;
+ get_posix_state(m)->UnameResultType = (PyObject *)UnameResultType;
#ifdef __APPLE__
/*
#endif /* __APPLE__ */
- if ((_posixstate(m)->billion = PyLong_FromLong(1000000000)) == NULL)
+ if ((get_posix_state(m)->billion = PyLong_FromLong(1000000000)) == NULL)
return NULL;
#if defined(HAVE_WAIT3) || defined(HAVE_WAIT4)
- _posixstate(m)->struct_rusage = PyUnicode_InternFromString("struct_rusage");
- if (_posixstate(m)->struct_rusage == NULL)
+ get_posix_state(m)->struct_rusage = PyUnicode_InternFromString("struct_rusage");
+ if (get_posix_state(m)->struct_rusage == NULL)
return NULL;
#endif
- _posixstate(m)->st_mode = PyUnicode_InternFromString("st_mode");
- if (_posixstate(m)->st_mode == NULL)
+ get_posix_state(m)->st_mode = PyUnicode_InternFromString("st_mode");
+ if (get_posix_state(m)->st_mode == NULL)
return NULL;
/* suppress "function not used" warnings */
typedef struct {
PyTypeObject *StructPwdType;
} pwdmodulestate;
-#define modulestate(o) ((pwdmodulestate *)PyModule_GetState(o))
-#define modulestate_global modulestate(PyState_FindModule(&pwdmodule))
+
+static inline pwdmodulestate*
+get_pwd_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (pwdmodulestate *)state;
+}
+
+#define modulestate_global get_pwd_state(PyState_FindModule(&pwdmodule))
static struct PyModuleDef pwdmodule;
};
static int pwdmodule_traverse(PyObject *m, visitproc visit, void *arg) {
- Py_VISIT(modulestate(m)->StructPwdType);
+ Py_VISIT(get_pwd_state(m)->StructPwdType);
return 0;
}
static int pwdmodule_clear(PyObject *m) {
- Py_CLEAR(modulestate(m)->StructPwdType);
+ Py_CLEAR(get_pwd_state(m)->StructPwdType);
return 0;
}
static void pwdmodule_free(void *m) {
PyObject *endidx;
} readlinestate;
-
-#define readline_state(o) ((readlinestate *)PyModule_GetState(o))
+static inline readlinestate*
+get_readline_state(PyModule *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (readlinestate *)state;
+}
static int
readline_clear(PyObject *m)
{
- readlinestate *state = readline_state(m);
+ readlinestate *state = get_readline_state(m);
Py_CLEAR(state->completion_display_matches_hook);
Py_CLEAR(state->startup_hook);
Py_CLEAR(state->pre_input_hook);
static int
readline_traverse(PyObject *m, visitproc visit, void *arg)
{
- readlinestate *state = readline_state(m);
+ readlinestate *state = get_readline_state(m);
Py_VISIT(state->completion_display_matches_hook);
Py_VISIT(state->startup_hook);
Py_VISIT(state->pre_input_hook);
static struct PyModuleDef selectmodule;
-#define _selectstate(o) ((_selectstate *)PyModule_GetState(o))
-#define _selectstate_global _selectstate(PyState_FindModule(&selectmodule))
+static inline _selectstate*
+get_select_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_selectstate *)state;
+}
+
+#define _selectstate_global get_select_state(PyState_FindModule(&selectmodule))
/*[clinic input]
module select
static int
_select_traverse(PyObject *module, visitproc visit, void *arg)
{
- Py_VISIT(_selectstate(module)->close);
- Py_VISIT(_selectstate(module)->poll_Type);
- Py_VISIT(_selectstate(module)->devpoll_Type);
- Py_VISIT(_selectstate(module)->pyEpoll_Type);
- Py_VISIT(_selectstate(module)->kqueue_event_Type);
- Py_VISIT(_selectstate(module)->kqueue_queue_Type);
+ Py_VISIT(get_select_state(module)->close);
+ Py_VISIT(get_select_state(module)->poll_Type);
+ Py_VISIT(get_select_state(module)->devpoll_Type);
+ Py_VISIT(get_select_state(module)->pyEpoll_Type);
+ Py_VISIT(get_select_state(module)->kqueue_event_Type);
+ Py_VISIT(get_select_state(module)->kqueue_queue_Type);
return 0;
}
static int
_select_clear(PyObject *module)
{
- Py_CLEAR(_selectstate(module)->close);
- Py_CLEAR(_selectstate(module)->poll_Type);
- Py_CLEAR(_selectstate(module)->devpoll_Type);
- Py_CLEAR(_selectstate(module)->pyEpoll_Type);
- Py_CLEAR(_selectstate(module)->kqueue_event_Type);
- Py_CLEAR(_selectstate(module)->kqueue_queue_Type);
+ Py_CLEAR(get_select_state(module)->close);
+ Py_CLEAR(get_select_state(module)->poll_Type);
+ Py_CLEAR(get_select_state(module)->devpoll_Type);
+ Py_CLEAR(get_select_state(module)->pyEpoll_Type);
+ Py_CLEAR(get_select_state(module)->kqueue_event_Type);
+ Py_CLEAR(get_select_state(module)->kqueue_queue_Type);
return 0;
}
if (m == NULL)
return NULL;
- _selectstate(m)->close = PyUnicode_InternFromString("close");
+ get_select_state(m)->close = PyUnicode_InternFromString("close");
Py_INCREF(PyExc_OSError);
PyModule_AddObject(m, "error", PyExc_OSError);
PyObject *poll_Type = PyType_FromSpec(&poll_Type_spec);
if (poll_Type == NULL)
return NULL;
- _selectstate(m)->poll_Type = (PyTypeObject *)poll_Type;
+ get_select_state(m)->poll_Type = (PyTypeObject *)poll_Type;
Py_INCREF(poll_Type);
PyModule_AddIntMacro(m, POLLIN);
PyObject *devpoll_Type = PyType_FromSpec(&devpoll_Type_spec);
if (devpoll_Type == NULL)
return NULL;
- _selectstate(m)->devpoll_Type = (PyTypeObject *)devpoll_Type;
+ get_select_state(m)->devpoll_Type = (PyTypeObject *)devpoll_Type;
Py_INCREF(devpoll_Type);
#endif
PyObject *pyEpoll_Type = PyType_FromSpec(&pyEpoll_Type_spec);
if (pyEpoll_Type == NULL)
return NULL;
- _selectstate(m)->pyEpoll_Type = (PyTypeObject *)pyEpoll_Type;
+ get_select_state(m)->pyEpoll_Type = (PyTypeObject *)pyEpoll_Type;
Py_INCREF(pyEpoll_Type);
- PyModule_AddObject(m, "epoll", (PyObject *)_selectstate(m)->pyEpoll_Type);
+ PyModule_AddObject(m, "epoll", (PyObject *)get_select_state(m)->pyEpoll_Type);
PyModule_AddIntMacro(m, EPOLLIN);
PyModule_AddIntMacro(m, EPOLLOUT);
PyObject *kqueue_event_Type = PyType_FromSpec(&kqueue_event_Type_spec);
if (kqueue_event_Type == NULL)
return NULL;
- _selectstate(m)->kqueue_event_Type = (PyTypeObject *)kqueue_event_Type;
- Py_INCREF(_selectstate(m)->kqueue_event_Type);
+ get_select_state(m)->kqueue_event_Type = (PyTypeObject *)kqueue_event_Type;
+ Py_INCREF(get_select_state(m)->kqueue_event_Type);
PyModule_AddObject(m, "kevent", kqueue_event_Type);
PyObject *kqueue_queue_Type = PyType_FromSpec(&kqueue_queue_Type_spec);
if (kqueue_queue_Type == NULL)
return NULL;
- _selectstate(m)->kqueue_queue_Type = (PyTypeObject *)kqueue_queue_Type;
- Py_INCREF(_selectstate(m)->kqueue_queue_Type);
+ get_select_state(m)->kqueue_queue_Type = (PyTypeObject *)kqueue_queue_Type;
+ Py_INCREF(get_select_state(m)->kqueue_queue_Type);
PyModule_AddObject(m, "kqueue", kqueue_queue_Type);
/* event filters */
typedef struct {
PyObject *TermiosError;
} termiosmodulestate;
-#define modulestate(o) ((termiosmodulestate *)PyModule_GetState(o))
-#define modulestate_global modulestate(PyState_FindModule(&termiosmodule))
+
+static inline termiosmodulestate*
+get_termios_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (termiosmodulestate *)state;
+}
+
+#define modulestate_global get_termios_state(PyState_FindModule(&termiosmodule))
static int fdconv(PyObject* obj, void* p)
{
};
static int termiosmodule_traverse(PyObject *m, visitproc visit, void *arg) {
- Py_VISIT(modulestate(m)->TermiosError);
+ Py_VISIT(get_termios_state(m)->TermiosError);
return 0;
}
static int termiosmodule_clear(PyObject *m) {
- Py_CLEAR(modulestate(m)->TermiosError);
+ Py_CLEAR(get_termios_state(m)->TermiosError);
return 0;
}
return NULL;
}
- termiosmodulestate *state = PyModule_GetState(m);
+ termiosmodulestate *state = get_termios_state(m);
state->TermiosError = PyErr_NewException("termios.error", NULL, NULL);
if (state->TermiosError == NULL) {
return NULL;
PyObject *ZlibError;
} _zlibstate;
-#define _zlibstate(o) ((_zlibstate *)PyModule_GetState(o))
+static inline _zlibstate*
+get_zlib_state(PyObject *module)
+{
+ void *state = PyModule_GetState(module);
+ assert(state != NULL);
+ return (_zlibstate *)state;
+}
+
#define _zlibstate_global ((_zlibstate *)PyModule_GetState(PyState_FindModule(&zlibmodule)))
typedef struct
static int
zlib_clear(PyObject *m)
{
- _zlibstate *state = _zlibstate(m);
+ _zlibstate *state = get_zlib_state(m);
Py_CLEAR(state->Comptype);
Py_CLEAR(state->Decomptype);
Py_CLEAR(state->ZlibError);
static int
zlib_traverse(PyObject *m, visitproc visit, void *arg)
{
- _zlibstate *state = _zlibstate(m);
+ _zlibstate *state = get_zlib_state(m);
Py_VISIT(state->Comptype);
Py_VISIT(state->Decomptype);
Py_VISIT(state->ZlibError);
PyTypeObject *Comptype = (PyTypeObject *)PyType_FromSpec(&Comptype_spec);
if (Comptype == NULL)
return NULL;
- _zlibstate(m)->Comptype = Comptype;
+ get_zlib_state(m)->Comptype = Comptype;
PyTypeObject *Decomptype = (PyTypeObject *)PyType_FromSpec(&Decomptype_spec);
if (Decomptype == NULL)
return NULL;
- _zlibstate(m)->Decomptype = Decomptype;
+ get_zlib_state(m)->Decomptype = Decomptype;
PyObject *ZlibError = PyErr_NewException("zlib.error", NULL, NULL);
if (ZlibError != NULL) {
Py_INCREF(ZlibError);
PyModule_AddObject(m, "error", ZlibError);
- _zlibstate(m)->ZlibError = ZlibError;
+ get_zlib_state(m)->ZlibError = ZlibError;
}
PyModule_AddIntMacro(m, MAX_WBITS);
PyModule_AddIntMacro(m, DEFLATED);