diff options
author | Owen Taylor <otaylor@src.gnome.org> | 2008-11-11 00:04:45 +0000 |
---|---|---|
committer | Owen Taylor <otaylor@src.gnome.org> | 2008-11-11 00:04:45 +0000 |
commit | 1764f6bcf2be6b45b0726694d86c501ce60d1b4e (patch) | |
tree | 41da0fde544d8c86c155c294ac5b70cae4b93aa2 /girepository | |
parent | eceeb044de0a3dd137fa15da7027ce706504bc94 (diff) | |
download | gobject-introspection-1764f6bcf2be6b45b0726694d86c501ce60d1b4e.tar.gz |
Split g_ir_ffi_get_ffi_type() out from ginvoke.c
Extract a function to convert GITypeTag to ffi_type from the internals
of ginvoke.c. This will be useful in figure out structure alignment.
Also fix handling of gsize and time_t to be portable. (Add a check
to configure.ac to figure out the width of time_t.)
svn path=/trunk/; revision=873
Diffstat (limited to 'girepository')
-rw-r--r-- | girepository/Makefile.am | 4 | ||||
-rw-r--r-- | girepository/ginvoke.c | 74 | ||||
-rw-r--r-- | girepository/girffi.c | 100 | ||||
-rw-r--r-- | girepository/girffi.h | 33 |
4 files changed, 139 insertions, 72 deletions
diff --git a/girepository/Makefile.am b/girepository/Makefile.am index be2d0d9c..005672dc 100644 --- a/girepository/Makefile.am +++ b/girepository/Makefile.am @@ -13,7 +13,9 @@ libgirepository_la_SOURCES = \ gtypelib.h \ gtypelib.c \ ginfo.c \ - ginvoke.c + ginvoke.c \ + girffi.c \ + girffi.h libgirepository_la_CPPFLAGS = $(GIREPO_CFLAGS) libgirepository_la_LIBADD = $(GIREPO_LIBS) libgirepository_la_LDFLAGS = -no-undefined diff --git a/girepository/ginvoke.c b/girepository/ginvoke.c index af21473b..89419e56 100644 --- a/girepository/ginvoke.c +++ b/girepository/ginvoke.c @@ -24,6 +24,7 @@ #include <glib-object.h> #include "girepository.h" +#include "girffi.h" #include "gtypelib.h" #include "config.h" @@ -41,79 +42,10 @@ g_invoke_error_quark (void) static ffi_type * get_ffi_type (GITypeInfo *info) { - ffi_type *rettype; - if (g_type_info_is_pointer (info)) - rettype = &ffi_type_pointer; + return &ffi_type_pointer; else - switch (g_type_info_get_tag (info)) - { - case GI_TYPE_TAG_VOID: - rettype = &ffi_type_void; - break; - case GI_TYPE_TAG_BOOLEAN: - rettype = &ffi_type_uint; - break; - case GI_TYPE_TAG_INT8: - rettype = &ffi_type_sint8; - break; - case GI_TYPE_TAG_UINT8: - rettype = &ffi_type_uint8; - break; - case GI_TYPE_TAG_INT16: - rettype = &ffi_type_sint16; - break; - case GI_TYPE_TAG_UINT16: - rettype = &ffi_type_uint16; - break; - case GI_TYPE_TAG_INT32: - rettype = &ffi_type_sint32; - break; - case GI_TYPE_TAG_UINT32: - rettype = &ffi_type_uint32; - break; - case GI_TYPE_TAG_INT64: - rettype = &ffi_type_sint64; - break; - case GI_TYPE_TAG_UINT64: - rettype = &ffi_type_uint64; - break; - case GI_TYPE_TAG_INT: - rettype = &ffi_type_sint; - break; - case GI_TYPE_TAG_UINT: - rettype = &ffi_type_uint; - break; - case GI_TYPE_TAG_SSIZE: /* FIXME */ - case GI_TYPE_TAG_LONG: - rettype = &ffi_type_slong; - break; - case GI_TYPE_TAG_SIZE: /* FIXME */ - case GI_TYPE_TAG_TIME_T: /* May not be portable */ - case GI_TYPE_TAG_ULONG: - rettype = &ffi_type_ulong; - break; - case GI_TYPE_TAG_FLOAT: - rettype = &ffi_type_float; - break; - case GI_TYPE_TAG_DOUBLE: - rettype = &ffi_type_double; - break; - case GI_TYPE_TAG_UTF8: - case GI_TYPE_TAG_FILENAME: - case GI_TYPE_TAG_ARRAY: - case GI_TYPE_TAG_INTERFACE: - case GI_TYPE_TAG_GLIST: - case GI_TYPE_TAG_GSLIST: - case GI_TYPE_TAG_GHASH: - case GI_TYPE_TAG_ERROR: - rettype = &ffi_type_pointer; - break; - default: - g_assert_not_reached (); - } - - return rettype; + return g_ir_ffi_get_ffi_type (g_type_info_get_tag (info)); } /** diff --git a/girepository/girffi.c b/girepository/girffi.c new file mode 100644 index 00000000..db5e87e8 --- /dev/null +++ b/girepository/girffi.c @@ -0,0 +1,100 @@ +/* GObject introspection: Helper functions for ffi integration + * + * Copyright (C) 2008 Red Hat, Inc + * Copyright (C) 2005 Matthias Clasen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include <config.h> +#include "girffi.h" + +ffi_type * +g_ir_ffi_get_ffi_type (GITypeTag tag) +{ + switch (tag) + { + case GI_TYPE_TAG_VOID: + return &ffi_type_void; + case GI_TYPE_TAG_BOOLEAN: + return &ffi_type_uint; + case GI_TYPE_TAG_INT8: + return &ffi_type_sint8; + case GI_TYPE_TAG_UINT8: + return &ffi_type_uint8; + case GI_TYPE_TAG_INT16: + return &ffi_type_sint16; + case GI_TYPE_TAG_UINT16: + return &ffi_type_uint16; + case GI_TYPE_TAG_INT32: + return &ffi_type_sint32; + case GI_TYPE_TAG_UINT32: + return &ffi_type_uint32; + case GI_TYPE_TAG_INT64: + return &ffi_type_sint64; + case GI_TYPE_TAG_UINT64: + return &ffi_type_uint64; + case GI_TYPE_TAG_INT: + return &ffi_type_sint; + case GI_TYPE_TAG_UINT: + return &ffi_type_uint; + case GI_TYPE_TAG_SSIZE: +#if GLIB_SIZEOF_SIZE_T == 4 + return &ffi_type_sint32; +#elif GLIB_SIZEOF_SIZE_T == 8 + return &ffi_type_sint64; +#else +# error "Unexpected size for size_t: not 4 or 8" +#endif + case GI_TYPE_TAG_LONG: + return &ffi_type_slong; + case GI_TYPE_TAG_SIZE: + case GI_TYPE_TAG_GTYPE: +#if GLIB_SIZEOF_SIZE_T == 4 + return &ffi_type_uint32; +#elif GLIB_SIZEOF_SIZE_T == 8 + return &ffi_type_uint64; +#else +# error "Unexpected size for size_t: not 4 or 8" +#endif + case GI_TYPE_TAG_TIME_T: +#if SIZEOF_TIME_T == 4 + return &ffi_type_sint32; +#elif SIZEOF_TIME_T == 8 + return &ffi_type_sint64; +#else +# error "Unexpected time for time_t: not 4 or 8" +#endif + case GI_TYPE_TAG_ULONG: + return &ffi_type_ulong; + case GI_TYPE_TAG_FLOAT: + return &ffi_type_float; + case GI_TYPE_TAG_DOUBLE: + return &ffi_type_double; + case GI_TYPE_TAG_UTF8: + case GI_TYPE_TAG_FILENAME: + case GI_TYPE_TAG_ARRAY: + case GI_TYPE_TAG_INTERFACE: + case GI_TYPE_TAG_GLIST: + case GI_TYPE_TAG_GSLIST: + case GI_TYPE_TAG_GHASH: + case GI_TYPE_TAG_ERROR: + return &ffi_type_pointer; + } + + g_assert_not_reached (); + + return NULL; +} diff --git a/girepository/girffi.h b/girepository/girffi.h new file mode 100644 index 00000000..842a2334 --- /dev/null +++ b/girepository/girffi.h @@ -0,0 +1,33 @@ +/* GObject introspection: Helper functions for ffi integration + * + * Copyright (C) 2008 Red Hat, Inc + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef __GIRFFI_H__ +#define __GIRFFI_H__ + +#include "girepository.h" +#include <ffi.h> + +G_BEGIN_DECLS + +ffi_type *g_ir_ffi_get_ffi_type (GITypeTag tag); + +G_END_DECLS + +#endif /* __GIRFFI_H__ */ |