2005-07-26 04:11:46 -07:00
|
|
|
/*
|
2005-12-23 06:30:26 -08:00
|
|
|
* moopython/moopython-utils.h
|
2005-07-26 04:11:46 -07:00
|
|
|
*
|
2006-02-23 06:03:17 -08: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.
|
|
|
|
*/
|
|
|
|
|
2005-12-23 06:30:26 -08:00
|
|
|
#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
|
|
|
|
|
2005-11-11 12:14:48 -08:00
|
|
|
#define MOO_TYPE_PY_OBJECT (moo_py_object_get_type())
|
2005-07-26 04:11:46 -07:00
|
|
|
|
2005-11-11 12:14:48 -08: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
|
|
|
|
2005-11-11 12:14:48 -08:00
|
|
|
PyObject *moo_strv_to_pyobject (char **strv);
|
2005-12-04 08:23:10 -08:00
|
|
|
|
|
|
|
/* result may not be freed */
|
2005-11-11 12:14:48 -08:00
|
|
|
int moo_pyobject_to_strv (PyObject *obj,
|
|
|
|
char ***dest);
|
2005-12-04 08:23:10 -08:00
|
|
|
int moo_pyobject_to_strv_no_null (PyObject *obj,
|
|
|
|
char ***dest);
|
2005-11-11 12:14:48 -08:00
|
|
|
|
|
|
|
PyObject *moo_object_slist_to_pyobject (GSList *list);
|
|
|
|
PyObject *moo_string_slist_to_pyobject (GSList *list);
|
2006-06-16 23:35:45 -07:00
|
|
|
PyObject *moo_boxed_slist_to_pyobject (GSList *list,
|
|
|
|
GType type);
|
2005-11-11 12:14:48 -08:00
|
|
|
|
|
|
|
PyObject *moo_gvalue_to_pyobject (const GValue *val);
|
2006-08-12 00:33:22 -07:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
2006-08-12 00:33:22 -07:00
|
|
|
#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
|
|
|
|
|
2005-12-23 06:30:26 -08:00
|
|
|
#endif /* __MOO_PYTHON_UTILS_H__ */
|