/alps/pcitool

To get this branch, use:
bzr branch http://suren.me/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to pcilib/py.c

  • Committer: Suren A. Chilingaryan
  • Date: 2016-03-02 23:50:59 UTC
  • Revision ID: csa@suren.me-20160302235059-i036bhgezo2ikrsy
Make Python problems non-fatal

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
                
136
136
    ctx->py->main_module = PyImport_AddModule("__parser__");
137
137
    if (!ctx->py->main_module) {
138
 
        pcilib_python_error("Error importing python parser");
 
138
        pcilib_python_warning("Error importing python parser");
139
139
        return PCILIB_ERROR_FAILED;
140
140
    }
141
141
 
142
142
    ctx->py->global_dict = PyModule_GetDict(ctx->py->main_module);
143
143
    if (!ctx->py->global_dict) {
144
 
        pcilib_python_error("Error locating global python dictionary");
 
144
        pcilib_python_warning("Error locating global python dictionary");
145
145
        return PCILIB_ERROR_FAILED;
146
146
    }
147
147
 
148
148
    PyObject *pywrap = PyImport_ImportModule(PCILIB_PYTHON_WRAPPER);
149
149
    if (!pywrap) {
150
 
        pcilib_python_error("Error importing pcilib python wrapper");
 
150
        pcilib_python_warning("Error importing pcilib python wrapper");
151
151
        return PCILIB_ERROR_FAILED;
152
152
    }
153
153
        
158
158
    Py_XDECREF(mod_name);
159
159
        
160
160
    if (!ctx->py->pcilib_pywrap) {
161
 
        pcilib_python_error("Error initializing python wrapper");
 
161
        pcilib_python_warning("Error initializing python wrapper");
162
162
        return PCILIB_ERROR_FAILED;
163
163
    }
164
164
#endif /* HAVE_PYTHON */
173
173
    PyObject *pydict, *pystr, *pyret = NULL;
174
174
    char *script_dir;
175
175
 
 
176
    if (!ctx->py) return 0;
 
177
 
176
178
    const char *model_dir = getenv("PCILIB_MODEL_DIR");
177
179
    if (!model_dir) model_dir = PCILIB_MODEL_DIR;
178
180
 
188
190
 
189
191
    pypath = PySys_GetObject("path");
190
192
    if (!pypath) {
191
 
        pcilib_python_error("Can't get python path");
 
193
        pcilib_python_warning("Can't get python path");
192
194
        return PCILIB_ERROR_FAILED;
193
195
    }
194
196
 
195
197
    pynewdir = PyUnicode_FromString(script_dir);
196
198
    if (!pynewdir) {
197
 
        pcilib_python_error("Can't create python string");
 
199
        pcilib_python_warning("Can't create python string");
198
200
        return PCILIB_ERROR_MEMORY;
199
201
    }
200
202
    
224
226
    Py_DECREF(pynewdir);
225
227
 
226
228
    if (err) {
227
 
        pcilib_python_error("Can't add directory (%s) to python path", script_dir);
 
229
        pcilib_python_warning("Can't add directory (%s) to python path", script_dir);
228
230
        return err;
229
231
    }
230
232
#endif /* HAVE_PYTHON */
267
269
    PyObject* pymodule;
268
270
    pcilib_script_t *module = NULL;
269
271
 
 
272
    if (!ctx->py) return 0;
270
273
 
271
274
    char *module_name = strdupa(script_name);
272
275
    if (!module_name) return PCILIB_ERROR_MEMORY;
304
307
    PyObject *dict;
305
308
    PyObject *pystr;
306
309
    pcilib_script_t *module;
307
 
        
 
310
 
 
311
    if (!ctx->py) {
 
312
        if (mode_ret) *mode_ret = mode;
 
313
        return 0;
 
314
    }
 
315
 
308
316
    HASH_FIND_STR(ctx->py->script_hash, script_name, module);
309
317
 
310
318
    if(!module) {
343
351
 
344
352
    long ival;
345
353
    double fval;
346
 
        
 
354
 
 
355
    if (!ctx->py) return NULL;
 
356
 
347
357
    gstate = PyGILState_Ensure();
348
358
    switch(val->type) {
349
359
     case PCILIB_TYPE_LONG:
383
393
    int err = 0;
384
394
    PyObject *pyval = (PyObject*)pval;
385
395
    PyGILState_STATE gstate;
386
 
        
 
396
 
 
397
    if (!ctx->py) return PCILIB_ERROR_NOTINITIALIZED;
 
398
 
387
399
    gstate = PyGILState_Ensure();
388
400
    if (PyLong_Check(pyval)) {
389
401
        err = pcilib_set_value_from_int(ctx, val, PyLong_AsLong(pyval));
536
548
    char *code;
537
549
    PyObject* obj;
538
550
 
 
551
    if (!ctx->py) return PCILIB_ERROR_NOTINITIALIZED;
 
552
 
539
553
    code = pcilib_py_parse_string(ctx, codestr, value);
540
554
    if (!code) {
541
555
        pcilib_error("Failed to parse registers in the code: %s", codestr);
572
586
    PyObject *pyval = NULL, *pyret;
573
587
    pcilib_script_t *module = NULL;
574
588
 
 
589
    if (!ctx->py) return PCILIB_ERROR_NOTINITIALIZED;
 
590
 
575
591
    HASH_FIND_STR(ctx->py->script_hash, script_name, module);
576
592
 
577
593
    if (!module) {