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