pygobject-private.h 6.42 KB
Newer Older
James Henstridge's avatar
James Henstridge committed
1 2 3 4 5 6 7 8 9 10
#ifndef _PYGOBJECT_PRIVATE_H_
#define _PYGOBJECT_PRIVATE_H_

#ifdef _PYGOBJECT_H_
#  error "include pygobject.h or pygobject-private.h, but not both"
#endif

#define _INSIDE_PYGOBJECT_
#include "pygobject.h"

11 12
#include "pyglib-python-compat.h"

13 14 15 16 17 18 19 20
#define PYGOBJECT_REGISTER_GTYPE(d, type, name, gtype)      \
  {                                                         \
    PyObject *o;					    \
    PYGLIB_REGISTER_TYPE(d, type, name);                    \
    PyDict_SetItemString(type.tp_dict, "__gtype__",         \
			 o=pyg_type_wrapper_new(gtype));    \
    Py_DECREF(o);                                           \
}
21

James Henstridge's avatar
James Henstridge committed
22
/* from gobjectmodule.c */
James Henstridge's avatar
James Henstridge committed
23
extern struct _PyGObject_Functions pygobject_api_functions;
24 25


26 27 28 29 30 31 32 33 34 35 36
#ifndef Py_CLEAR /* since Python 2.4 */
# define Py_CLEAR(op)				\
        do {                            	\
                if (op) {			\
                        PyObject *tmp = (PyObject *)(op);	\
                        (op) = NULL;		\
                        Py_DECREF(tmp);		\
                }				\
        } while (0)
#endif

37
extern GType PY_TYPE_OBJECT;
38

39 40 41 42
extern GQuark pygboxed_type_key;
extern GQuark pygboxed_marshal_key;
extern GQuark pygenum_class_key;
extern GQuark pygflags_class_key;
43 44
extern GQuark pyginterface_type_key;
extern GQuark pyginterface_info_key;
45
extern GQuark pygobject_class_init_key;
46 47 48
extern GQuark pygobject_class_key;
extern GQuark pygobject_wrapper_key;
extern GQuark pygpointer_class_key;
49
extern GQuark pygobject_has_updated_constructor_key;
50
extern GQuark pygobject_instance_data_key;
51
extern GQuark pygobject_custom_key;
52

53
void     pygobject_data_free  (PyGObjectData *data);
54
void     pyg_destroy_notify   (gpointer     user_data);
55
gboolean pyg_handler_marshal  (gpointer     user_data);
56 57 58 59
gboolean pyg_error_check      (GError     **error);
int      pygobject_constructv (PyGObject   *self,
                               guint        n_parameters,
                               GParameter  *parameters);
60

61 62 63 64
PyObject *pyg_integer_richcompare(PyObject *v,
                                  PyObject *w,
                                  int op);

65 66
gboolean pyg_gerror_exception_check(GError **error);

67 68 69
void pygobject_ref_float(PyGObject *self);
void pygobject_ref_sink(PyGObject *self);

70 71 72
/* from pygtype.h */
extern PyTypeObject PyGTypeWrapper_Type;

James Henstridge's avatar
James Henstridge committed
73
PyObject *pyg_type_wrapper_new (GType type);
74
GType     pyg_type_from_object_strict (PyObject *obj, gboolean strict);
James Henstridge's avatar
James Henstridge committed
75 76
GType     pyg_type_from_object (PyObject *obj);

77
gint pyg_enum_get_value  (GType enum_type, PyObject *obj, gint *val);
78
gint pyg_flags_get_value (GType flag_type, PyObject *obj, guint *val);
79
int pyg_pyobj_to_unichar_conv (PyObject* py_obj, void* ptr);
80

James Henstridge's avatar
James Henstridge committed
81
GClosure *pyg_closure_new(PyObject *callback, PyObject *extra_args, PyObject *swap_data);
82 83
void	  pyg_closure_set_exception_handler(GClosure *closure,
					    PyClosureExceptionHandler handler);
James Henstridge's avatar
James Henstridge committed
84
GClosure *pyg_signal_class_closure_get(void);
Johan Dahlin's avatar
Johan Dahlin committed
85
GClosure *gclosure_from_pyfunc(PyGObject *object, PyObject *func);
James Henstridge's avatar
James Henstridge committed
86

James Henstridge's avatar
James Henstridge committed
87
PyObject *pyg_object_descr_doc_get(void);
88
void pygobject_object_register_types(PyObject *d);
James Henstridge's avatar
James Henstridge committed
89

90
extern PyTypeObject *PyGObject_MetaType;
91

92 93
/* from pygobject.h */
extern PyTypeObject PyGObject_Type;
94 95 96
extern PyTypeObject PyGProps_Type;
extern PyTypeObject PyGPropsDescr_Type;
extern PyTypeObject PyGPropsIter_Type;
97 98 99 100 101 102 103

  /* Data that belongs to the GObject instance, not the Python wrapper */
struct _PyGObjectData {
    PyTypeObject *type; /* wrapper type for this instance */
    GSList *closures;
};

104 105 106 107 108 109
void          pygobject_register_class   (PyObject *dict,
					  const gchar *type_name,
					  GType gtype, PyTypeObject *type,
					  PyObject *bases);
void          pygobject_register_wrapper (PyObject *self);
PyObject *    pygobject_new              (GObject *obj);
110
PyObject *    pygobject_new_full         (GObject *obj, gboolean steal, gpointer g_class);
111
void          pygobject_sink             (GObject *obj);
112
PyTypeObject *pygobject_lookup_class     (GType gtype);
113
void          pygobject_watch_closure    (PyObject *self, GClosure *closure);
114
int           pyg_type_register          (PyTypeObject *class,
115
					  const gchar *type_name);
116

James Henstridge's avatar
James Henstridge committed
117 118 119 120 121 122 123 124
/* from pygboxed.c */
extern PyTypeObject PyGBoxed_Type;

void       pyg_register_boxed (PyObject *dict, const gchar *class_name,
			       GType boxed_type, PyTypeObject *type);
PyObject * pyg_boxed_new      (GType boxed_type, gpointer boxed,
			       gboolean copy_boxed, gboolean own_ref);

125 126 127 128 129
extern PyTypeObject PyGPointer_Type;

void       pyg_register_pointer (PyObject *dict, const gchar *class_name,
				 GType pointer_type, PyTypeObject *type);
PyObject * pyg_pointer_new      (GType pointer_type, gpointer pointer);
James Henstridge's avatar
James Henstridge committed
130

131
const gchar * pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix);
132 133 134

/* pygflags */
typedef struct {
135 136
    PYGLIB_PyLongObject parent;
    int zero_pad; /* must always be 0 */
137 138 139 140 141
    GType gtype;
} PyGFlags;

extern PyTypeObject PyGFlags_Type;

142
#define PyGFlags_Check(x) (PyObject_IsInstance((PyObject *)x, (PyObject *)&PyGFlags_Type) && g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_FLAGS))
143

144
extern PyObject * pyg_flags_add        (PyObject *   module,
145
					const char * type_name,
146 147 148
					const char * strip_prefix,
					GType        gtype);
extern PyObject * pyg_flags_from_gtype (GType        gtype,
149
					guint        value);
150 151

/* pygenum */
152
#define PyGEnum_Check(x) (PyObject_IsInstance((PyObject *)x, (PyObject *)&PyGEnum_Type) && g_type_is_a(((PyGFlags*)x)->gtype, G_TYPE_ENUM))
153 154

typedef struct {
155 156
    PYGLIB_PyLongObject parent;
    int zero_pad; /* must always be 0 */
157 158 159 160 161 162
    GType gtype;
} PyGEnum;

extern PyTypeObject PyGEnum_Type;

extern PyObject * pyg_enum_add        (PyObject *   module,
163
				       const char * type_name,
164 165 166 167 168
				       const char * strip_prefix,
				       GType        gtype);
extern PyObject * pyg_enum_from_gtype (GType        gtype,
				       int          value);

169
/* pygtype.c */
170
extern gboolean pyg_gtype_is_custom (GType gtype);
171

172 173 174 175 176 177
/* pygobject.c */
extern PyTypeObject PyGObjectWeakRef_Type;

static inline PyGObjectData *
pyg_object_peek_inst_data(GObject *obj)
{
178
    return ((PyGObjectData *)
179 180 181
            g_object_get_qdata(obj, pygobject_instance_data_key));
}

182 183 184 185
gboolean        pygobject_prepare_construct_properties  (GObjectClass *class,
                                                         PyObject *kwargs,
                                                         guint *n_params,
                                                         GParameter **params);
186 187
/* Defined by PYGLIB_MODULE_START */
extern PyObject *pyglib__gobject_module_create (void);
188

189
#endif /*_PYGOBJECT_PRIVATE_H_*/