medit/moo/moopython/moopython-utils.h

84 lines
3.5 KiB
C
Raw Normal View History

2005-07-26 04:11:46 -07:00
/*
* moopython/moopython-utils.h
2005-07-26 04:11:46 -07:00
*
* Copyright (C) 2004-2006 by Yevgen Muntyan <muntyan@math.tamu.edu>
2005-07-26 04:11:46 -07:00
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* See COPYING file that comes with this distribution.
*/
#ifndef __MOO_PYTHON_UTILS_H__
#define __MOO_PYTHON_UTILS_H__
2005-07-26 04:11:46 -07:00
#include <Python.h>
2005-07-30 09:21:40 -07:00
#include <glib-object.h>
2005-07-26 04:11:46 -07:00
G_BEGIN_DECLS
#define MOO_TYPE_PY_OBJECT (moo_py_object_get_type())
2005-07-26 04:11:46 -07:00
PyObject *moo_py_object_ref (PyObject *obj);
void moo_py_object_unref (PyObject *obj);
GType moo_py_object_get_type (void) G_GNUC_CONST;
2005-07-26 04:11:46 -07:00
PyObject *moo_strv_to_pyobject (char **strv);
/* result may not be freed */
int moo_pyobject_to_strv (PyObject *obj,
char ***dest);
int moo_pyobject_to_strv_no_null (PyObject *obj,
char ***dest);
PyObject *moo_object_slist_to_pyobject (GSList *list);
PyObject *moo_string_slist_to_pyobject (GSList *list);
PyObject *moo_boxed_slist_to_pyobject (GSList *list,
GType type);
PyObject *moo_gvalue_to_pyobject (const GValue *val);
void moo_pyobject_to_gvalue (PyObject *object,
GValue *value);
2005-07-30 09:21:40 -07:00
2006-03-15 00:16:42 -08:00
char *moo_py_err_string (void);
void moo_py_init_print_funcs (void);
2005-07-30 09:21:40 -07:00
#define return_None G_STMT_START {Py_INCREF(Py_None); return Py_None;} G_STMT_END
#define return_Self G_STMT_START {Py_INCREF((PyObject*)self); return (PyObject*)self;} G_STMT_END
#define return_True G_STMT_START {Py_INCREF(Py_True); return Py_True;} G_STMT_END
#define return_False G_STMT_START {Py_INCREF(Py_False); return Py_False;} G_STMT_END
#define return_Bool(v) \
G_STMT_START { \
if ((v)) \
{ \
Py_INCREF(Py_True); \
return Py_True; \
} else \
{ \
Py_INCREF(Py_False); \
return Py_False; \
} \
} G_STMT_END
#define return_Int(v) return Py_BuildValue ((char*)"i", (v))
#define return_AttrError(msg) G_STMT_START {PyErr_SetString(PyExc_AttributeError, msg); return NULL;} G_STMT_END
#define return_AttrErrorInt(msg) G_STMT_START {PyErr_SetString(PyExc_AttributeError, msg); return -1;} G_STMT_END
#define return_TypeError(msg) G_STMT_START {PyErr_SetString(PyExc_TypeError, msg); return NULL;} G_STMT_END
#define return_TypeErrorInt(msg) G_STMT_START {PyErr_SetString(PyExc_TypeError, msg); return -1;} G_STMT_END
#define return_RuntimeError(msg) G_STMT_START {PyErr_SetString(PyExc_RuntimeError, msg); return NULL;} G_STMT_END
#define return_RuntimeErrorInt(msg) G_STMT_START {PyErr_SetString(PyExc_RuntimeError, msg); return -1;} G_STMT_END
#define return_ValueError(msg) G_STMT_START {PyErr_SetString(PyExc_ValueError, msg); return NULL;} G_STMT_END
#define return_ValueErrorInt(msg) G_STMT_START {PyErr_SetString(PyExc_ValueError, msg); return -1;} G_STMT_END
2005-07-30 09:21:40 -07:00
2005-07-26 04:11:46 -07:00
G_END_DECLS
#endif /* __MOO_PYTHON_UTILS_H__ */