2
* Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for
5
* This library is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU Library General Public License as published by
7
* the Free Software Foundation; either version 2.1 of the License, or (at your
8
* option) any later version.
10
* This library is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13
* License for more details.
15
* You should have received a copy of the GNU Library General Public License
16
* along with this library; if not, write to the Free Software Foundation,
17
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307 USA.
19
* $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Glib/gperl.h,v 1.41 2005/04/26 22:56:56 ebassi Exp $
30
/* perl and glib disagree on a few macros... let the wookie win. */
37
#include <glib-object.h>
43
/* never use this function directly. use GPERL_CALL_BOOT. */
44
void _gperl_call_XS (pTHX_ void (*subaddr) (pTHX_ CV *), CV * cv, SV ** mark);
47
* call the boot code of a module by symbol rather than by name.
49
* in a perl extension which uses several xs files but only one pm, you
50
* need to bootstrap the other xs files in order to get their functions
51
* exported to perl. if the file has MODULE = Foo::Bar, the boot symbol
52
* would be boot_Foo__Bar.
54
#define GPERL_CALL_BOOT(name) \
57
_gperl_call_XS (aTHX_ name, cv, mark); \
60
gpointer gperl_alloc_temp (int nbytes);
61
gchar *gperl_filename_from_sv (SV *sv);
62
SV *gperl_sv_from_filename (const gchar *filename);
64
gboolean gperl_str_eq (const char * a, const char * b);
65
guint gperl_str_hash (gconstpointer key);
73
GPerlArgv * gperl_argv_new ();
74
void gperl_argv_update (GPerlArgv *pargv);
75
void gperl_argv_free (GPerlArgv *pargv);
77
char * gperl_format_variable_for_output (SV * sv);
79
/* internal trickery */
80
gpointer gperl_type_class (GType type);
84
gboolean gperl_try_convert_enum (GType type, SV * sv, gint * val);
85
gint gperl_convert_enum (GType type, SV * val);
86
SV * gperl_convert_back_enum_pass_unknown (GType type, gint val);
87
SV * gperl_convert_back_enum (GType type, gint val);
89
gboolean gperl_try_convert_flag (GType type, const char * val_p, gint * val);
90
gint gperl_convert_flag_one (GType type, const char * val_p);
91
gint gperl_convert_flags (GType type, SV * val);
92
SV * gperl_convert_back_flags (GType type, gint val);
94
/* register a fundamental type (enums, flags...) */
96
typedef struct _GPerlValueWrapperClass GPerlValueWrapperClass;
98
typedef SV* (*GPerlValueWrapFunc) (const GValue * value);
99
typedef void (*GPerlValueUnwrapFunc) (GValue * value,
102
struct _GPerlValueWrapperClass {
103
GPerlValueWrapFunc wrap;
104
GPerlValueUnwrapFunc unwrap;
107
void gperl_register_fundamental (GType gtype, const char * package);
108
void gperl_register_fundamental_full (GType gtype, const char * package, GPerlValueWrapperClass * wrapper_class);
110
GType gperl_fundamental_type_from_package (const char * package);
111
const char * gperl_fundamental_package_from_type (GType gtype);
112
GPerlValueWrapperClass * gperl_fundamental_wrapper_class_from_type (GType gtype);
115
* GErrors as exception objects
117
/* it is rare that you should ever want or need these two functions. */
118
SV * gperl_sv_from_gerror (GError * error);
119
void gperl_gerror_from_sv (SV * sv, GError ** error);
121
void gperl_register_error_domain (GQuark domain,
123
const char * package);
125
void gperl_croak_gerror (const char * ignored, GError * err);
128
* inheritance management
130
/* push @{$parent_package}::ISA, $child_package */
131
void gperl_set_isa (const char * child_package, const char * parent_package);
132
/* unshift @{$parent_package}::ISA, $child_package */
133
void gperl_prepend_isa (const char * child_package, const char * parent_package);
135
/* these work regardless of what the actual type is (GBoxed, GObject, GEnum,
136
* or GFlags). in general it's safer to use the most specific one, but this
137
* is handy when you don't care. */
138
GType gperl_type_from_package (const char * package);
139
const char * gperl_package_from_type (GType type);
143
* we need a GBoxed wrapper for a generic SV, so we can store SVs
144
* in GObjects reliably.
146
#define GPERL_TYPE_SV (gperl_sv_get_type ())
147
GType gperl_sv_get_type (void) G_GNUC_CONST;
148
SV * gperl_sv_copy (SV * sv);
149
void gperl_sv_free (SV * sv);
153
* clean function wrappers for treating gchar* as UTF8 strings, in the
154
* same idiom as the rest of the cast macros. these are wrapped up
155
* as functions because comma expressions in macros get kinda tricky.
157
/*const*/ gchar * SvGChar (SV * sv);
158
SV * newSVGChar (const gchar * str);
165
gboolean gperl_value_from_sv (GValue * value, SV * sv);
166
SV * gperl_sv_from_value (const GValue * value);
172
typedef struct _GPerlBoxedWrapperClass GPerlBoxedWrapperClass;
174
typedef SV* (*GPerlBoxedWrapFunc) (GType gtype,
175
const char * package,
178
typedef gpointer (*GPerlBoxedUnwrapFunc) (GType gtype,
179
const char * package,
181
typedef void (*GPerlBoxedDestroyFunc) (SV * sv);
183
struct _GPerlBoxedWrapperClass {
184
GPerlBoxedWrapFunc wrap;
185
GPerlBoxedUnwrapFunc unwrap;
186
GPerlBoxedDestroyFunc destroy;
189
GPerlBoxedWrapperClass * gperl_default_boxed_wrapper_class (void);
191
void gperl_register_boxed (GType gtype,
192
const char * package,
193
GPerlBoxedWrapperClass * wrapper_class);
195
SV * gperl_new_boxed (gpointer boxed, GType gtype, gboolean own);
196
SV * gperl_new_boxed_copy (gpointer boxed, GType gtype);
197
gpointer gperl_get_boxed_check (SV * sv, GType gtype);
200
GType gperl_boxed_type_from_package (const char * package);
201
const char * gperl_boxed_package_from_type (GType type);
207
void gperl_register_object (GType gtype, const char * package);
209
typedef void (*GPerlObjectSinkFunc) (GObject *);
210
void gperl_register_sink_func (GType gtype,
211
GPerlObjectSinkFunc func);
213
void gperl_object_set_no_warn_unreg_subclass (GType gtype, gboolean nowarn);
215
const char * gperl_object_package_from_type (GType gtype);
216
HV * gperl_object_stash_from_type (GType gtype);
217
GType gperl_object_type_from_package (const char * package);
219
SV * gperl_new_object (GObject * object, gboolean own);
221
GObject * gperl_get_object (SV * sv);
222
GObject * gperl_get_object_check (SV * sv, GType gtype);
224
SV * gperl_object_check_type (SV * sv, GType gtype);
226
/* typedefs and macros for use with the typemap */
227
typedef gchar gchar_length;
228
typedef gchar gchar_own;
229
typedef gchar gchar_ornull;
230
typedef char char_ornull;
231
typedef char char_own;
232
typedef GObject GObject_ornull;
233
typedef GObject GObject_noinc;
234
typedef gchar *GPerlFilename;
235
typedef const gchar *GPerlFilename_const;
236
typedef gchar *GPerlFilename_own;
237
typedef GPerlFilename GPerlFilename_ornull;
239
#define newSVGObject(obj) (gperl_new_object ((obj), FALSE))
240
#define newSVGObject_noinc(obj) (gperl_new_object ((obj), TRUE))
241
#define SvGObject(sv) (gperl_get_object (sv))
242
#define SvGObject_ornull(sv) ((sv && SvOK (sv)) ? SvGObject (sv) : NULL)
248
SV * newSVGSignalFlags (GSignalFlags flags);
249
GSignalFlags SvGSignalFlags (SV * sv);
250
SV * newSVGSignalInvocationHint (GSignalInvocationHint * ihint);
251
SV * newSVGSignalQuery (GSignalQuery * query);
253
void gperl_signal_set_marshaller_for (GType instance_type,
254
char * detailed_signal,
255
GClosureMarshal marshaller);
256
gulong gperl_signal_connect (SV * instance,
257
char * detailed_signal,
260
GConnectFlags flags);
266
typedef struct _GPerlClosure GPerlClosure;
267
struct _GPerlClosure {
270
SV * data; /* callback data */
271
gboolean swap; /* TRUE if target and data are to be swapped */
275
/* evaluates to true if the instance and data are to be swapped on invocation */
276
#define GPERL_CLOSURE_SWAP_DATA(gpc) ((gpc)->swap)
278
/* this is the one you want. */
279
GClosure * gperl_closure_new (SV * callback,
282
/* very scary, use only if you really know what you are doing */
283
GClosure * gperl_closure_new_with_marshaller (SV * callback,
286
GClosureMarshal marshaller);
292
typedef struct _GPerlCallback GPerlCallback;
293
struct _GPerlCallback {
302
GPerlCallback * gperl_callback_new (SV * func,
308
void gperl_callback_destroy (GPerlCallback * callback);
310
void gperl_callback_invoke (GPerlCallback * callback,
311
GValue * return_value,
318
int gperl_install_exception_handler (GClosure * closure);
319
void gperl_remove_exception_handler (guint tag);
320
void gperl_run_exception_handlers (void);
323
* to be used by extensions...
325
gint gperl_handle_logs_for (const gchar * log_domain);
328
* gparamspec.h / GParamSpec.xs
330
SV * newSVGParamSpec (GParamSpec * pspec);
331
GParamSpec * SvGParamSpec (SV * sv);
332
SV * newSVGParamFlags (GParamFlags flags);
333
GParamFlags SvGParamFlags (SV * sv);
336
* gkeyfile.h / GKeyFile.xs
338
#if GLIB_CHECK_VERSION (2, 6, 0)
339
SV * newSVGKeyFile (GKeyFile * key_file);
340
GKeyFile * SvGKeyFile (SV * sv);
341
SV * newSVGKeyFileFlags (GKeyFileFlags flags);
342
GKeyFileFlags SvGKeyFileFlags (SV * sv);
343
#endif /* GLIB_CHECK_VERSION (2, 6, 0) */
345
const char * gperl_param_spec_package_from_type (GType gtype);
348
* helpful debugging stuff
350
#define GPERL_OBJECT_VITALS(o) \
352
? form ("%s(%p)[%d]", G_OBJECT_TYPE_NAME (o), (o), \
353
G_OBJECT (o)->ref_count) \
355
#define GPERL_WRAPPER_VITALS(w) \
358
? form ("SvRV(%p)->%s(%p)[%d]", (w), \
359
sv_reftype (SvRV (w), TRUE), \
360
SvRV (w), SvREFCNT (SvRV (w))) \
361
: "[not a reference!]") \
364
#endif /* _GPERL_H_ */