moo_py_set_error()

master
Yevgen Muntyan 2007-05-22 23:59:55 -05:00
parent de70314d1f
commit b667c8b41d
2 changed files with 52 additions and 1 deletions

View File

@ -20,6 +20,7 @@
#include <Python.h> #include <Python.h>
#define NO_IMPORT_PYGOBJECT #define NO_IMPORT_PYGOBJECT
#include "pygobject.h" #include "pygobject.h"
#include <glib/gprintf.h>
static MooPyObject * static MooPyObject *
@ -232,6 +233,43 @@ moo_python_api_dict_del_item (MooPyObject *dict,
} }
static void
moo_python_api_set_error (int type,
const char *format,
...)
{
PyObject *exception = NULL;
char *msg = NULL;
va_list args;
va_start (args, format);
g_vasprintf (&msg, format, args);
va_end (args);
g_return_if_fail (msg != NULL);
switch (type)
{
case MOO_PY_RUNTIME_ERROR:
exception = PyExc_RuntimeError;
break;
case MOO_PY_TYPE_ERROR:
exception = PyExc_TypeError;
break;
case MOO_PY_VALUE_ERROR:
exception = PyExc_ValueError;
break;
case MOO_PY_NOT_IMPLEMENTED_ERROR:
exception = PyExc_NotImplementedError;
break;
}
g_return_if_fail (exception != NULL);
PyErr_SetString (exception, (char*) msg);
}
static void static void
moo_python_api_py_err_print (void) moo_python_api_py_err_print (void)
{ {
@ -439,6 +477,7 @@ moo_python_api_init (void)
moo_python_api_dict_del_item, moo_python_api_dict_del_item,
moo_python_api_import_exec, moo_python_api_import_exec,
moo_python_api_set_error,
moo_python_api_py_err_print, moo_python_api_py_err_print,
moo_python_api_py_object_call_method, moo_python_api_py_object_call_method,
moo_python_api_py_object_call_function, moo_python_api_py_object_call_function,

View File

@ -18,7 +18,7 @@
G_BEGIN_DECLS G_BEGIN_DECLS
#define MOO_PY_API_VERSION 93 #define MOO_PY_API_VERSION 94
typedef struct _MooPyAPI MooPyAPI; typedef struct _MooPyAPI MooPyAPI;
typedef struct _MooPyObject MooPyObject; typedef struct _MooPyObject MooPyObject;
@ -35,6 +35,13 @@ enum {
MOO_PY_METH_STATIC = 1 << 5 MOO_PY_METH_STATIC = 1 << 5
}; };
enum {
MOO_PY_RUNTIME_ERROR,
MOO_PY_TYPE_ERROR,
MOO_PY_VALUE_ERROR,
MOO_PY_NOT_IMPLEMENTED_ERROR
};
struct _MooPyMethodDef { struct _MooPyMethodDef {
const char *ml_name; const char *ml_name;
MooPyCFunction ml_meth; MooPyCFunction ml_meth;
@ -79,6 +86,9 @@ struct _MooPyAPI {
MooPyObject* (*import_exec) (const char *name, MooPyObject* (*import_exec) (const char *name,
const char *string); const char *string);
void (*set_error) (int type,
const char *format,
...);
void (*py_err_print) (void); void (*py_err_print) (void);
MooPyObject* (*py_object_call_method) (MooPyObject *object, MooPyObject* (*py_object_call_method) (MooPyObject *object,
const char *method, const char *method,
@ -128,6 +138,8 @@ void moo_Py_DECREF (MooPyObject *obj);
#define moo_py_object_from_gobject moo_py_api->py_object_from_gobject #define moo_py_object_from_gobject moo_py_api->py_object_from_gobject
#define moo_gobject_from_py_object moo_py_api->gobject_from_py_object #define moo_gobject_from_py_object moo_py_api->gobject_from_py_object
#define moo_py_set_error moo_py_api->set_error
#define moo_PyErr_Print moo_py_api->py_err_print #define moo_PyErr_Print moo_py_api->py_err_print
#define moo_PyObject_CallMethod moo_py_api->py_object_call_method #define moo_PyObject_CallMethod moo_py_api->py_object_call_method
#define moo_PyObject_CallFunction moo_py_api->py_object_call_function #define moo_PyObject_CallFunction moo_py_api->py_object_call_function