Changeset 391 for python/trunk/Modules/_curses_panel.c
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Modules/_curses_panel.c
r2 r391 23 23 24 24 /* 25 * Check the return code from a curses function and return None 25 * Check the return code from a curses function and return None 26 26 * or raise an exception as appropriate. 27 27 */ … … 31 31 { 32 32 if (code != ERR) { 33 34 33 Py_INCREF(Py_None); 34 return Py_None; 35 35 } else { 36 37 38 39 40 41 36 if (fname == NULL) { 37 PyErr_SetString(PyCursesError, catchall_ERR); 38 } else { 39 PyErr_Format(PyCursesError, "%s() returned ERR", fname); 40 } 41 return NULL; 42 42 } 43 43 } … … 52 52 PyObject_HEAD 53 53 PANEL *pan; 54 PyCursesWindowObject *wo; 54 PyCursesWindowObject *wo; /* for reference counts */ 55 55 } PyCursesPanelObject; 56 56 57 57 PyTypeObject PyCursesPanel_Type; 58 58 59 #define PyCursesPanel_Check(v) 59 #define PyCursesPanel_Check(v) (Py_TYPE(v) == &PyCursesPanel_Type) 60 60 61 61 /* Some helper functions. The problem is that there's always a window … … 89 89 { 90 90 list_of_panels *new; 91 91 92 92 if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) { 93 94 93 PyErr_NoMemory(); 94 return -1; 95 95 } 96 96 new->po = po; … … 108 108 temp = lop; 109 109 if (temp->po == po) { 110 111 112 110 lop = temp->next; 111 free(temp); 112 return; 113 113 } 114 114 while (temp->next == NULL || temp->next->po != po) { 115 116 117 118 119 120 115 if (temp->next == NULL) { 116 PyErr_SetString(PyExc_RuntimeError, 117 "remove_lop: can't find Panel Object"); 118 return; 119 } 120 temp = temp->next; 121 121 } 122 122 n = temp->next->next; … … 132 132 list_of_panels *temp; 133 133 for (temp = lop; temp->po->pan != pan; temp = temp->next) 134 if (temp->next == NULL) return NULL;/* not found!? */134 if (temp->next == NULL) return NULL; /* not found!? */ 135 135 return temp->po; 136 136 } … … 179 179 if (po == NULL) return NULL; 180 180 po->pan = pan; 181 if (insert_lop(po) < 0) { 182 po->wo = NULL; 183 Py_DECREF(po); 184 return NULL; 185 } 181 186 po->wo = wo; 182 187 Py_INCREF(wo); 183 if (insert_lop(po) < 0) {184 PyObject_DEL(po);185 return NULL;186 }187 188 return (PyObject *)po; 188 189 } … … 192 193 { 193 194 (void)del_panel(po->pan); 194 Py_DECREF(po->wo); 195 remove_lop(po); 195 if (po->wo != NULL) { 196 Py_DECREF(po->wo); 197 remove_lop(po); 198 } 196 199 PyObject_DEL(po); 197 200 } … … 204 207 PANEL *pan; 205 208 PyCursesPanelObject *po; 206 209 207 210 pan = panel_above(self->pan); 208 211 209 if (pan == NULL) { 210 211 212 212 if (pan == NULL) { /* valid output, it means the calling panel 213 is on top of the stack */ 214 Py_INCREF(Py_None); 215 return Py_None; 213 216 } 214 217 po = find_po(pan); 215 218 if (po == NULL) { 216 217 218 219 PyErr_SetString(PyExc_RuntimeError, 220 "panel_above: can't find Panel Object"); 221 return NULL; 219 222 } 220 223 Py_INCREF(po); … … 229 232 PANEL *pan; 230 233 PyCursesPanelObject *po; 231 234 232 235 pan = panel_below(self->pan); 233 234 if (pan == NULL) { 235 236 237 236 237 if (pan == NULL) { /* valid output, it means the calling panel 238 is on the bottom of the stack */ 239 Py_INCREF(Py_None); 240 return Py_None; 238 241 } 239 242 po = find_po(pan); 240 243 if (po == NULL) { 241 242 243 244 PyErr_SetString(PyExc_RuntimeError, 245 "panel_below: can't find Panel Object"); 246 return NULL; 244 247 } 245 248 Py_INCREF(po); … … 260 263 PyCursesWindowObject *temp; 261 264 int rtn; 262 265 263 266 if (PyTuple_Size(args) != 1) { 264 265 267 PyErr_SetString(PyExc_TypeError, "replace requires one argument"); 268 return NULL; 266 269 } 267 270 if (!PyArg_ParseTuple(args, "O!;window object", 268 269 271 &PyCursesWindow_Type, &temp)) 272 return NULL; 270 273 271 274 po = find_po(self->pan); 272 275 if (po == NULL) { 273 274 275 276 PyErr_SetString(PyExc_RuntimeError, 277 "replace_panel: can't find Panel Object"); 278 return NULL; 276 279 } 277 280 278 281 rtn = replace_panel(self->pan, temp->win); 279 282 if (rtn == ERR) { 280 281 283 PyErr_SetString(PyCursesError, "replace_panel() returned ERR"); 284 return NULL; 282 285 } 283 286 Py_DECREF(po->wo); … … 291 294 PyCursesPanel_set_panel_userptr(PyCursesPanelObject *self, PyObject *obj) 292 295 { 296 PyObject *oldobj; 297 int rc; 298 PyCursesInitialised; 293 299 Py_INCREF(obj); 294 return PyCursesCheckERR(set_panel_userptr(self->pan, (void*)obj), 295 "set_panel_userptr"); 300 oldobj = (PyObject *) panel_userptr(self->pan); 301 rc = set_panel_userptr(self->pan, (void*)obj); 302 if (rc == ERR) { 303 /* In case of an ncurses error, decref the new object again */ 304 Py_DECREF(obj); 305 } 306 Py_XDECREF(oldobj); 307 return PyCursesCheckERR(rc, "set_panel_userptr"); 296 308 } 297 309 … … 300 312 { 301 313 PyObject *obj; 302 PyCursesInitialised; 314 PyCursesInitialised; 303 315 obj = (PyObject *) panel_userptr(self->pan); 304 316 if (obj == NULL) { 305 306 317 PyErr_SetString(PyCursesError, "no userptr set"); 318 return NULL; 307 319 } 308 320 … … 327 339 {"userptr", (PyCFunction)PyCursesPanel_userptr, METH_NOARGS}, 328 340 {"window", (PyCFunction)PyCursesPanel_window, METH_NOARGS}, 329 {NULL, 341 {NULL, NULL} /* sentinel */ 330 342 }; 331 343 … … 340 352 PyTypeObject PyCursesPanel_Type = { 341 353 PyVarObject_HEAD_INIT(NULL, 0) 342 "_curses_panel.curses panel", 343 sizeof(PyCursesPanelObject), 344 0, 354 "_curses_panel.curses panel", /*tp_name*/ 355 sizeof(PyCursesPanelObject), /*tp_basicsize*/ 356 0, /*tp_itemsize*/ 345 357 /* methods */ 346 358 (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/ 347 0, 359 0, /*tp_print*/ 348 360 (getattrfunc)PyCursesPanel_GetAttr, /*tp_getattr*/ 349 361 (setattrfunc)0, /*tp_setattr*/ 350 0, 351 0, 352 0, 353 0, 354 0, 355 0, 362 0, /*tp_compare*/ 363 0, /*tp_repr*/ 364 0, /*tp_as_number*/ 365 0, /*tp_as_sequence*/ 366 0, /*tp_as_mapping*/ 367 0, /*tp_hash*/ 356 368 }; 357 369 … … 370 382 pan = panel_above(NULL); 371 383 372 if (pan == NULL) { 373 there's no panel at all */ 374 375 384 if (pan == NULL) { /* valid output, it means 385 there's no panel at all */ 386 Py_INCREF(Py_None); 387 return Py_None; 376 388 } 377 389 po = find_po(pan); 378 390 if (po == NULL) { 379 380 381 391 PyErr_SetString(PyExc_RuntimeError, 392 "panel_above: can't find Panel Object"); 393 return NULL; 382 394 } 383 395 Py_INCREF(po); … … 395 407 pan = new_panel(win->win); 396 408 if (pan == NULL) { 397 398 409 PyErr_SetString(PyCursesError, catchall_NULL); 410 return NULL; 399 411 } 400 412 return (PyObject *)PyCursesPanel_New(pan, win); … … 411 423 PANEL *pan; 412 424 PyCursesPanelObject *po; 413 425 414 426 PyCursesInitialised; 415 427 416 428 pan = panel_below(NULL); 417 429 418 if (pan == NULL) { 419 420 421 430 if (pan == NULL) { /* valid output, it means 431 there's no panel at all */ 432 Py_INCREF(Py_None); 433 return Py_None; 422 434 } 423 435 po = find_po(pan); 424 436 if (po == NULL) { 425 426 427 437 PyErr_SetString(PyExc_RuntimeError, 438 "panel_below: can't find Panel Object"); 439 return NULL; 428 440 } 429 441 Py_INCREF(po); … … 432 444 433 445 static PyObject *PyCurses_update_panels(PyObject *self) 434 { 446 { 435 447 PyCursesInitialised; 436 448 update_panels(); … … 447 459 {"top_panel", (PyCFunction)PyCurses_top_panel, METH_NOARGS}, 448 460 {"update_panels", (PyCFunction)PyCurses_update_panels, METH_NOARGS}, 449 {NULL, NULL}/* sentinel */461 {NULL, NULL} /* sentinel */ 450 462 }; 451 463 … … 465 477 m = Py_InitModule("_curses_panel", PyCurses_methods); 466 478 if (m == NULL) 467 479 return; 468 480 d = PyModule_GetDict(m); 469 481
Note:
See TracChangeset
for help on using the changeset viewer.