Issue #14936: curses_panel was converted to PEP 3121 and PEP 384 API. · python/cpython@bc07cb8 (original) (raw)

`@@ -18,12 +18,11 @@ static char *PyCursesVersion = "2.1";

`

18

18

``

19

19

`typedef struct {

`

20

20

`PyObject *PyCursesError;

`

``

21

`+

PyObject *PyCursesPanel_Type;

`

21

22

`} _curses_panelstate;

`

22

23

``

23

24

`#define _curses_panelstate(o) ((_curses_panelstate *)PyModule_GetState(o))

`

24

25

``

25

``

`-

/*static PyObject PyCursesError;/

`

26

``

-

27

26

`static int

`

28

27

`_curses_panel_clear(PyObject *m)

`

29

28

`{

`

`@@ -84,9 +83,8 @@ typedef struct {

`

84

83

`PyCursesWindowObject wo; / for reference counts */

`

85

84

`} PyCursesPanelObject;

`

86

85

``

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)

`

90

88

``

91

89

`/* Some helper functions. The problem is that there's always a window

`

92

90

` associated with a panel. To ensure that Python's GC doesn't pull

`

`@@ -205,7 +203,8 @@ PyCursesPanel_New(PANEL *pan, PyCursesWindowObject *wo)

`

205

203

`{

`

206

204

`PyCursesPanelObject *po;

`

207

205

``

208

``

`-

po = PyObject_NEW(PyCursesPanelObject, &PyCursesPanel_Type);

`

``

206

`+

po = PyObject_NEW(PyCursesPanelObject,

`

``

207

`+

(PyTypeObject *)(_curses_panelstate_global)->PyCursesPanel_Type);

`

209

208

`if (po == NULL) return NULL;

`

210

209

`po->pan = pan;

`

211

210

`if (insert_lop(po) < 0) {

`

`@@ -364,36 +363,18 @@ static PyMethodDef PyCursesPanel_Methods[] = {

`

364

363

``

365

364

`/* -------------------------------------------------------*/

`

366

365

``

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

`

397

378

`};

`

398

379

``

399

380

`/* Wrapper for panel_above(NULL). This function returns the bottom

`

`@@ -510,18 +491,20 @@ PyInit__curses_panel(void)

`

510

491

`{

`

511

492

`PyObject *m, *d, *v;

`

512

493

``

513

``

`-

/* Initialize object type */

`

514

``

`-

if (PyType_Ready(&PyCursesPanel_Type) < 0)

`

515

``

`-

return NULL;

`

516

``

-

517

``

`-

import_curses();

`

518

``

-

519

494

`/* Create the module and add the functions */

`

520

495

`m = PyModule_Create(&_curses_panelmodule);

`

521

496

`if (m == NULL)

`

522

``

`-

return NULL;

`

``

497

`+

goto fail;

`

523

498

`d = PyModule_GetDict(m);

`

524

499

``

``

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

+

525

508

`/* For exception _curses_panel.error */

`

526

509

`_curses_panelstate(m)->PyCursesError = PyErr_NewException("_curses_panel.error", NULL, NULL);

`

527

510

`PyDict_SetItemString(d, "error", _curses_panelstate(m)->PyCursesError);

`

`@@ -532,4 +515,7 @@ PyInit__curses_panel(void)

`

532

515

`PyDict_SetItemString(d, "version", v);

`

533

516

`Py_DECREF(v);

`

534

517

`return m;

`

``

518

`+

fail:

`

``

519

`+

Py_XDECREF(m);

`

``

520

`+

return NULL;

`

535

521

`}

`