@@ -18,12 +18,11 @@ static char *PyCursesVersion = "2.1";
1818
1919typedef struct {
2020 PyObject * PyCursesError ;
21+ PyObject * PyCursesPanel_Type ;
2122} _curses_panelstate ;
2223
2324#define _curses_panelstate (o ) ((_curses_panelstate *)PyModule_GetState(o))
2425
25- /*static PyObject *PyCursesError;*/
26-
2726static int
2827_curses_panel_clear (PyObject * m )
2928{
@@ -84,9 +83,8 @@ typedef struct {
8483 PyCursesWindowObject * wo ; /* for reference counts */
8584} PyCursesPanelObject ;
8685
87- PyTypeObject PyCursesPanel_Type ;
88-
89- #define PyCursesPanel_Check (v ) (Py_TYPE(v) == &PyCursesPanel_Type)
86+ #define PyCursesPanel_Check (v ) \
87+ (Py_TYPE(v) == _curses_panelstate_global->PyCursesPanel_Type)
9088
9189/* Some helper functions. The problem is that there's always a window
9290 associated with a panel. To ensure that Python's GC doesn't pull
@@ -205,7 +203,8 @@ PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)
205203{
206204 PyCursesPanelObject * po ;
207205
208- po = PyObject_NEW (PyCursesPanelObject , & PyCursesPanel_Type );
206+ po = PyObject_NEW (PyCursesPanelObject ,
207+ (PyTypeObject * )(_curses_panelstate_global )-> PyCursesPanel_Type );
209208 if (po == NULL ) return NULL ;
210209 po -> pan = pan ;
211210 if (insert_lop (po ) < 0 ) {
@@ -364,36 +363,18 @@ static PyMethodDef PyCursesPanel_Methods[] = {
364363
365364/* -------------------------------------------------------*/
366365
367- PyTypeObject PyCursesPanel_Type = {
368- PyVarObject_HEAD_INIT (NULL , 0 )
369- "_curses_panel.curses panel" , /*tp_name*/
370- sizeof (PyCursesPanelObject ), /*tp_basicsize*/
371- 0 , /*tp_itemsize*/
372- /* methods */
373- (destructor )PyCursesPanel_Dealloc , /*tp_dealloc*/
374- 0 , /*tp_print*/
375- 0 , /*tp_getattr*/
376- 0 , /*tp_setattr*/
377- 0 , /*tp_reserved*/
378- 0 , /*tp_repr*/
379- 0 , /*tp_as_number*/
380- 0 , /*tp_as_sequence*/
381- 0 , /*tp_as_mapping*/
382- 0 , /*tp_hash*/
383- 0 , /*tp_call*/
384- 0 , /*tp_str*/
385- 0 , /*tp_getattro*/
386- 0 , /*tp_setattro*/
387- 0 , /*tp_as_buffer*/
388- Py_TPFLAGS_DEFAULT , /*tp_flags*/
389- 0 , /*tp_doc*/
390- 0 , /*tp_traverse*/
391- 0 , /*tp_clear*/
392- 0 , /*tp_richcompare*/
393- 0 , /*tp_weaklistoffset*/
394- 0 , /*tp_iter*/
395- 0 , /*tp_iternext*/
396- PyCursesPanel_Methods , /*tp_methods*/
366+ static PyType_Slot PyCursesPanel_Type_slots [] = {
367+ {Py_tp_dealloc , PyCursesPanel_Dealloc },
368+ {Py_tp_methods , PyCursesPanel_Methods },
369+ {0 , 0 },
370+ };
371+
372+ static PyType_Spec PyCursesPanel_Type_spec = {
373+ "_curses_panel.curses panel" ,
374+ sizeof (PyCursesPanelObject ),
375+ 0 ,
376+ Py_TPFLAGS_DEFAULT ,
377+ PyCursesPanel_Type_slots
397378};
398379
399380/* Wrapper for panel_above(NULL). This function returns the bottom
@@ -510,18 +491,20 @@ PyInit__curses_panel(void)
510491{
511492 PyObject * m , * d , * v ;
512493
513- /* Initialize object type */
514- if (PyType_Ready (& PyCursesPanel_Type ) < 0 )
515- return NULL ;
516-
517- import_curses ();
518-
519494 /* Create the module and add the functions */
520495 m = PyModule_Create (& _curses_panelmodule );
521496 if (m == NULL )
522- return NULL ;
497+ goto fail ;
523498 d = PyModule_GetDict (m );
524499
500+ /* Initialize object type */
501+ _curses_panelstate (m )-> PyCursesPanel_Type = \
502+ PyType_FromSpec (& PyCursesPanel_Type_spec );
503+ if (_curses_panelstate (m )-> PyCursesPanel_Type == NULL )
504+ goto fail ;
505+
506+ import_curses ();
507+
525508 /* For exception _curses_panel.error */
526509 _curses_panelstate (m )-> PyCursesError = PyErr_NewException ("_curses_panel.error" , NULL , NULL );
527510 PyDict_SetItemString (d , "error" , _curses_panelstate (m )-> PyCursesError );
@@ -532,4 +515,7 @@ PyInit__curses_panel(void)
532515 PyDict_SetItemString (d , "__version__" , v );
533516 Py_DECREF (v );
534517 return m ;
518+ fail :
519+ Py_XDECREF (m );
520+ return NULL ;
535521}
0 commit comments