/[ascend]/trunk/pygtk/interface/reporter.cpp
ViewVC logotype

Contents of /trunk/pygtk/interface/reporter.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 526 - (show annotations) (download) (as text)
Fri Apr 21 13:47:31 2006 UTC (14 years, 7 months ago) by johnpye
File MIME type: text/x-c++src
File size: 2740 byte(s)
Fixed up a problem with ordering of headers with Python.h.
Removed psyco initialisation, pending evidence that it actually does something :-)
Disabled python 'director' error message callbacks, trying to debug a segfault.
Added ability to disable GCC Visibility, scons WITH_GCCVISIBILITY=0.
Turned off runtime signal tests for SIG_INT and SIG_FPE (makes using GDB a pain), see base/generic/utilities/ascSignal.[ch].
1 #include "config.h"
2 #include "reporter.h"
3
4 #include <cstdio>
5 #include <iostream>
6 using namespace std;
7
8 #ifndef ASCXX_USE_PYTHON
9 # error "Where's ASCXX_USE_PYTHON?"
10 #endif
11
12
13 static const int REPORTER_MAX_ERROR_MSG = 1024;
14
15 #ifdef ASCXX_USE_PYTHON
16 // Python-invoking callback function
17 int reporter_error_python(ERROR_REPORTER_CALLBACK_ARGS){
18 int res=0;
19 if(filename!=NULL){
20 res += ASC_FPRINTF(ASCERR,"%s:",filename);
21 }
22 if(line!=0){
23 res += ASC_FPRINTF(ASCERR,"%d:",line);
24 }
25 if(funcname!=NULL){
26 res += ASC_FPRINTF(ASCERR,"%s:",funcname);
27 }
28 if ((filename!=NULL) || (line!=0) || (funcname!=NULL)){
29 res += ASC_FPRINTF(ASCERR," ");
30 }
31
32 res += ASC_VFPRINTF(ASCERR,fmt,args);
33 return res;
34 //Reporter *reporter = Reporter::Instance();
35 //return reporter->reportErrorPython(ERROR_REPORTER_CALLBACK_VARS);
36 }
37 #endif
38
39 Reporter::Reporter(){
40 error_reporter_set_callback(NULL);
41 }
42
43 Reporter *Reporter::_instance;
44
45 Reporter *
46 Reporter::Instance(){
47 if(_instance==0){
48 _instance = new Reporter();
49 }
50 return _instance;
51 }
52
53 Reporter *getReporter(){
54 return Reporter::Instance();
55 }
56
57 Reporter::~Reporter(){
58 error_reporter_set_callback(NULL);
59 }
60
61 void
62 Reporter::setErrorCallback(error_reporter_callback_t callback, void *client_data){
63 this->client_data = client_data;
64 error_reporter_set_callback(callback);
65 }
66
67 /*
68 int
69 Reporter::reportError(ERROR_REPORTER_CALLBACK_ARGS){
70 char msg[REPORTER_MAX_ERROR_MSG];
71 vsnprintf(msg,REPORTER_MAX_ERROR_MSG,fmt,args);
72 cerr << char(27) << "[32;1m" << msg << char(27) << "[0m";
73 return strlen(msg) + 11; // 11 chars worth of escape codes
74 }
75 */
76
77 #ifdef ASCXX_USE_PYTHON
78 int
79 Reporter::reportErrorPython(ERROR_REPORTER_CALLBACK_ARGS){
80 PyObject *pyfunc, *pyarglist, *pyresult;
81 pyfunc = (PyObject *)client_data;
82
83 char msg[REPORTER_MAX_ERROR_MSG];
84 vsprintf(msg,fmt,args);
85
86 cerr << "reportErrorPython: msg=" << msg ;
87 cerr << "reportErrorPython: pyfunc=" << pyfunc << endl;
88 cerr.flush();
89
90 pyarglist = Py_BuildValue("(H,z,i,z)",sev,filename,line,msg); // Build argument list
91 pyresult = PyEval_CallObject(pyfunc,pyarglist); // Call Python
92 Py_DECREF(pyarglist); // Trash arglist
93
94 int res = 0;
95 if (pyresult) { // If no errors, return int
96 long long_res = PyInt_AsLong(pyresult);
97 res = int(long_res);
98 }else{
99 //cerr << "pyresult = 0"<< endl;
100 }
101
102 Py_XDECREF(pyresult);
103 return res;
104 }
105
106 void
107 Reporter::setPythonErrorCallback(PyObject *pyfunc) {
108 setErrorCallback(reporter_error_python, (void *) pyfunc);
109 Py_INCREF(pyfunc);
110 is_python = true;
111 }
112
113 void
114 Reporter::clearPythonErrorCallback(){
115 if(is_python){
116 PyObject *pyfunc = (PyObject *)client_data;
117 Py_DECREF(pyfunc);
118 is_python=false;
119 }
120 setErrorCallback(NULL);
121 }
122
123 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22