Skip to content
Prev Previous commit
Next Next commit
apply victor's comment
  • Loading branch information
shihai1991 committed Jan 25, 2021
commit 9f73df5133f6542700fd5e96d1cf79a01a97f4a3
16 changes: 8 additions & 8 deletions Include/py_curses.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ typedef struct {
} PyCursesWindowObject;

typedef struct {
PyTypeObject *Window_Type;
int (*SetupTermCalled)(void);
int (*Initialised)(void);
int (*InitialisedColor)(void);
PyTypeObject *window_type;
int (*setup_term_called)(void);
int (*initialized)(void);
int (*initialized_color)(void);
} PyCurses_CAPI;

#define PyCursesWindow_Check(v) Py_IS_TYPE(v, &PyCursesWindow_Type)
Expand All @@ -82,10 +82,10 @@ typedef struct {

static PyCurses_CAPI *PyCurses_API;

#define PyCursesWindow_Type (*PyCurses_API->Window_Type)
#define PyCursesSetupTermCalled {if (!PyCurses_API->SetupTermCalled()) return NULL;}
#define PyCursesInitialised {if (!PyCurses_API->Initialised()) return NULL;}
#define PyCursesInitialisedColor {if (!PyCurses_API->InitialisedColor()) return NULL;}
#define PyCursesWindow_Type (*PyCurses_API->window_type)
#define PyCursesSetupTermCalled {if (!PyCurses_API->setup_term_called()) return NULL;}
#define PyCursesInitialised {if (!PyCurses_API->initialized()) return NULL;}
#define PyCursesInitialisedColor {if (!PyCurses_API->initialized_color()) return NULL;}

#define import_curses() \
PyCurses_API = PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
Expand Down
12 changes: 6 additions & 6 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -4729,7 +4729,7 @@ static void
curses_destructor(PyObject *op)
{
PyCurses_CAPI *ptr = PyCapsule_GetPointer(op, PyCurses_CAPSULE_NAME);
Py_DECREF(ptr->Window_Type);
Py_DECREF(ptr->window_type);
PyMem_Free(ptr);
}

Expand Down Expand Up @@ -4759,17 +4759,17 @@ PyInit__curses(void)
return NULL;
}
/* Initialize the C API struct pointer */
Comment thread
shihai1991 marked this conversation as resolved.
Outdated
PyCurses_API->Window_Type = (PyTypeObject *)Py_NewRef(
PyCurses_API->window_type = (PyTypeObject *)Py_NewRef(
&PyCursesWindow_Type);
PyCurses_API->SetupTermCalled = func_PyCursesSetupTermCalled;
PyCurses_API->Initialised = func_PyCursesInitialised;
PyCurses_API->InitialisedColor = func_PyCursesInitialisedColor;
PyCurses_API->setup_term_called = func_PyCursesSetupTermCalled;
PyCurses_API->initialized = func_PyCursesInitialised;
PyCurses_API->initialized_color = func_PyCursesInitialisedColor;

/* Add a capsule for the C API */
c_api_object = PyCapsule_New(PyCurses_API, PyCurses_CAPSULE_NAME,
curses_destructor);
if (c_api_object == NULL) {
Py_DECREF(PyCurses_API->Window_Type);
Py_DECREF(PyCurses_API->window_type);
PyMem_Free(PyCurses_API);
return NULL;
}
Expand Down