Visitar URL original
bpo-1635741: port winapi to multi-stage init by koubaa · Pull Request #21371 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update based on review
  • Loading branch information
koubaa committed Aug 13, 2020
commit e0e1b30cf0812876d7ebba93de3468fe3b99c6b5
21 changes: 8 additions & 13 deletions Modules/_winapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1910,21 +1910,15 @@ static PyMethodDef winapi_functions[] = {
{NULL, NULL}
};

static int
SetWinAPIConstant(PyObject* d, const char* fmt, const char* constantString, int constant) {
PyObject *value = Py_BuildValue(fmt, constant);
if (PyDict_SetItemString(d, constantString, value) < 0) {
Py_DECREF(value);
return -1;
}

Py_DECREF(value);
return 0;
#define WINAPI_CONSTANT(fmt, con) { \
PyObject *value = Py_BuildValue(fmt, con); \
if (PyDict_SetItemString(d, #con, value) < 0) { \
Py_DECREF(value); \
return -1; \
} \
Py_DECREF(value); \
}

#define WINAPI_CONSTANT(fmt, con) \
if (SetWinAPIConstant(d, fmt, #con, con) < 0) return -1

static int winapi_exec(PyObject *m)
{
WinApiState *st = winapi_get_state(m);
Expand All @@ -1934,6 +1928,7 @@ static int winapi_exec(PyObject *m)
return -1;
}

Py_INCREF(st->overlapped_type);
if (PyModule_AddObject(m, "Overlapped", (PyObject *)st->overlapped_type) < 0) {
Py_DECREF(st->overlapped_type);
return -1;
Expand Down