Imported Upstream version 3.3.1
[platform/upstream/pygobject2.git] / gi / _gobject / pygobject.h
1 /* -*- Mode: C; c-basic-offset: 4 -*- */
2 #ifndef _PYGOBJECT_H_
3 #define _PYGOBJECT_H_
4
5 #include <Python.h>
6
7 #include <glib.h>
8 #include <glib-object.h>
9
10 G_BEGIN_DECLS
11
12 /* PyGClosure is a _private_ structure */
13 typedef void (* PyClosureExceptionHandler) (GValue *ret, guint n_param_values, const GValue *params);
14 typedef struct _PyGClosure PyGClosure;
15 typedef struct _PyGObjectData PyGObjectData;
16
17 struct _PyGClosure {
18     GClosure closure;
19     PyObject *callback;
20     PyObject *extra_args; /* tuple of extra args to pass to callback */
21     PyObject *swap_data; /* other object for gtk_signal_connect__object */
22     PyClosureExceptionHandler exception_handler;
23 };
24
25 typedef enum {
26     PYGOBJECT_USING_TOGGLE_REF = 1 << 0,
27     PYGOBJECT_IS_FLOATING_REF = 1 << 1
28 } PyGObjectFlags;
29
30   /* closures is just an alias for what is found in the
31    * PyGObjectData */
32 typedef struct {
33     PyObject_HEAD
34     GObject *obj;
35     PyObject *inst_dict; /* the instance dictionary -- must be last */
36     PyObject *weakreflist; /* list of weak references */
37     
38       /*< private >*/
39       /* using union to preserve ABI compatibility (structure size
40        * must not change) */
41     union {
42         GSList *closures; /* stale field; no longer updated DO-NOT-USE! */
43         PyGObjectFlags flags;
44     } private_flags;
45
46 } PyGObject;
47
48 #define pygobject_get(v) (((PyGObject *)(v))->obj)
49 #define pygobject_check(v,base) (PyObject_TypeCheck(v,base))
50
51 typedef struct {
52     PyObject_HEAD
53     gpointer boxed;
54     GType gtype;
55     gboolean free_on_dealloc;
56 } PyGBoxed;
57
58 #define pyg_boxed_get(v,t)      ((t *)((PyGBoxed *)(v))->boxed)
59 #define pyg_boxed_check(v,typecode) (PyObject_TypeCheck(v, &PyGBoxed_Type) && ((PyGBoxed *)(v))->gtype == typecode)
60
61 typedef struct {
62     PyObject_HEAD
63     gpointer pointer;
64     GType gtype;
65 } PyGPointer;
66
67 #define pyg_pointer_get(v,t)      ((t *)((PyGPointer *)(v))->pointer)
68 #define pyg_pointer_check(v,typecode) (PyObject_TypeCheck(v, &PyGPointer_Type) && ((PyGPointer *)(v))->gtype == typecode)
69
70 typedef void (*PyGFatalExceptionFunc) (void);
71 typedef void (*PyGThreadBlockFunc) (void);
72
73 typedef struct {
74     PyObject_HEAD
75     GParamSpec *pspec;
76 } PyGParamSpec;
77
78 #define PyGParamSpec_Get(v) (((PyGParamSpec *)v)->pspec)
79 #define PyGParamSpec_Check(v) (PyObject_TypeCheck(v, &PyGParamSpec_Type))
80
81 typedef int (*PyGClassInitFunc) (gpointer gclass, PyTypeObject *pyclass);
82 typedef PyTypeObject * (*PyGTypeRegistrationFunction) (const gchar *name,
83                                                        gpointer data);
84
85 struct _PyGObject_Functions {
86     /* 
87      * All field names in here are considered private,
88      * use the macros below instead, which provides stability
89      */
90     void (* register_class)(PyObject *dict, const gchar *class_name,
91                             GType gtype, PyTypeObject *type, PyObject *bases);
92     void (* register_wrapper)(PyObject *self);
93     PyTypeObject *(* lookup_class)(GType type);
94     PyObject *(* newgobj)(GObject *obj);
95
96     GClosure *(* closure_new)(PyObject *callback, PyObject *extra_args,
97                               PyObject *swap_data);
98     void      (* object_watch_closure)(PyObject *self, GClosure *closure);
99     GDestroyNotify destroy_notify;
100
101     GType (* type_from_object)(PyObject *obj);
102     PyObject *(* type_wrapper_new)(GType type);
103
104     gint (* enum_get_value)(GType enum_type, PyObject *obj, gint *val);
105     gint (* flags_get_value)(GType flag_type, PyObject *obj, gint *val);
106     void (* register_gtype_custom)(GType gtype,
107                             PyObject *(* from_func)(const GValue *value),
108                             int (* to_func)(GValue *value, PyObject *obj));
109     int (* value_from_pyobject)(GValue *value, PyObject *obj);
110     PyObject *(* value_as_pyobject)(const GValue *value, gboolean copy_boxed);
111
112     void (* register_interface)(PyObject *dict, const gchar *class_name,
113                                 GType gtype, PyTypeObject *type);
114
115     PyTypeObject *boxed_type;
116     void (* register_boxed)(PyObject *dict, const gchar *class_name,
117                             GType boxed_type, PyTypeObject *type);
118     PyObject *(* boxed_new)(GType boxed_type, gpointer boxed,
119                             gboolean copy_boxed, gboolean own_ref);
120
121     PyTypeObject *pointer_type;
122     void (* register_pointer)(PyObject *dict, const gchar *class_name,
123                               GType pointer_type, PyTypeObject *type);
124     PyObject *(* pointer_new)(GType boxed_type, gpointer pointer);
125
126     void (* enum_add_constants)(PyObject *module, GType enum_type,
127                                 const gchar *strip_prefix);
128     void (* flags_add_constants)(PyObject *module, GType flags_type,
129                                  const gchar *strip_prefix);
130
131     const gchar *(* constant_strip_prefix)(const gchar *name,
132                                      const gchar *strip_prefix);
133
134     gboolean (* error_check)(GError **error);
135
136     /* hooks to register handlers for getting GDK threads to cooperate
137      * with python threading */
138     void (* set_thread_block_funcs) (PyGThreadBlockFunc block_threads_func,
139                                      PyGThreadBlockFunc unblock_threads_func);
140     PyGThreadBlockFunc block_threads;
141     PyGThreadBlockFunc unblock_threads;
142     PyTypeObject *paramspec_type;
143     PyObject *(* paramspec_new)(GParamSpec *spec);
144     GParamSpec *(*paramspec_get)(PyObject *tuple);
145     int (*pyobj_to_unichar_conv)(PyObject *pyobj, void* ptr);
146     gboolean (*parse_constructor_args)(GType        obj_type,
147                                        char       **arg_names,
148                                        char       **prop_names,
149                                        GParameter  *params,
150                                        guint       *nparams,
151                                        PyObject   **py_args);
152     PyObject *(* param_gvalue_as_pyobject) (const GValue* gvalue, 
153                                             gboolean copy_boxed,
154                                             const GParamSpec* pspec);
155     int (* gvalue_from_param_pyobject) (GValue* value, 
156                                         PyObject* py_obj, 
157                                         const GParamSpec* pspec);
158     PyTypeObject *enum_type;
159     PyObject *(*enum_add)(PyObject *module,
160                           const char *type_name_,
161                           const char *strip_prefix,
162                           GType gtype);
163     PyObject* (*enum_from_gtype)(GType gtype, int value);
164     
165     PyTypeObject *flags_type;
166     PyObject *(*flags_add)(PyObject *module,
167                            const char *type_name_,
168                            const char *strip_prefix,
169                            GType gtype);
170     PyObject* (*flags_from_gtype)(GType gtype, int value);
171
172     gboolean threads_enabled;
173     int       (*enable_threads) (void);
174
175     int       (*gil_state_ensure) (void);
176     void      (*gil_state_release) (int flag);
177     
178     void      (*register_class_init) (GType gtype, PyGClassInitFunc class_init);
179     void      (*register_interface_info) (GType gtype, const GInterfaceInfo *info);
180     void      (*closure_set_exception_handler) (GClosure *closure, PyClosureExceptionHandler handler);
181
182     void      (*add_warning_redirection) (const char *domain,
183                                           PyObject   *warning);
184     void      (*disable_warning_redirections) (void);
185     void      (*type_register_custom)(const gchar *type_name,
186                                       PyGTypeRegistrationFunction callback,
187                                       gpointer data);
188     gboolean  (*gerror_exception_check) (GError **error);
189     PyObject* (*option_group_new) (GOptionGroup *group);
190     GType (* type_from_object_strict) (PyObject *obj, gboolean strict);    
191 };
192
193 #ifndef _INSIDE_PYGOBJECT_
194
195 #if defined(NO_IMPORT) || defined(NO_IMPORT_PYGOBJECT)
196 extern struct _PyGObject_Functions *_PyGObject_API;
197 #else
198 struct _PyGObject_Functions *_PyGObject_API;
199 #endif
200
201 #define pygobject_register_class    (_PyGObject_API->register_class)
202 #define pygobject_register_wrapper  (_PyGObject_API->register_wrapper)
203 #define pygobject_lookup_class      (_PyGObject_API->lookup_class)
204 #define pygobject_new               (_PyGObject_API->newgobj)
205 #define pyg_closure_new             (_PyGObject_API->closure_new)
206 #define pygobject_watch_closure     (_PyGObject_API->object_watch_closure)
207 #define pyg_closure_set_exception_handler (_PyGObject_API->closure_set_exception_handler)
208 #define pyg_destroy_notify          (_PyGObject_API->destroy_notify)
209 #define pyg_type_from_object_strict   (_PyGObject_API->type_from_object_strict)
210 #define pyg_type_from_object        (_PyGObject_API->type_from_object)
211 #define pyg_type_wrapper_new        (_PyGObject_API->type_wrapper_new)
212 #define pyg_enum_get_value          (_PyGObject_API->enum_get_value)
213 #define pyg_flags_get_value         (_PyGObject_API->flags_get_value)
214 #define pyg_register_gtype_custom   (_PyGObject_API->register_gtype_custom)
215 #define pyg_value_from_pyobject     (_PyGObject_API->value_from_pyobject)
216 #define pyg_value_as_pyobject       (_PyGObject_API->value_as_pyobject)
217 #define pyg_register_interface      (_PyGObject_API->register_interface)
218 #define PyGBoxed_Type               (*_PyGObject_API->boxed_type)
219 #define pyg_register_boxed          (_PyGObject_API->register_boxed)
220 #define pyg_boxed_new               (_PyGObject_API->boxed_new)
221 #define PyGPointer_Type             (*_PyGObject_API->pointer_type)
222 #define pyg_register_pointer        (_PyGObject_API->register_pointer)
223 #define pyg_pointer_new             (_PyGObject_API->pointer_new)
224 #define pyg_enum_add_constants      (_PyGObject_API->enum_add_constants)
225 #define pyg_flags_add_constants     (_PyGObject_API->flags_add_constants)
226 #define pyg_constant_strip_prefix   (_PyGObject_API->constant_strip_prefix)
227 #define pyg_error_check             (_PyGObject_API->error_check)
228 #define pyg_set_thread_block_funcs  (_PyGObject_API->set_thread_block_funcs)
229 #define PyGParamSpec_Type           (*_PyGObject_API->paramspec_type)
230 #define pyg_param_spec_new          (_PyGObject_API->paramspec_new)
231 #define pyg_param_spec_from_object  (_PyGObject_API->paramspec_get)
232 #define pyg_pyobj_to_unichar_conv   (_PyGObject_API->pyobj_to_unichar_conv)
233 #define pyg_parse_constructor_args  (_PyGObject_API->parse_constructor_args)
234 #define pyg_param_gvalue_as_pyobject   (_PyGObject_API->value_as_pyobject)
235 #define pyg_param_gvalue_from_pyobject (_PyGObject_API->gvalue_from_param_pyobject)
236 #define PyGEnum_Type                (*_PyGObject_API->enum_type)
237 #define pyg_enum_add                (_PyGObject_API->enum_add)
238 #define pyg_enum_from_gtype         (_PyGObject_API->enum_from_gtype)
239 #define PyGFlags_Type               (*_PyGObject_API->flags_type)
240 #define pyg_flags_add               (_PyGObject_API->flags_add)
241 #define pyg_flags_from_gtype        (_PyGObject_API->flags_from_gtype)
242 #define pyg_enable_threads          (_PyGObject_API->enable_threads)
243 #define pyg_gil_state_ensure        (_PyGObject_API->gil_state_ensure)
244 #define pyg_gil_state_release       (_PyGObject_API->gil_state_release)
245 #define pyg_register_class_init     (_PyGObject_API->register_class_init)
246 #define pyg_register_interface_info (_PyGObject_API->register_interface_info)
247 #define pyg_add_warning_redirection   (_PyGObject_API->add_warning_redirection)
248 #define pyg_disable_warning_redirections (_PyGObject_API->disable_warning_redirections)
249 #define pyg_type_register_custom_callback (_PyGObject_API->type_register_custom)
250 #define pyg_gerror_exception_check (_PyGObject_API->gerror_exception_check)
251 #define pyg_option_group_new       (_PyGObject_API->option_group_new)
252
253 #define pyg_block_threads()   G_STMT_START {   \
254     if (_PyGObject_API->block_threads != NULL) \
255       (* _PyGObject_API->block_threads)();     \
256   } G_STMT_END
257 #define pyg_unblock_threads() G_STMT_START {     \
258     if (_PyGObject_API->unblock_threads != NULL) \
259       (* _PyGObject_API->unblock_threads)();     \
260   } G_STMT_END
261
262 #define pyg_threads_enabled (_PyGObject_API->threads_enabled)
263
264 #define pyg_begin_allow_threads                 \
265     G_STMT_START {                              \
266         PyThreadState *_save = NULL;            \
267         if (_PyGObject_API->threads_enabled)    \
268             _save = PyEval_SaveThread();
269 #define pyg_end_allow_threads                   \
270         if (_PyGObject_API->threads_enabled)    \
271             PyEval_RestoreThread(_save);        \
272     } G_STMT_END
273
274
275 /**
276  * pygobject_init:
277  * @req_major: minimum version major number, or -1
278  * @req_minor: minimum version minor number, or -1
279  * @req_micro: minimum version micro number, or -1
280  * 
281  * Imports and initializes the 'gobject' python module.  Can
282  * optionally check for a required minimum version if @req_major,
283  * @req_minor, and @req_micro are all different from -1.
284  * 
285  * Returns: a new reference to the gobject module on success, NULL in
286  * case of failure (and raises ImportError).
287  **/
288 static inline PyObject *
289 pygobject_init(int req_major, int req_minor, int req_micro)
290 {
291     PyObject *gobject, *cobject;
292     
293     gobject = PyImport_ImportModule("gi._gobject");
294     if (!gobject) {
295         if (PyErr_Occurred())
296         {
297             PyObject *type, *value, *traceback;
298             PyObject *py_orig_exc;
299             PyErr_Fetch(&type, &value, &traceback);
300             py_orig_exc = PyObject_Repr(value);
301             Py_XDECREF(type);
302             Py_XDECREF(value);
303             Py_XDECREF(traceback);
304
305
306 #if PY_VERSION_HEX < 0x03000000
307             PyErr_Format(PyExc_ImportError,
308                          "could not import gobject (error was: %s)",
309                          PyString_AsString(py_orig_exc));
310 #else
311             {
312                 /* Can not use PyErr_Format because it doesn't have
313                  * a format string for dealing with PyUnicode objects
314                  * like PyUnicode_FromFormat has
315                  */
316                 PyObject *errmsg = PyUnicode_FromFormat("could not import gobject (error was: %U)",
317                                                         py_orig_exc);
318
319                 if (errmsg) {
320                    PyErr_SetObject(PyExc_ImportError,
321                                    errmsg);
322                    Py_DECREF(errmsg);
323                 }
324                 /* if errmsg is NULL then we might have OOM
325                  * PyErr should already be set and trying to
326                  * return our own error would be futile
327                  */
328             }
329 #endif
330             Py_DECREF(py_orig_exc);
331         } else {
332             PyErr_SetString(PyExc_ImportError,
333                             "could not import gobject (no error given)");
334         }
335         return NULL;
336     }
337
338     cobject = PyObject_GetAttrString(gobject, "_PyGObject_API");
339 #if PY_VERSION_HEX >= 0x03000000
340     if (cobject && PyCapsule_CheckExact(cobject))
341         _PyGObject_API = (struct _PyGObject_Functions *) PyCapsule_GetPointer(cobject, "gobject._PyGObject_API");
342
343 #else
344     if (cobject && PyCObject_Check(cobject))
345         _PyGObject_API = (struct _PyGObject_Functions *) PyCObject_AsVoidPtr(cobject);
346 #endif
347     else {
348         PyErr_SetString(PyExc_ImportError,
349                         "could not import gobject (could not find _PyGObject_API object)");
350         Py_DECREF(gobject);
351         return NULL;
352     }
353
354     if (req_major != -1)
355     {
356         int found_major, found_minor, found_micro;
357         PyObject *version;
358
359         version = PyObject_GetAttrString(gobject, "pygobject_version");
360         if (!version) {
361             PyErr_SetString(PyExc_ImportError,
362                             "could not import gobject (version too old)");
363             Py_DECREF(gobject);
364             return NULL;
365         }
366         if (!PyArg_ParseTuple(version, "iii",
367                               &found_major, &found_minor, &found_micro)) {
368             PyErr_SetString(PyExc_ImportError,
369                             "could not import gobject (version has invalid format)");
370             Py_DECREF(version);
371             Py_DECREF(gobject);
372             return NULL;
373         }
374         Py_DECREF(version);
375         if (req_major != found_major ||
376             req_minor >  found_minor ||
377             (req_minor == found_minor && req_micro > found_micro)) {
378             PyErr_Format(PyExc_ImportError,
379                          "could not import gobject (version mismatch, %d.%d.%d is required, "
380                          "found %d.%d.%d)", req_major, req_minor, req_micro,
381                          found_major, found_minor, found_micro);
382             Py_DECREF(gobject);
383             return NULL;
384         }
385     }
386     return gobject;
387 }
388
389 /**
390  * PYLIST_FROMGLIBLIST:
391  * @type: the type of the GLib list e.g. #GList or #GSList
392  * @prefix: the prefix of functions that manipulate a list of the type
393  * given by type.
394  *
395  * A macro that creates a type specific code block which converts a GLib
396  * list (#GSList or #GList) to a Python list. The first two args of the macro
397  * are used to specify the type and list function prefix so that the type
398  * specific macros can be generated.
399  *
400  * The rest of the args are for the standard args for the type specific
401  * macro(s) created from this macro.
402  */
403  #define PYLIST_FROMGLIBLIST(type,prefix,py_list,list,item_convert_func,\
404                             list_free,list_item_free)  \
405 G_STMT_START \
406 { \
407     gint i, len; \
408     PyObject *item; \
409     void (*glib_list_free)(type*) = list_free; \
410     GFunc glib_list_item_free = (GFunc)list_item_free;  \
411  \
412     len = prefix##_length(list); \
413     py_list = PyList_New(len); \
414     for (i = 0; i < len; i++) { \
415         gpointer list_item = prefix##_nth_data(list, i); \
416  \
417         item = item_convert_func; \
418         PyList_SetItem(py_list, i, item); \
419     } \
420     if (glib_list_item_free != NULL) \
421         prefix##_foreach(list, glib_list_item_free, NULL); \
422     if (glib_list_free != NULL) \
423         glib_list_free(list); \
424 } G_STMT_END
425
426 /**
427  * PYLIST_FROMGLIST:
428  * @py_list: the name of the Python list
429  *
430  * @list: the #GList to be converted to a Python list
431  *
432  * @item_convert_func: the function that converts a list item to a Python
433  * object. The function must refer to the list item using "@list_item" and
434  * must return a #PyObject* object. An example conversion function is:
435  * [[
436  * PyString_FromString(list_item)
437  * ]]
438  * A more elaborate function is:
439  * [[
440  * pyg_boxed_new(GTK_TYPE_RECENT_INFO, list_item, TRUE, TRUE)
441  * ]]
442  * @list_free: the name of a function that takes a single arg (the list) and
443  * frees its memory. Can be NULL if the list should not be freed. An example
444  * is:
445  * [[
446  * g_list_free
447  * ]]
448  * @list_item_free: the name of a #GFunc function that frees the memory used
449  * by the items in the list or %NULL if the list items do not have to be
450  * freed. A simple example is:
451  * [[
452  * g_free
453  * ]]
454  *
455  * A macro that adds code that converts a #GList to a Python list.
456  *
457  */
458 #define PYLIST_FROMGLIST(py_list,list,item_convert_func,list_free,\
459                          list_item_free) \
460         PYLIST_FROMGLIBLIST(GList,g_list,py_list,list,item_convert_func,\
461                             list_free,list_item_free)
462
463 /**
464  * PYLIST_FROMGSLIST:
465  * @py_list: the name of the Python list
466  *
467  * @list: the #GSList to be converted to a Python list
468  *
469  * @item_convert_func: the function that converts a list item to a Python
470  * object. The function must refer to the list item using "@list_item" and
471  * must return a #PyObject* object. An example conversion function is:
472  * [[
473  * PyString_FromString(list_item)
474  * ]]
475  * A more elaborate function is:
476  * [[
477  * pyg_boxed_new(GTK_TYPE_RECENT_INFO, list_item, TRUE, TRUE)
478  * ]]
479  * @list_free: the name of a function that takes a single arg (the list) and
480  * frees its memory. Can be %NULL if the list should not be freed. An example
481  * is:
482  * [[
483  * g_list_free
484  * ]]
485  * @list_item_free: the name of a #GFunc function that frees the memory used
486  * by the items in the list or %NULL if the list items do not have to be
487  * freed. A simple example is:
488  * [[
489  * g_free
490  * ]]
491  *
492  * A macro that adds code that converts a #GSList to a Python list.
493  *
494  */
495 #define PYLIST_FROMGSLIST(py_list,list,item_convert_func,list_free,\
496                           list_item_free) \
497         PYLIST_FROMGLIBLIST(GSList,g_slist,py_list,list,item_convert_func,\
498                             list_free,list_item_free)
499
500 /**
501  * PYLIST_ASGLIBLIST
502  * @type: the type of the GLib list e.g. GList or GSList
503  * @prefix: the prefix of functions that manipulate a list of the type
504  * given by type e.g. g_list or g_slist
505  *
506  * A macro that creates a type specific code block to be used to convert a
507  * Python list to a GLib list (GList or GSList). The first two args of the
508  * macro are used to specify the type and list function prefix so that the
509  * type specific macros can be generated.
510  *
511  * The rest of the args are for the standard args for the type specific
512  * macro(s) created from this macro.
513  */
514 #define PYLIST_ASGLIBLIST(type,prefix,py_list,list,check_func,\
515                            convert_func,child_free_func,errormsg,errorreturn) \
516 G_STMT_START \
517 { \
518     Py_ssize_t i, n_list; \
519     GFunc glib_child_free_func = (GFunc)child_free_func;        \
520  \
521     if (!(py_list = PySequence_Fast(py_list, ""))) { \
522         errormsg; \
523         return errorreturn; \
524     } \
525     n_list = PySequence_Fast_GET_SIZE(py_list); \
526     for (i = 0; i < n_list; i++) { \
527         PyObject *py_item = PySequence_Fast_GET_ITEM(py_list, i); \
528  \
529         if (!check_func) { \
530             if (glib_child_free_func) \
531                     prefix##_foreach(list, glib_child_free_func, NULL); \
532             prefix##_free(list); \
533             Py_DECREF(py_list); \
534             errormsg; \
535             return errorreturn; \
536         } \
537         list = prefix##_prepend(list, convert_func); \
538     }; \
539         Py_DECREF(py_list); \
540         list =  prefix##_reverse(list); \
541 } \
542 G_STMT_END
543 /**
544  * PYLIST_ASGLIST
545  * @py_list: the Python list to be converted
546  * @list: the #GList list to be converted
547  * @check_func: the expression that takes a #PyObject* arg (must be named
548  * @py_item) and returns an int value indicating if the Python object matches
549  * the required list item type (0 - %False or 1 - %True). An example is:
550  * [[
551  * (PyString_Check(py_item)||PyUnicode_Check(py_item))
552  * ]]
553  * @convert_func: the function that takes a #PyObject* arg (must be named
554  * py_item) and returns a pointer to the converted list object. An example
555  * is:
556  * [[
557  * pygobject_get(py_item)
558  * ]]
559  * @child_free_func: the name of a #GFunc function that frees a GLib list
560  * item or %NULL if the list item does not have to be freed. This function is
561  * used to help free the items in a partially created list if there is an
562  * error. An example is:
563  * [[
564  * g_free
565  * ]]
566  * @errormsg: a function that sets up a Python error message. An example is:
567  * [[
568  * PyErr_SetString(PyExc_TypeError, "strings must be a sequence of" "strings
569  * or unicode objects")
570  * ]]
571  * @errorreturn: the value to return if an error occurs, e.g.:
572  * [[
573  * %NULL
574  * ]]
575  *
576  * A macro that creates code that converts a Python list to a #GList. The
577  * returned list must be freed using the appropriate list free function when
578  * it's no longer needed. If an error occurs the child_free_func is used to
579  * release the memory used by the list items and then the list memory is
580  * freed.
581  */
582 #define PYLIST_ASGLIST(py_list,list,check_func,convert_func,child_free_func,\
583                        errormsg,errorreturn) \
584         PYLIST_ASGLIBLIST(GList,g_list,py_list,list,check_func,convert_func,\
585                           child_free_func,errormsg,errorreturn)
586
587 /**
588  * PYLIST_ASGSLIST
589  * @py_list: the Python list to be converted
590  * @list: the #GSList list to be converted
591  * @check_func: the expression that takes a #PyObject* arg (must be named
592  * @py_item) and returns an int value indicating if the Python object matches
593  * the required list item type (0 - %False or 1 - %True). An example is:
594  * [[
595  * (PyString_Check(py_item)||PyUnicode_Check(py_item))
596  * ]]
597  * @convert_func: the function that takes a #PyObject* arg (must be named
598  * py_item) and returns a pointer to the converted list object. An example
599  * is:
600  * [[
601  * pygobject_get(py_item)
602  * ]]
603  * @child_free_func: the name of a #GFunc function that frees a GLib list
604  * item or %NULL if the list item does not have to be freed. This function is
605  * used to help free the items in a partially created list if there is an
606  * error. An example is:
607  * [[
608  * g_free
609  * ]]
610  * @errormsg: a function that sets up a Python error message. An example is:
611  * [[
612  * PyErr_SetString(PyExc_TypeError, "strings must be a sequence of" "strings
613  * or unicode objects")
614  * ]]
615  * @errorreturn: the value to return if an error occurs, e.g.:
616  * [[
617  * %NULL
618  * ]]
619  *
620  * A macro that creates code that converts a Python list to a #GSList. The
621  * returned list must be freed using the appropriate list free function when
622  * it's no longer needed. If an error occurs the child_free_func is used to
623  * release the memory used by the list items and then the list memory is
624  * freed.
625  */
626 #define PYLIST_ASGSLIST(py_list,list,check_func,convert_func,child_free_func,\
627                         errormsg,errorreturn) \
628         PYLIST_ASGLIBLIST(GSList,g_slist,py_list,list,check_func,convert_func,\
629                           child_free_func,errormsg,errorreturn)
630
631 #endif /* !_INSIDE_PYGOBJECT_ */
632
633 G_END_DECLS
634
635 #endif /* !_PYGOBJECT_H_ */