~ubuntu-branches/ubuntu/natty/python3.1/natty-security

« back to all changes in this revision

Viewing changes to Modules/_curses_panel.c

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2010-07-06 16:52:42 UTC
  • mfrom: (1.2.1 upstream) (2.1.11 sid)
  • Revision ID: james.westby@ubuntu.com-20100706165242-2xv4i019r3et6c0j
Tags: 3.1.2+20100706-1ubuntu1
* Merge with Debian; remaining changes:
  - Regenerate the control file.
  - Add debian/patches/overwrite-semaphore-check for Lucid buildds.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
/* Utility Functions */
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
 */
28
28
 
30
30
PyCursesCheckERR(int code, char *fname)
31
31
{
32
32
    if (code != ERR) {
33
 
        Py_INCREF(Py_None);
34
 
        return Py_None;
 
33
        Py_INCREF(Py_None);
 
34
        return Py_None;
35
35
    } else {
36
 
        if (fname == NULL) {
37
 
            PyErr_SetString(PyCursesError, catchall_ERR);
38
 
        } else {
39
 
            PyErr_Format(PyCursesError, "%s() returned ERR", fname);
40
 
        }
41
 
        return NULL;
 
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
}
44
44
 
51
51
typedef struct {
52
52
    PyObject_HEAD
53
53
    PANEL *pan;
54
 
    PyCursesWindowObject *wo;   /* for reference counts */
 
54
    PyCursesWindowObject *wo;   /* for reference counts */
55
55
} PyCursesPanelObject;
56
56
 
57
57
PyTypeObject PyCursesPanel_Type;
58
58
 
59
 
#define PyCursesPanel_Check(v)   (Py_TYPE(v) == &PyCursesPanel_Type)
 
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
62
62
   associated with a panel. To ensure that Python's GC doesn't pull
88
88
insert_lop(PyCursesPanelObject *po)
89
89
{
90
90
    list_of_panels *new;
91
 
    
 
91
 
92
92
    if ((new = (list_of_panels *)malloc(sizeof(list_of_panels))) == NULL) {
93
 
        PyErr_NoMemory();
94
 
        return -1;
 
93
        PyErr_NoMemory();
 
94
        return -1;
95
95
    }
96
96
    new->po = po;
97
97
    new->next = lop;
107
107
 
108
108
    temp = lop;
109
109
    if (temp->po == po) {
110
 
        lop = temp->next;
111
 
        free(temp);
112
 
        return;
 
110
        lop = temp->next;
 
111
        free(temp);
 
112
        return;
113
113
    }
114
114
    while (temp->next == NULL || temp->next->po != po) {
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;
 
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;
123
123
    free(temp->next);
131
131
{
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
}
137
137
 
179
179
    if (po == NULL) return NULL;
180
180
    po->pan = pan;
181
181
    if (insert_lop(po) < 0) {
182
 
        po->wo = NULL;
183
 
        Py_DECREF(po);
184
 
        return NULL;
 
182
        po->wo = NULL;
 
183
        Py_DECREF(po);
 
184
        return NULL;
185
185
    }
186
186
    po->wo = wo;
187
187
    Py_INCREF(wo);
193
193
{
194
194
    (void)del_panel(po->pan);
195
195
    if (po->wo != NULL) {
196
 
        Py_DECREF(po->wo);
197
 
        remove_lop(po);
 
196
        Py_DECREF(po->wo);
 
197
        remove_lop(po);
198
198
    }
199
199
    PyObject_DEL(po);
200
200
}
206
206
{
207
207
    PANEL *pan;
208
208
    PyCursesPanelObject *po;
209
 
    
 
209
 
210
210
    pan = panel_above(self->pan);
211
211
 
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;
 
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;
216
216
    }
217
217
    po = find_po(pan);
218
218
    if (po == NULL) {
219
 
        PyErr_SetString(PyExc_RuntimeError,
220
 
                        "panel_above: can't find Panel Object");
221
 
        return NULL;
 
219
        PyErr_SetString(PyExc_RuntimeError,
 
220
                        "panel_above: can't find Panel Object");
 
221
        return NULL;
222
222
    }
223
223
    Py_INCREF(po);
224
224
    return (PyObject *)po;
231
231
{
232
232
    PANEL *pan;
233
233
    PyCursesPanelObject *po;
234
 
    
 
234
 
235
235
    pan = panel_below(self->pan);
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;
 
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;
241
241
    }
242
242
    po = find_po(pan);
243
243
    if (po == NULL) {
244
 
        PyErr_SetString(PyExc_RuntimeError,
245
 
                        "panel_below: can't find Panel Object");
246
 
        return NULL;
 
244
        PyErr_SetString(PyExc_RuntimeError,
 
245
                        "panel_below: can't find Panel Object");
 
246
        return NULL;
247
247
    }
248
248
    Py_INCREF(po);
249
249
    return (PyObject *)po;
262
262
    PyCursesPanelObject *po;
263
263
    PyCursesWindowObject *temp;
264
264
    int rtn;
265
 
    
 
265
 
266
266
    if (PyTuple_Size(args) != 1) {
267
 
        PyErr_SetString(PyExc_TypeError, "replace requires one argument");
268
 
        return NULL;
 
267
        PyErr_SetString(PyExc_TypeError, "replace requires one argument");
 
268
        return NULL;
269
269
    }
270
270
    if (!PyArg_ParseTuple(args, "O!;window object",
271
 
                          &PyCursesWindow_Type, &temp))
272
 
        return NULL;
 
271
                          &PyCursesWindow_Type, &temp))
 
272
        return NULL;
273
273
 
274
274
    po = find_po(self->pan);
275
275
    if (po == NULL) {
276
 
        PyErr_SetString(PyExc_RuntimeError,
277
 
                        "replace_panel: can't find Panel Object");
278
 
        return NULL;
 
276
        PyErr_SetString(PyExc_RuntimeError,
 
277
                        "replace_panel: can't find Panel Object");
 
278
        return NULL;
279
279
    }
280
280
 
281
281
    rtn = replace_panel(self->pan, temp->win);
282
282
    if (rtn == ERR) {
283
 
        PyErr_SetString(PyCursesError, "replace_panel() returned ERR");
284
 
        return NULL;
 
283
        PyErr_SetString(PyCursesError, "replace_panel() returned ERR");
 
284
        return NULL;
285
285
    }
286
286
    Py_DECREF(po->wo);
287
287
    po->wo = temp;
302
302
PyCursesPanel_userptr(PyCursesPanelObject *self)
303
303
{
304
304
    PyObject *obj;
305
 
    PyCursesInitialised; 
 
305
    PyCursesInitialised;
306
306
    obj = (PyObject *) panel_userptr(self->pan);
307
307
    if (obj == NULL) {
308
 
        PyErr_SetString(PyCursesError, "no userptr set");
309
 
        return NULL;
 
308
        PyErr_SetString(PyCursesError, "no userptr set");
 
309
        return NULL;
310
310
    }
311
311
 
312
312
    Py_INCREF(obj);
329
329
    {"top",             (PyCFunction)PyCursesPanel_top_panel, METH_NOARGS},
330
330
    {"userptr",         (PyCFunction)PyCursesPanel_userptr, METH_NOARGS},
331
331
    {"window",          (PyCFunction)PyCursesPanel_window, METH_NOARGS},
332
 
    {NULL,              NULL}   /* sentinel */
 
332
    {NULL,              NULL}   /* sentinel */
333
333
};
334
334
 
335
335
/* -------------------------------------------------------*/
336
336
 
337
337
PyTypeObject PyCursesPanel_Type = {
338
338
    PyVarObject_HEAD_INIT(NULL, 0)
339
 
    "_curses_panel.curses panel",       /*tp_name*/
340
 
    sizeof(PyCursesPanelObject),        /*tp_basicsize*/
341
 
    0,                  /*tp_itemsize*/
 
339
    "_curses_panel.curses panel",       /*tp_name*/
 
340
    sizeof(PyCursesPanelObject),        /*tp_basicsize*/
 
341
    0,                  /*tp_itemsize*/
342
342
    /* methods */
343
343
    (destructor)PyCursesPanel_Dealloc, /*tp_dealloc*/
344
 
    0,                  /*tp_print*/
345
 
    0,                  /*tp_getattr*/
346
 
    0,                  /*tp_setattr*/
347
 
    0,                  /*tp_reserved*/
348
 
    0,                  /*tp_repr*/
349
 
    0,                  /*tp_as_number*/
350
 
    0,                  /*tp_as_sequence*/
351
 
    0,                  /*tp_as_mapping*/
352
 
    0,                  /*tp_hash*/
353
 
    0,                  /*tp_call*/
354
 
    0,                  /*tp_str*/
355
 
    0,                  /*tp_getattro*/
356
 
    0,                  /*tp_setattro*/
357
 
    0,                  /*tp_as_buffer*/
 
344
    0,                  /*tp_print*/
 
345
    0,                  /*tp_getattr*/
 
346
    0,                  /*tp_setattr*/
 
347
    0,                  /*tp_reserved*/
 
348
    0,                  /*tp_repr*/
 
349
    0,                  /*tp_as_number*/
 
350
    0,                  /*tp_as_sequence*/
 
351
    0,                  /*tp_as_mapping*/
 
352
    0,                  /*tp_hash*/
 
353
    0,                  /*tp_call*/
 
354
    0,                  /*tp_str*/
 
355
    0,                  /*tp_getattro*/
 
356
    0,                  /*tp_setattro*/
 
357
    0,                  /*tp_as_buffer*/
358
358
    Py_TPFLAGS_DEFAULT, /*tp_flags*/
359
 
    0,                  /*tp_doc*/
360
 
    0,                  /*tp_traverse*/
361
 
    0,                  /*tp_clear*/
362
 
    0,                  /*tp_richcompare*/
363
 
    0,                  /*tp_weaklistoffset*/
364
 
    0,                  /*tp_iter*/
365
 
    0,                  /*tp_iternext*/
 
359
    0,                  /*tp_doc*/
 
360
    0,                  /*tp_traverse*/
 
361
    0,                  /*tp_clear*/
 
362
    0,                  /*tp_richcompare*/
 
363
    0,                  /*tp_weaklistoffset*/
 
364
    0,                  /*tp_iter*/
 
365
    0,                  /*tp_iternext*/
366
366
    PyCursesPanel_Methods, /*tp_methods*/
367
367
};
368
368
 
380
380
 
381
381
    pan = panel_above(NULL);
382
382
 
383
 
    if (pan == NULL) {          /* valid output, it means
384
 
                                   there's no panel at all */  
385
 
        Py_INCREF(Py_None);
386
 
        return Py_None;
 
383
    if (pan == NULL) {          /* valid output, it means
 
384
                                   there's no panel at all */
 
385
        Py_INCREF(Py_None);
 
386
        return Py_None;
387
387
    }
388
388
    po = find_po(pan);
389
389
    if (po == NULL) {
390
 
        PyErr_SetString(PyExc_RuntimeError,
391
 
                        "panel_above: can't find Panel Object");
392
 
        return NULL;
 
390
        PyErr_SetString(PyExc_RuntimeError,
 
391
                        "panel_above: can't find Panel Object");
 
392
        return NULL;
393
393
    }
394
394
    Py_INCREF(po);
395
395
    return (PyObject *)po;
405
405
        return NULL;
406
406
    pan = new_panel(win->win);
407
407
    if (pan == NULL) {
408
 
        PyErr_SetString(PyCursesError, catchall_NULL);
409
 
        return NULL;
 
408
        PyErr_SetString(PyCursesError, catchall_NULL);
 
409
        return NULL;
410
410
    }
411
411
    return (PyObject *)PyCursesPanel_New(pan, win);
412
412
}
421
421
{
422
422
    PANEL *pan;
423
423
    PyCursesPanelObject *po;
424
 
    
 
424
 
425
425
    PyCursesInitialised;
426
426
 
427
427
    pan = panel_below(NULL);
428
428
 
429
 
    if (pan == NULL) {          /* valid output, it means
430
 
                                   there's no panel at all */
431
 
        Py_INCREF(Py_None);
432
 
        return Py_None;
 
429
    if (pan == NULL) {          /* valid output, it means
 
430
                                   there's no panel at all */
 
431
        Py_INCREF(Py_None);
 
432
        return Py_None;
433
433
    }
434
434
    po = find_po(pan);
435
435
    if (po == NULL) {
436
 
        PyErr_SetString(PyExc_RuntimeError,
437
 
                        "panel_below: can't find Panel Object");
438
 
        return NULL;
 
436
        PyErr_SetString(PyExc_RuntimeError,
 
437
                        "panel_below: can't find Panel Object");
 
438
        return NULL;
439
439
    }
440
440
    Py_INCREF(po);
441
441
    return (PyObject *)po;
442
442
}
443
443
 
444
444
static PyObject *PyCurses_update_panels(PyObject *self)
445
 
 
445
{
446
446
    PyCursesInitialised;
447
447
    update_panels();
448
448
    Py_INCREF(Py_None);
457
457
    {"new_panel",           (PyCFunction)PyCurses_new_panel,     METH_VARARGS},
458
458
    {"top_panel",           (PyCFunction)PyCurses_top_panel,     METH_NOARGS},
459
459
    {"update_panels",       (PyCFunction)PyCurses_update_panels, METH_NOARGS},
460
 
    {NULL,              NULL}           /* sentinel */
 
460
    {NULL,              NULL}           /* sentinel */
461
461
};
462
462
 
463
463
/* Initialization function for the module */
464
464
 
465
465
 
466
466
static struct PyModuleDef _curses_panelmodule = {
467
 
        PyModuleDef_HEAD_INIT,
468
 
        "_curses_panel",
469
 
        NULL,
470
 
        -1,
471
 
        PyCurses_methods,
472
 
        NULL,
473
 
        NULL,
474
 
        NULL,
475
 
        NULL
 
467
        PyModuleDef_HEAD_INIT,
 
468
        "_curses_panel",
 
469
        NULL,
 
470
        -1,
 
471
        PyCurses_methods,
 
472
        NULL,
 
473
        NULL,
 
474
        NULL,
 
475
        NULL
476
476
};
477
477
 
478
478
PyMODINIT_FUNC
489
489
    /* Create the module and add the functions */
490
490
    m = PyModule_Create(&_curses_panelmodule);
491
491
    if (m == NULL)
492
 
        return NULL;
 
492
        return NULL;
493
493
    d = PyModule_GetDict(m);
494
494
 
495
495
    /* For exception _curses_panel.error */