~lifeless/storm/bug-620615

« back to all changes in this revision

Viewing changes to storm/cextensions.c

  • Committer: Gustavo Niemeyer
  • Date: 2008-06-18 23:13:04 UTC
  • mto: (235.2.21 need-for-speed-revenge)
  • mto: This revision was merged to the branch mainline in revision 245.
  • Revision ID: gustavo@niemeyer.net-20080618231304-iww2kewacv2ux78v
Simplify the calling semantics of _when in the expr module, as
suggested by James.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1281
1281
static PyObject *
1282
1282
Compile_when(CompileObject *self, PyObject *types)
1283
1283
{
1284
 
    PyObject *module = NULL;
1285
 
    PyObject *_when = NULL;
1286
 
    PyObject *args = NULL;
1287
 
    PyObject *decorator;
1288
 
    Py_ssize_t i;
1289
 
 
1290
 
    CATCH(NULL, module = PyImport_ImportModule("storm.expr"));
1291
 
    CATCH(NULL, _when = PyObject_GetAttrString(module, "_when"));
1292
 
 
1293
 
    CATCH(NULL, args = PyTuple_New(PyTuple_GET_SIZE(types) + 1));
1294
 
 
1295
 
    Py_INCREF(self);
1296
 
    PyTuple_SET_ITEM(args, 0, (PyObject *)self);
1297
 
 
1298
 
    for (i = 0; i != PyTuple_GET_SIZE(types); i++) {
1299
 
        PyObject *item = PyTuple_GET_ITEM(types, i);
1300
 
        Py_INCREF(item);
1301
 
        PyTuple_SET_ITEM(args, i + 1, item);
 
1284
    PyObject *result = NULL;
 
1285
    PyObject *module = PyImport_ImportModule("storm.expr");
 
1286
    if (module) {
 
1287
        PyObject *_when = PyObject_GetAttrString(module, "_when");
 
1288
        if (_when) {
 
1289
            result = PyObject_CallFunctionObjArgs(_when, self, types, NULL);
 
1290
            Py_DECREF(_when);
 
1291
        }
 
1292
        Py_DECREF(module);
1302
1293
    }
1303
 
 
1304
 
    CATCH(NULL, decorator = PyObject_Call(_when, args, NULL));
1305
 
 
1306
 
    Py_DECREF(module);
1307
 
    Py_DECREF(_when);
1308
 
    Py_DECREF(args);
1309
 
    return decorator;
1310
 
 
1311
 
error:
1312
 
    Py_XDECREF(module);
1313
 
    Py_XDECREF(_when);
1314
 
    Py_XDECREF(args);
1315
 
    return NULL;
 
1294
    return result;    
1316
1295
}
1317
1296
 
1318
1297
static PyObject *