build: Allow to build cogl without an external glib dependency

This commit pushes --disable-glib to the extreme of embedding the par of
glib cogl depends on in tree to be able to generate a DSO that does not
depend on an external glib.

To do so, it:
  - keeps a lot of glib's configure.ac in as-glibconfig.m4
  - pulls the code cogl depends on and the necessary dependencies

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This commit is contained in:
Damien Lespiau 2012-09-17 02:20:10 +01:00 committed by Robert Bragg
parent df21e20f65
commit d2c41502a4
85 changed files with 40555 additions and 63 deletions

4
.gitignore vendored
View File

@ -18,7 +18,9 @@ stamp-enum-types
stamp-marshal
/build/autotools/*.m4
/build/win32/*.bat
!/build/autotools/acglib.m4
!/build/autotools/introspection.m4
!/build/autotools/as-glibconfig.m4
!/build/autotools/as-linguas.m4
!/build/autotools/as-compiler-flag.m4
/build/config.guess
@ -42,6 +44,8 @@ config.log
config.status
configure
depcomp
/deps/glib/glibconfig.h
/deps/gmodule/gmoduleconf.h
/doc/reference/cogl2/cogl2-*.txt
!/doc/reference/cogl2/cogl2-sections.txt
/doc/reference/cogl2/html

View File

@ -1,4 +1,4 @@
SUBDIRS = cogl tests
SUBDIRS = deps cogl tests
if BUILD_COGL_PANGO
SUBDIRS += cogl-pango

131
build/autotools/acglib.m4 Normal file
View File

@ -0,0 +1,131 @@
## Portability defines that help interoperate with classic and modern autoconfs
ifdef([AC_TR_SH],[
define([GLIB_TR_SH],[AC_TR_SH([$1])])
define([GLIB_TR_CPP],[AC_TR_CPP([$1])])
], [
define([GLIB_TR_SH],
[patsubst(translit([[$1]], [*+], [pp]), [[^a-zA-Z0-9_]], [_])])
define([GLIB_TR_CPP],
[patsubst(translit([[$1]],
[*abcdefghijklmnopqrstuvwxyz],
[PABCDEFGHIJKLMNOPQRSTUVWXYZ]),
[[^A-Z0-9_]], [_])])
])
# GLIB_AC_DIVERT_BEFORE_HELP(STUFF)
# ---------------------------------
# Put STUFF early enough so that they are available for $ac_help expansion.
# Handle both classic (<= v2.13) and modern autoconf
AC_DEFUN([GLIB_AC_DIVERT_BEFORE_HELP],
[ifdef([m4_divert_text], [m4_divert_text([NOTICE],[$1])],
[ifdef([AC_DIVERT], [AC_DIVERT([NOTICE],[$1])],
[AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)dnl
$1
AC_DIVERT_POP()])])])
dnl GLIB_IF_VAR_EQ (ENV_VAR, VALUE [, EQUALS_ACTION] [, ELSE_ACTION])
AC_DEFUN([GLIB_IF_VAR_EQ],[
case "$[$1]" in
"[$2]"[)]
[$3]
;;
*[)]
[$4]
;;
esac
])
dnl GLIB_STR_CONTAINS (SRC_STRING, SUB_STRING [, CONTAINS_ACTION] [, ELSE_ACTION])
AC_DEFUN([GLIB_STR_CONTAINS],[
case "[$1]" in
*"[$2]"*[)]
[$3]
;;
*[)]
[$4]
;;
esac
])
dnl GLIB_ADD_TO_VAR (ENV_VARIABLE, CHECK_STRING, ADD_STRING)
AC_DEFUN([GLIB_ADD_TO_VAR],[
GLIB_STR_CONTAINS($[$1], [$2], [$1]="$[$1]", [$1]="$[$1] [$3]")
])
# GLIB_SIZEOF (INCLUDES, TYPE, ALIAS)
# ---------------------------------------------------------------
# The definition here is based of that of AC_CHECK_SIZEOF
AC_DEFUN([GLIB_SIZEOF],
[AS_LITERAL_IF([$3], [],
[AC_FATAL([$0: requires literal arguments])])dnl
AC_CACHE_CHECK([size of $2], AS_TR_SH([glib_cv_sizeof_$3]),
[ # The cast to unsigned long works around a bug in the HP C Compiler
# version HP92453-01 B.11.11.23709.GP, which incorrectly rejects
# declarations like `int a3[[(sizeof (unsigned char)) >= 0]];'.
# This bug is HP SR number 8606223364.
_AC_COMPUTE_INT([(long) (sizeof ($2))],
[AS_TR_SH([glib_cv_sizeof_$3])],
[AC_INCLUDES_DEFAULT([$1])],
[AC_MSG_ERROR([cannot compute sizeof ($2), 77])])
])dnl
AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_sizeof_$3), $AS_TR_SH([glib_cv_sizeof_$3]),
[The size of $3, as computed by sizeof.])
])# GLIB_SIZEOF
dnl GLIB_BYTE_CONTENTS (INCLUDES, TYPE, ALIAS, N_BYTES, INITIALIZER)
AC_DEFUN([GLIB_BYTE_CONTENTS],
[pushdef([glib_ByteContents], GLIB_TR_SH([glib_cv_byte_contents_$3]))dnl
AC_CACHE_CHECK([byte contents of $5], glib_ByteContents,
[AC_TRY_RUN([#include <stdio.h>
$1
main()
{
static $2 tv = $5;
char *p = (char*) &tv;
int i;
FILE *f=fopen("conftestval", "w");
if (!f) exit(1);
for (i = 0; i < $4; i++)
fprintf(f, "%s%d", i?",":"", *(p++));
fprintf(f, "\n");
exit(0);
}],
[glib_ByteContents=`cat conftestval` dnl''
],
[glib_ByteContents=no],
[glib_ByteContents=no])])
AC_DEFINE_UNQUOTED(GLIB_TR_CPP(glib_byte_contents_$3), [$[]glib_ByteContents],
[Byte contents of $3])
popdef([glib_ByteContents])dnl
])
# GLIB_CHECK_VALUE(SYMBOL, INCLUDES, ACTION-IF-FAIL)
# ---------------------------------------------------------------
AC_DEFUN([GLIB_CHECK_VALUE],
[AC_CACHE_CHECK([value of $1], AS_TR_SH([glib_cv_value_$1]),
[_AC_COMPUTE_INT([$1], AS_TR_SH([glib_cv_value_$1]), [$2], [$3])])
])dnl
# GLIB_CHECK_COMPILE_WARNINGS(PROGRAM, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
# ---------------------------------------------------------------------
# Try to compile PROGRAM, check for warnings
m4_define([GLIB_CHECK_COMPILE_WARNINGS],
[m4_ifvaln([$1], [AC_LANG_CONFTEST([$1])])dnl
rm -f conftest.$ac_objext
glib_ac_compile_save="$ac_compile"
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext'
AS_IF([_AC_EVAL_STDERR($ac_compile) &&
AC_TRY_COMMAND([(if test -s conftest.err; then false ; else true; fi)])],
[$2],
[echo "$as_me: failed program was:" >&AS_MESSAGE_LOG_FD
cat conftest.$ac_ext >&AS_MESSAGE_LOG_FD
m4_ifvaln([$3],[$3])dnl])
ac_compile="$glib_ac_compile_save"
rm -f conftest.$ac_objext conftest.err m4_ifval([$1], [conftest.$ac_ext])[]dnl
])# GLIB_CHECK_COMPILE_WARNINGS
# GLIB_ASSERT_SET(VARIABLE)
# -------------------------
AC_DEFUN([GLIB_ASSERT_SET],
[if test "x${$1+set}" != "xset" ; then
AC_MSG_ERROR($1 [must be set in cache file when cross-compiling.])
fi
])dnl

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,9 @@ NULL =
lib_LTLIBRARIES = libcogl-gles2.la
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir)
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_builddir)/deps/glib
AM_CFLAGS = $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS) $(MAINTAINER_CFLAGS)

View File

@ -18,6 +18,7 @@ lib_LTLIBRARIES =
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir) \
-I$(top_builddir)/deps/glib \
-I$(srcdir)/tesselator \
-I$(srcdir)/winsys \
-I$(srcdir)/driver/gl \
@ -515,6 +516,10 @@ libcogl_la_LIBADD = -lm $(COGL_DEP_LIBS) $(COGL_EXTRA_LDFLAGS)
if SUPPORT_GLX
libcogl_la_LIBADD += -ldl
endif
if !USE_GLIB
libcogl_la_LIBADD += $(top_builddir)/deps/glib/libglib.la
libcogl_la_LIBADD += $(top_builddir)/deps/gmodule/libgmodule.la
endif
# XXX: The aim is to eventually get rid of all private API exports
# for cogl-pango.
libcogl_la_LDFLAGS = \

View File

@ -147,6 +147,7 @@ dnl Compiler stuff.
dnl ================================================================
AC_PROG_CC
AC_PROG_CPP
AC_PROG_CXX
AM_PROG_CC_C_O
AC_ISC_POSIX
AC_C_CONST
@ -392,25 +393,6 @@ AS_IF(
]
)
dnl ============================================================
dnl Should cogl-pango be built?
dnl ============================================================
AC_ARG_ENABLE(
[cogl-pango],
[AC_HELP_STRING([--enable-cogl-pango=@<:@no/yes@:>@], [Enable pango support @<:@default=yes@:>@])],
[],
enable_cogl_pango=yes
)
AM_CONDITIONAL([BUILD_COGL_PANGO], [test "x$enable_cogl_pango" = "xyes"])
AS_IF([test "x$enable_cogl_pango" = "xyes"],
[
COGL_PANGO_PKG_REQUIRES="$COGL_PANGO_PKG_REQUIRES pangocairo >= pangocairo_req_version"
]
)
dnl ============================================================
dnl Should examples be installed?
dnl ============================================================
@ -422,27 +404,6 @@ AC_ARG_ENABLE(
)
AM_CONDITIONAL([INSTALL_EXAMPLES], [test "x$enable_examples_install" = "xyes"])
dnl ============================================================
dnl Should glib be used?
dnl ============================================================
AC_ARG_ENABLE(
[glib],
[AC_HELP_STRING([--enable-glib=@<:@no/yes@:>@], [Enable glib support @<:@default=yes@:>@])],
[],
enable_glib=yes
)
AM_CONDITIONAL([USE_GLIB], [test "x$enable_glib" = "xyes"])
AS_IF([test "x$enable_glib" = "xyes"],
[
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_GLIB_SUPPORT"
],
[
EXPERIMENTAL_CONFIG=yes
EXPERIMENTAL_OPTIONS="$EXPERIMENTAL_OPTIONS --disable-glib,"
]
)
dnl ============================================================
dnl Determine which drivers and window systems we can support
dnl ============================================================
@ -1039,20 +1000,6 @@ AM_CONDITIONAL(X11_TESTS, [test "x$SUPPORT_X11" = "xyes"])
AM_CONDITIONAL(SUPPORT_X11, [test "x$SUPPORT_X11" = "xyes"])
AM_CONDITIONAL(SUPPORT_XLIB, [test "x$SUPPORT_XLIB" = "xyes"])
dnl ================================================================
dnl I18n stuff.
dnl ================================================================
AM_GNU_GETTEXT_VERSION([0.17])
AM_GNU_GETTEXT([external])
GETTEXT_PACKAGE="cogl"
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,
"$GETTEXT_PACKAGE",
[The prefix for our gettext translation domains.])
AS_ALL_LINGUAS
dnl ================================================================
dnl Documentation stuff.
dnl ================================================================
@ -1068,14 +1015,79 @@ dnl Check for dependency packages.
dnl ================================================================
dnl ============================================================
dnl Check glib dependencies
dnl Should glib be used?
dnl ============================================================
AM_PATH_GLIB_2_0([glib_req_version],
[have_glib=yes], [have_glib=no],
[gobject gthread gmodule-no-export])
AS_IF([test "x$have_glib" = "xno"], AC_MSG_ERROR([gobject-2.0 is required]))
AC_ARG_ENABLE(
[glib],
[AC_HELP_STRING([--enable-glib=@<:@no/yes@:>@], [Enable glib support @<:@default=yes@:>@])],
[],
enable_glib=yes
)
AS_IF([test "x$have_glib" = "xno" && test "x$enable_glib" = "xyes"],
[AC_MSG_ERROR([gobject-2.0 is required])])
AM_CONDITIONAL([USE_GLIB], [test "x$enable_glib" = "xyes"])
AS_IF([test "x$enable_glib" = "xyes"],
[
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_GLIB_SUPPORT"
COGL_DEFINES_SYMBOLS="$COGL_DEFINES_SYMBOLS COGL_HAS_GTYPE_SUPPORT"
COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES gobject-2.0 gmodule-no-export-2.0"
],
[
AS_GLIBCONFIG([deps/glib])
COGL_EXTRA_CFLAGS="$COGL_EXTRA_CFLAGS -I\$(top_srcdir)/deps"
COGL_EXTRA_CFLAGS="$COGL_EXTRA_CFLAGS -I\$(top_srcdir)/deps/glib"
COGL_EXTRA_CFLAGS="$COGL_EXTRA_CFLAGS -I\$(top_srcdir)/deps/gmodule"
EXPERIMENTAL_CONFIG=yes
EXPERIMENTAL_OPTIONS="$EXPERIMENTAL_OPTIONS --disable-glib,"
enable_nls=no
]
)
dnl ============================================================
dnl Should cogl-pango be built?
dnl ============================================================
AS_IF([test "x$enable_glib" != "xyes"],
[
AS_IF([test "x$enable_cogl_pango" = "xyes"],
AC_MSG_ERROR([--enable-cogl-pango conflicts with --disable-glib]))
enable_cogl_pango=no
]
)
AC_ARG_ENABLE(
[cogl-pango],
[AC_HELP_STRING([--enable-cogl-pango=@<:@no/yes@:>@], [Enable pango support @<:@default=yes@:>@])],
[],
enable_cogl_pango=yes
)
AS_IF([test "x$enable_cogl_pango" = "xyes"],
[
COGL_PANGO_PKG_REQUIRES="$COGL_PANGO_PKG_REQUIRES pangocairo >= pangocairo_req_version"
]
)
dnl ================================================================
dnl I18n stuff.
dnl ================================================================
AM_GNU_GETTEXT_VERSION([0.17])
AM_GNU_GETTEXT([external])
GETTEXT_PACKAGE="cogl"
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,
"$GETTEXT_PACKAGE",
[The prefix for our gettext translation domains.])
AS_ALL_LINGUAS
COGL_PKG_REQUIRES="$COGL_PKG_REQUIRES gobject-2.0 gmodule-no-export-2.0"
AC_SUBST(COGL_PKG_REQUIRES)
PKG_CHECK_MODULES(COGL_DEP, [$COGL_PKG_REQUIRES])
if test -n "$COGL_PKG_REQUIRES_GL"; then
@ -1099,6 +1111,8 @@ AC_SUBST(COGL_PANGO_PKG_REQUIRES)
AS_IF([test "x$enable_cogl_pango" = "xyes"],
[PKG_CHECK_MODULES(COGL_PANGO_DEP, [$COGL_PANGO_PKG_REQUIRES])]
)
AM_CONDITIONAL([BUILD_COGL_PANGO], [test "x$enable_cogl_pango" = "xyes"])
dnl ================================================================
dnl Misc program dependencies.
@ -1108,7 +1122,15 @@ AC_PROG_INSTALL
dnl ================================================================
dnl GObject-Introspection check
dnl ================================================================
GOBJECT_INTROSPECTION_CHECK([gi_req_version])
AS_IF([test "x$enable_glib" = "xyes"],
[
GOBJECT_INTROSPECTION_CHECK([gi_req_version])
],
[
enable_introspection="no"
AM_CONDITIONAL([HAVE_INTROSPECTION], 0)
]
)
dnl ================================================================
dnl Checks for header files.
@ -1214,6 +1236,10 @@ build/Makefile
build/win32/Makefile
build/win32/vs9/Makefile
build/win32/vs10/Makefile
deps/Makefile
deps/glib/Makefile
deps/gmodule/Makefile
deps/gmodule/gmoduleconf.h
cogl/Makefile
cogl/cogl-1.0.pc
cogl/cogl-2.0-experimental.pc

5
deps/Makefile.am vendored Normal file
View File

@ -0,0 +1,5 @@
SUBDIRS =
if !USE_GLIB
SUBDIRS += glib gmodule
endif

76
deps/glib/Makefile.am vendored Normal file
View File

@ -0,0 +1,76 @@
noinst_LTLIBRARIES = libglib.la
libglib_la_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/deps \
-Wall \
$(NULL)
libglib_la_SOURCES = \
galloca.h \
garray.c \
garray.h \
gatomic.c \
gatomic.h \
gbacktrace.h \
gbitlock.c \
gbitlock.h \
gconvert.c \
gconvert.h \
gdatasetprivate.h \
gdataset.c \
gdataset.h \
gdebug.h \
gerror.c \
gerror.h \
gfileutils.c \
gfileutils.h \
ghash.c \
ghash.h \
ghook.c \
ghook.h \
gi18n-lib.h \
glibconfig.h \
glibintl.h \
glib.h \
glib-object.h \
glib_trace.h \
glist.c \
glist.h \
gmacros.h \
gmain.c \
gmain.h \
gmem.c \
gmem.h \
gmessages.c \
gmessages.h \
gprintf.c \
gprintf.h \
gprintfint.h \
gqsort.c \
gqsort.h \
gquark.h \
gqueue.c \
gqueue.h \
gslice.c \
gslice.h \
gslist.c \
gslist.h \
gstdio.c \
gstdio.h \
gstrfuncs.c \
gstrfuncs.h \
gstring.c \
gstring.h \
gtestutils.c \
gtestutils.h \
gthread.c \
gthread.h \
gtypes.h \
gunicode.h \
gutils.c \
gutils.h \
$(NULL)
EXTRA_DIST = README

14
deps/glib/README vendored Normal file
View File

@ -0,0 +1,14 @@
These are files striped from glib 2.30.2 to build a standalone cogl. A few
changes were done on those imported files:
- the needed functions in gconvert.[ch] have been stubbed (don't want any of the
charset conversions in error messages in standalone mode,
- gmain.c has been stipped to only have the one used function
(g_get_current_time()),
- gtestutils.c has also being stripped down to what cogl uses to reduce what it
pulls in,
- gmessage.c has seen the charset conversions and invalid unicode caracters
escaping stripped.
- charset conversion in error messages has been removed in gstrfuncs.c
- g_string_append_uri_escaped() has been removed from gstrinc.c
- remove g_get_codeset() from gutils.c

110
deps/glib/galloca.h vendored Normal file
View File

@ -0,0 +1,110 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_ALLOCA_H__
#define __G_ALLOCA_H__
#include <glib/gtypes.h>
#ifdef __GNUC__
/* GCC does the right thing */
# undef alloca
# define alloca(size) __builtin_alloca (size)
#elif defined (GLIB_HAVE_ALLOCA_H)
/* a native and working alloca.h is there */
# include <alloca.h>
#else /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
# if defined(_MSC_VER) || defined(__DMC__)
# include <malloc.h>
# define alloca _alloca
# else /* !_MSC_VER && !__DMC__ */
# ifdef _AIX
# pragma alloca
# else /* !_AIX */
# ifndef alloca /* predefined by HP cc +Olibcalls */
G_BEGIN_DECLS
char *alloca ();
G_END_DECLS
# endif /* !alloca */
# endif /* !_AIX */
# endif /* !_MSC_VER && !__DMC__ */
#endif /* !__GNUC__ && !GLIB_HAVE_ALLOCA_H */
/**
* g_alloca:
* @size: number of bytes to allocate.
*
* Allocates @size bytes on the stack; these bytes will be freed when the current
* stack frame is cleaned up. This macro essentially just wraps the alloca()
* function present on most UNIX variants.
* Thus it provides the same advantages and pitfalls as alloca():
* <variablelist>
* <varlistentry><term></term><listitem><para>
* + alloca() is very fast, as on most systems it's implemented by just adjusting
* the stack pointer register.
* </para></listitem></varlistentry>
* <varlistentry><term></term><listitem><para>
* + It doesn't cause any memory fragmentation, within its scope, separate alloca()
* blocks just build up and are released together at function end.
* </para></listitem></varlistentry>
* <varlistentry><term></term><listitem><para>
* - Allocation sizes have to fit into the current stack frame. For instance in a
* threaded environment on Linux, the per-thread stack size is limited to 2 Megabytes,
* so be sparse with alloca() uses.
* </para></listitem></varlistentry>
* <varlistentry><term></term><listitem><para>
* - Allocation failure due to insufficient stack space is not indicated with a %NULL
* return like e.g. with malloc(). Instead, most systems probably handle it the same
* way as out of stack space situations from infinite function recursion, i.e.
* with a segmentation fault.
* </para></listitem></varlistentry>
* <varlistentry><term></term><listitem><para>
* - Special care has to be taken when mixing alloca() with GNU C variable sized arrays.
* Stack space allocated with alloca() in the same scope as a variable sized array
* will be freed together with the variable sized array upon exit of that scope, and
* not upon exit of the enclosing function scope.
* </para></listitem></varlistentry>
* </variablelist>
*
* Returns: space for @size bytes, allocated on the stack
*/
#define g_alloca(size) alloca (size)
/**
* g_newa:
* @struct_type: Type of memory chunks to be allocated
* @n_structs: Number of chunks to be allocated
*
* Wraps g_alloca() in a more typesafe manner.
*
* Returns: Pointer to stack space for @n_structs chunks of type @struct_type
*/
#define g_newa(struct_type, n_structs) ((struct_type*) g_alloca (sizeof (struct_type) * (gsize) (n_structs)))
#endif /* __G_ALLOCA_H__ */

1624
deps/glib/garray.c vendored Normal file

File diff suppressed because it is too large Load Diff

181
deps/glib/garray.h vendored Normal file
View File

@ -0,0 +1,181 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_ARRAY_H__
#define __G_ARRAY_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
typedef struct _GArray GArray;
typedef struct _GByteArray GByteArray;
typedef struct _GPtrArray GPtrArray;
struct _GArray
{
gchar *data;
guint len;
};
struct _GByteArray
{
guint8 *data;
guint len;
};
struct _GPtrArray
{
gpointer *pdata;
guint len;
};
/* Resizable arrays. remove fills any cleared spot and shortens the
* array, while preserving the order. remove_fast will distort the
* order by moving the last element to the position of the removed.
*/
#define g_array_append_val(a,v) g_array_append_vals (a, &(v), 1)
#define g_array_prepend_val(a,v) g_array_prepend_vals (a, &(v), 1)
#define g_array_insert_val(a,i,v) g_array_insert_vals (a, i, &(v), 1)
#define g_array_index(a,t,i) (((t*) (void *) (a)->data) [(i)])
GArray* g_array_new (gboolean zero_terminated,
gboolean clear_,
guint element_size);
GArray* g_array_sized_new (gboolean zero_terminated,
gboolean clear_,
guint element_size,
guint reserved_size);
gchar* g_array_free (GArray *array,
gboolean free_segment);
GArray *g_array_ref (GArray *array);
void g_array_unref (GArray *array);
guint g_array_get_element_size (GArray *array);
GArray* g_array_append_vals (GArray *array,
gconstpointer data,
guint len);
GArray* g_array_prepend_vals (GArray *array,
gconstpointer data,
guint len);
GArray* g_array_insert_vals (GArray *array,
guint index_,
gconstpointer data,
guint len);
GArray* g_array_set_size (GArray *array,
guint length);
GArray* g_array_remove_index (GArray *array,
guint index_);
GArray* g_array_remove_index_fast (GArray *array,
guint index_);
GArray* g_array_remove_range (GArray *array,
guint index_,
guint length);
void g_array_sort (GArray *array,
GCompareFunc compare_func);
void g_array_sort_with_data (GArray *array,
GCompareDataFunc compare_func,
gpointer user_data);
/* Resizable pointer array. This interface is much less complicated
* than the above. Add appends a pointer. Remove fills any cleared
* spot and shortens the array. remove_fast will again distort order.
*/
#define g_ptr_array_index(array,index_) ((array)->pdata)[index_]
GPtrArray* g_ptr_array_new (void);
GPtrArray* g_ptr_array_new_with_free_func (GDestroyNotify element_free_func);
GPtrArray* g_ptr_array_sized_new (guint reserved_size);
GPtrArray* g_ptr_array_new_full (guint reserved_size,
GDestroyNotify element_free_func);
gpointer* g_ptr_array_free (GPtrArray *array,
gboolean free_seg);
GPtrArray* g_ptr_array_ref (GPtrArray *array);
void g_ptr_array_unref (GPtrArray *array);
void g_ptr_array_set_free_func (GPtrArray *array,
GDestroyNotify element_free_func);
void g_ptr_array_set_size (GPtrArray *array,
gint length);
gpointer g_ptr_array_remove_index (GPtrArray *array,
guint index_);
gpointer g_ptr_array_remove_index_fast (GPtrArray *array,
guint index_);
gboolean g_ptr_array_remove (GPtrArray *array,
gpointer data);
gboolean g_ptr_array_remove_fast (GPtrArray *array,
gpointer data);
void g_ptr_array_remove_range (GPtrArray *array,
guint index_,
guint length);
void g_ptr_array_add (GPtrArray *array,
gpointer data);
void g_ptr_array_sort (GPtrArray *array,
GCompareFunc compare_func);
void g_ptr_array_sort_with_data (GPtrArray *array,
GCompareDataFunc compare_func,
gpointer user_data);
void g_ptr_array_foreach (GPtrArray *array,
GFunc func,
gpointer user_data);
/* Byte arrays, an array of guint8. Implemented as a GArray,
* but type-safe.
*/
GByteArray* g_byte_array_new (void);
GByteArray* g_byte_array_sized_new (guint reserved_size);
guint8* g_byte_array_free (GByteArray *array,
gboolean free_segment);
GByteArray *g_byte_array_ref (GByteArray *array);
void g_byte_array_unref (GByteArray *array);
GByteArray* g_byte_array_append (GByteArray *array,
const guint8 *data,
guint len);
GByteArray* g_byte_array_prepend (GByteArray *array,
const guint8 *data,
guint len);
GByteArray* g_byte_array_set_size (GByteArray *array,
guint length);
GByteArray* g_byte_array_remove_index (GByteArray *array,
guint index_);
GByteArray* g_byte_array_remove_index_fast (GByteArray *array,
guint index_);
GByteArray* g_byte_array_remove_range (GByteArray *array,
guint index_,
guint length);
void g_byte_array_sort (GByteArray *array,
GCompareFunc compare_func);
void g_byte_array_sort_with_data (GByteArray *array,
GCompareDataFunc compare_func,
gpointer user_data);
G_END_DECLS
#endif /* __G_ARRAY_H__ */

848
deps/glib/gatomic.c vendored Normal file
View File

@ -0,0 +1,848 @@
/*
* Copyright © 2011 Ryan Lortie
*
* 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
* licence, 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.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#include "config.h"
#include "gatomic.h"
/**
* SECTION:atomic_operations
* @title: Atomic Operations
* @short_description: basic atomic integer and pointer operations
* @see_also: #GMutex
*
* The following is a collection of compiler macros to provide atomic
* access to integer and pointer-sized values.
*
* The macros that have 'int' in the name will operate on pointers to
* #gint and #guint. The macros with 'pointer' in the name will operate
* on pointers to any pointer-sized value, including #gsize. There is
* no support for 64bit operations on platforms with 32bit pointers
* because it is not generally possible to perform these operations
* atomically.
*
* The get, set and exchange operations for integers and pointers
* nominally operate on #gint and #gpointer, respectively. Of the
* arithmetic operations, the 'add' operation operates on (and returns)
* signed integer values (#gint and #gssize) and the 'and', 'or', and
* 'xor' operations operate on (and return) unsigned integer values
* (#guint and #gsize).
*
* All of the operations act as a full compiler and (where appropriate)
* hardware memory barrier. Acquire and release or producer and
* consumer barrier semantics are not available through this API.
*
* On GCC, these macros are implemented using GCC intrinsic operations.
* On non-GCC compilers they will evaluate to function calls to
* functions implemented by GLib.
*
* If GLib itself was compiled with GCC then these functions will again
* be implemented by the GCC intrinsics. On Windows without GCC, the
* interlocked API is used to implement the functions.
*
* With non-GCC compilers on non-Windows systems, the functions are
* currently incapable of implementing true atomic operations --
* instead, they fallback to holding a global lock while performing the
* operation. This provides atomicity between the threads of one
* process, but not between separate processes. For this reason, one
* should exercise caution when attempting to use these options on
* shared memory regions.
*
* It is very important that all accesses to a particular integer or
* pointer be performed using only this API and that different sizes of
* operation are not mixed or used on overlapping memory regions. Never
* read or assign directly from or to a value -- always use this API.
*
* For simple reference counting purposes you should use
* g_atomic_int_inc() and g_atomic_int_dec_and_test(). Other uses that
* fall outside of simple reference counting patterns are prone to
* subtle bugs and occasionally undefined behaviour. It is also worth
* noting that since all of these operations require global
* synchronisation of the entire machine, they can be quite slow. In
* the case of performing multiple atomic operations it can often be
* faster to simply acquire a mutex lock around the critical area,
* perform the operations normally and then release the lock.
**/
#ifdef G_ATOMIC_OP_USE_GCC_BUILTINS
#ifndef __GNUC__
#error Using GCC builtin atomic ops, but not compiling with GCC?
#endif
/**
* g_atomic_int_get:
* @atomic: a pointer to a #gint or #guint
*
* Gets the current value of @atomic.
*
* This call acts as a full compiler and hardware
* memory barrier (before the get).
*
* Returns: the value of the integer
*
* Since: 2.4
**/
gint
(g_atomic_int_get) (volatile gint *atomic)
{
return g_atomic_int_get (atomic);
}
/**
* g_atomic_int_set:
* @atomic: a pointer to a #gint or #guint
* @newval: a new value to store
*
* Sets the value of @atomic to @newval.
*
* This call acts as a full compiler and hardware
* memory barrier (after the set).
*
* Since: 2.4
*/
void
(g_atomic_int_set) (volatile gint *atomic,
gint newval)
{
g_atomic_int_set (atomic, newval);
}
/**
* g_atomic_int_inc:
* @atomic: a pointer to a #gint or #guint
*
* Increments the value of @atomic by 1.
*
* Think of this operation as an atomic version of
* <literal>{ *@atomic += 1; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Since: 2.4
**/
void
(g_atomic_int_inc) (volatile gint *atomic)
{
g_atomic_int_inc (atomic);
}
/**
* g_atomic_int_dec_and_test:
* @atomic: a pointer to a #gint or #guint
*
* Decrements the value of @atomic by 1.
*
* Think of this operation as an atomic version of
* <literal>{ *@atomic -= 1; return (*@atomic == 0); }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: %TRUE if the resultant value is zero
*
* Since: 2.4
**/
gboolean
(g_atomic_int_dec_and_test) (volatile gint *atomic)
{
return g_atomic_int_dec_and_test (atomic);
}
/**
* g_atomic_int_compare_and_exchange:
* @atomic: a pointer to a #gint or #guint
* @oldval: the value to compare with
* @newval: the value to conditionally replace with
*
* Compares @atomic to @oldval and, if equal, sets it to @newval.
* If @atomic was not equal to @oldval then no change occurs.
*
* This compare and exchange is done atomically.
*
* Think of this operation as an atomic version of
* <literal>{ if (*@atomic == @oldval) { *@atomic = @newval; return TRUE; } else return FALSE; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: %TRUE if the exchange took place
*
* Since: 2.4
**/
gboolean
(g_atomic_int_compare_and_exchange) (volatile gint *atomic,
gint oldval,
gint newval)
{
return g_atomic_int_compare_and_exchange (atomic, oldval, newval);
}
/**
* g_atomic_int_add:
* @atomic: a pointer to a #gint or #guint
* @val: the value to add
*
* Atomically adds @val to the value of @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic += @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Before version 2.30, this function did not return a value
* (but g_atomic_int_exchange_and_add() did, and had the same meaning).
*
* Returns: the value of @atomic before the add, signed
*
* Since: 2.4
**/
gint
(g_atomic_int_add) (volatile gint *atomic,
gint val)
{
return g_atomic_int_add (atomic, val);
}
/**
* g_atomic_int_and:
* @atomic: a pointer to a #gint or #guint
* @val: the value to 'and'
*
* Performs an atomic bitwise 'and' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* This call acts as a full compiler and hardware memory barrier.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic &= @val; return tmp; }</literal>
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
guint
(g_atomic_int_and) (volatile guint *atomic,
guint val)
{
return g_atomic_int_and (atomic, val);
}
/**
* g_atomic_int_or:
* @atomic: a pointer to a #gint or #guint
* @val: the value to 'or'
*
* Performs an atomic bitwise 'or' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic |= @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
guint
(g_atomic_int_or) (volatile guint *atomic,
guint val)
{
return g_atomic_int_or (atomic, val);
}
/**
* g_atomic_int_xor:
* @atomic: a pointer to a #gint or #guint
* @val: the value to 'xor'
*
* Performs an atomic bitwise 'xor' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic ^= @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
guint
(g_atomic_int_xor) (volatile guint *atomic,
guint val)
{
return g_atomic_int_xor (atomic, val);
}
/**
* g_atomic_pointer_get:
* @atomic: a pointer to a #gpointer-sized value
*
* Gets the current value of @atomic.
*
* This call acts as a full compiler and hardware
* memory barrier (before the get).
*
* Returns: the value of the pointer
*
* Since: 2.4
**/
gpointer
(g_atomic_pointer_get) (volatile void *atomic)
{
return g_atomic_pointer_get ((volatile gpointer *) atomic);
}
/**
* g_atomic_pointer_set:
* @atomic: a pointer to a #gpointer-sized value
* @newval: a new value to store
*
* Sets the value of @atomic to @newval.
*
* This call acts as a full compiler and hardware
* memory barrier (after the set).
*
* Since: 2.4
**/
void
(g_atomic_pointer_set) (volatile void *atomic,
gpointer newval)
{
g_atomic_pointer_set ((volatile gpointer *) atomic, newval);
}
/**
* g_atomic_pointer_compare_and_exchange:
* @atomic: a pointer to a #gpointer-sized value
* @oldval: the value to compare with
* @newval: the value to conditionally replace with
*
* Compares @atomic to @oldval and, if equal, sets it to @newval.
* If @atomic was not equal to @oldval then no change occurs.
*
* This compare and exchange is done atomically.
*
* Think of this operation as an atomic version of
* <literal>{ if (*@atomic == @oldval) { *@atomic = @newval; return TRUE; } else return FALSE; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: %TRUE if the exchange took place
*
* Since: 2.4
**/
gboolean
(g_atomic_pointer_compare_and_exchange) (volatile void *atomic,
gpointer oldval,
gpointer newval)
{
return g_atomic_pointer_compare_and_exchange ((volatile gpointer *) atomic,
oldval, newval);
}
/**
* g_atomic_pointer_add:
* @atomic: a pointer to a #gpointer-sized value
* @val: the value to add
*
* Atomically adds @val to the value of @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic += @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the add, signed
*
* Since: 2.30
**/
gssize
(g_atomic_pointer_add) (volatile void *atomic,
gssize val)
{
return g_atomic_pointer_add ((volatile gpointer *) atomic, val);
}
/**
* g_atomic_pointer_and:
* @atomic: a pointer to a #gpointer-sized value
* @val: the value to 'and'
*
* Performs an atomic bitwise 'and' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic &= @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
gsize
(g_atomic_pointer_and) (volatile void *atomic,
gsize val)
{
return g_atomic_pointer_and ((volatile gpointer *) atomic, val);
}
/**
* g_atomic_pointer_or:
* @atomic: a pointer to a #gpointer-sized value
* @val: the value to 'or'
*
* Performs an atomic bitwise 'or' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic |= @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
gsize
(g_atomic_pointer_or) (volatile void *atomic,
gsize val)
{
return g_atomic_pointer_or ((volatile gpointer *) atomic, val);
}
/**
* g_atomic_pointer_xor:
* @atomic: a pointer to a #gpointer-sized value
* @val: the value to 'xor'
*
* Performs an atomic bitwise 'xor' of the value of @atomic and @val,
* storing the result back in @atomic.
*
* Think of this operation as an atomic version of
* <literal>{ tmp = *atomic; *@atomic ^= @val; return tmp; }</literal>
*
* This call acts as a full compiler and hardware memory barrier.
*
* Returns: the value of @atomic before the operation, unsigned
*
* Since: 2.30
**/
gsize
(g_atomic_pointer_xor) (volatile void *atomic,
gsize val)
{
return g_atomic_pointer_xor ((volatile gpointer *) atomic, val);
}
#elif defined (G_PLATFORM_WIN32) && defined(HAVE_WIN32_BUILTINS_FOR_ATOMIC_OPERATIONS)
#include <windows.h>
#if !defined(_M_AMD64) && !defined (_M_IA64) && !defined(_M_X64)
#define InterlockedAnd _InterlockedAnd
#define InterlockedOr _InterlockedOr
#define InterlockedXor _InterlockedXor
#endif
/*
* http://msdn.microsoft.com/en-us/library/ms684122(v=vs.85).aspx
*/
gint
(g_atomic_int_get) (volatile gint *atomic)
{
MemoryBarrier ();
return *atomic;
}
void
(g_atomic_int_set) (volatile gint *atomic,
gint newval)
{
*atomic = newval;
MemoryBarrier ();
}
void
(g_atomic_int_inc) (volatile gint *atomic)
{
InterlockedIncrement (atomic);
}
gboolean
(g_atomic_int_dec_and_test) (volatile gint *atomic)
{
return InterlockedDecrement (atomic) == 0;
}
gboolean
(g_atomic_int_compare_and_exchange) (volatile gint *atomic,
gint oldval,
gint newval)
{
return InterlockedCompareExchange (atomic, newval, oldval) == oldval;
}
gint
(g_atomic_int_add) (volatile gint *atomic,
gint val)
{
return InterlockedExchangeAdd (atomic, val);
}
guint
(g_atomic_int_and) (volatile guint *atomic,
guint val)
{
return InterlockedAnd (atomic, val);
}
guint
(g_atomic_int_or) (volatile guint *atomic,
guint val)
{
return InterlockedOr (atomic, val);
}
guint
(g_atomic_int_xor) (volatile guint *atomic,
guint val)
{
return InterlockedXor (atomic, val);
}
gpointer
(g_atomic_pointer_get) (volatile void *atomic)
{
volatile gpointer *ptr = atomic;
MemoryBarrier ();
return *ptr;
}
void
(g_atomic_pointer_set) (volatile void *atomic,
gpointer newval)
{
volatile gpointer *ptr = atomic;
*ptr = newval;
MemoryBarrier ();
}
gboolean
(g_atomic_pointer_compare_and_exchange) (volatile void *atomic,
gpointer oldval,
gpointer newval)
{
return InterlockedCompareExchangePointer (atomic, newval, oldval) == oldval;
}
gssize
(g_atomic_pointer_add) (volatile void *atomic,
gssize val)
{
#if GLIB_SIZEOF_VOID_P == 8
return InterlockedExchangeAdd64 (atomic, val);
#else
return InterlockedExchangeAdd (atomic, val);
#endif
}
gsize
(g_atomic_pointer_and) (volatile void *atomic,
gsize val)
{
#if GLIB_SIZEOF_VOID_P == 8
return InterlockedAnd64 (atomic, val);
#else
return InterlockedAnd (atomic, val);
#endif
}
gsize
(g_atomic_pointer_or) (volatile void *atomic,
gsize val)
{
#if GLIB_SIZEOF_VOID_P == 8
return InterlockedOr64 (atomic, val);
#else
return InterlockedOr (atomic, val);
#endif
}
gsize
(g_atomic_pointer_xor) (volatile void *atomic,
gsize val)
{
#if GLIB_SIZEOF_VOID_P == 8
return InterlockedXor64 (atomic, val);
#else
return InterlockedXor (atomic, val);
#endif
}
#else
#include "gthread.h"
static GStaticMutex g_atomic_lock;
gint
(g_atomic_int_get) (volatile gint *atomic)
{
gint value;
g_static_mutex_lock (&g_atomic_lock);
value = *atomic;
g_static_mutex_unlock (&g_atomic_lock);
return value;
}
void
(g_atomic_int_set) (volatile gint *atomic,
gint value)
{
g_static_mutex_lock (&g_atomic_lock);
*atomic = value;
g_static_mutex_unlock (&g_atomic_lock);
}
void
(g_atomic_int_inc) (volatile gint *atomic)
{
g_static_mutex_lock (&g_atomic_lock);
(*atomic)++;
g_static_mutex_unlock (&g_atomic_lock);
}
gboolean
(g_atomic_int_dec_and_test) (volatile gint *atomic)
{
gboolean is_zero;
g_static_mutex_lock (&g_atomic_lock);
is_zero = --(*atomic) == 0;
g_static_mutex_unlock (&g_atomic_lock);
return is_zero;
}
gboolean
(g_atomic_int_compare_and_exchange) (volatile gint *atomic,
gint oldval,
gint newval)
{
gboolean success;
g_static_mutex_lock (&g_atomic_lock);
if ((success = (*atomic == oldval)))
*atomic = newval;
g_static_mutex_unlock (&g_atomic_lock);
return success;
}
gint
(g_atomic_int_add) (volatile gint *atomic,
gint val)
{
gint oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *atomic;
*atomic = oldval + val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
guint
(g_atomic_int_and) (volatile guint *atomic,
guint val)
{
guint oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *atomic;
*atomic = oldval & val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
guint
(g_atomic_int_or) (volatile guint *atomic,
guint val)
{
guint oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *atomic;
*atomic = oldval | val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
guint
(g_atomic_int_xor) (volatile guint *atomic,
guint val)
{
guint oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *atomic;
*atomic = oldval ^ val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
gpointer
(g_atomic_pointer_get) (volatile void *atomic)
{
volatile gpointer *ptr = atomic;
gpointer value;
g_static_mutex_lock (&g_atomic_lock);
value = *ptr;
g_static_mutex_unlock (&g_atomic_lock);
return value;
}
void
(g_atomic_pointer_set) (volatile void *atomic,
gpointer newval)
{
volatile gpointer *ptr = atomic;
g_static_mutex_lock (&g_atomic_lock);
*ptr = newval;
g_static_mutex_unlock (&g_atomic_lock);
}
gboolean
(g_atomic_pointer_compare_and_exchange) (volatile void *atomic,
gpointer oldval,
gpointer newval)
{
volatile gpointer *ptr = atomic;
gboolean success;
g_static_mutex_lock (&g_atomic_lock);
if ((success = (*ptr == oldval)))
*ptr = newval;
g_static_mutex_unlock (&g_atomic_lock);
return success;
}
gssize
(g_atomic_pointer_add) (volatile void *atomic,
gssize val)
{
volatile gssize *ptr = atomic;
gssize oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *ptr;
*ptr = oldval + val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
gsize
(g_atomic_pointer_and) (volatile void *atomic,
gsize val)
{
volatile gsize *ptr = atomic;
gsize oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *ptr;
*ptr = oldval & val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
gsize
(g_atomic_pointer_or) (volatile void *atomic,
gsize val)
{
volatile gsize *ptr = atomic;
gsize oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *ptr;
*ptr = oldval | val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
gsize
(g_atomic_pointer_xor) (volatile void *atomic,
gsize val)
{
volatile gsize *ptr = atomic;
gsize oldval;
g_static_mutex_lock (&g_atomic_lock);
oldval = *ptr;
*ptr = oldval ^ val;
g_static_mutex_unlock (&g_atomic_lock);
return oldval;
}
#endif
/**
* g_atomic_int_exchange_and_add:
* @atomic: a pointer to a #gint
* @val: the value to add
*
* This function existed before g_atomic_int_add() returned the prior
* value of the integer (which it now does). It is retained only for
* compatibility reasons. Don't use this function in new code.
*
* Returns: the value of @atomic before the add, signed
* Since: 2.4
* Deprecated: 2.30: Use g_atomic_int_add() instead.
**/
gint
g_atomic_int_exchange_and_add (volatile gint *atomic,
gint val)
{
return (g_atomic_int_add) (atomic, val);
}

217
deps/glib/gatomic.h vendored Normal file
View File

@ -0,0 +1,217 @@
/*
* Copyright © 2011 Ryan Lortie
*
* 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
* licence, 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.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_ATOMIC_H__
#define __G_ATOMIC_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
gint g_atomic_int_get (volatile gint *atomic);
void g_atomic_int_set (volatile gint *atomic,
gint newval);
void g_atomic_int_inc (volatile gint *atomic);
gboolean g_atomic_int_dec_and_test (volatile gint *atomic);
gboolean g_atomic_int_compare_and_exchange (volatile gint *atomic,
gint oldval,
gint newval);
gint g_atomic_int_add (volatile gint *atomic,
gint val);
guint g_atomic_int_and (volatile guint *atomic,
guint val);
guint g_atomic_int_or (volatile guint *atomic,
guint val);
guint g_atomic_int_xor (volatile guint *atomic,
guint val);
gpointer g_atomic_pointer_get (volatile void *atomic);
void g_atomic_pointer_set (volatile void *atomic,
gpointer newval);
gboolean g_atomic_pointer_compare_and_exchange (volatile void *atomic,
gpointer oldval,
gpointer newval);
gssize g_atomic_pointer_add (volatile void *atomic,
gssize val);
gsize g_atomic_pointer_and (volatile void *atomic,
gsize val);
gsize g_atomic_pointer_or (volatile void *atomic,
gsize val);
gsize g_atomic_pointer_xor (volatile void *atomic,
gsize val);
#ifndef G_DISABLE_DEPRECATED
gint g_atomic_int_exchange_and_add (volatile gint *atomic,
gint val);
#endif
G_END_DECLS
#if defined(__GNUC__) && defined(G_ATOMIC_OP_USE_GCC_BUILTINS)
#define g_atomic_int_get(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ *(atomic) : 0); \
__sync_synchronize (); \
(gint) *(atomic); \
}))
#define g_atomic_int_set(atomic, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (newval) : 0); \
*(atomic) = (newval); \
__sync_synchronize (); \
}))
#define g_atomic_int_inc(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ *(atomic) : 0); \
(void) __sync_fetch_and_add ((atomic), 1); \
}))
#define g_atomic_int_dec_and_test(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ *(atomic) : 0); \
__sync_fetch_and_sub ((atomic), 1) == 1; \
}))
#define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (newval) ^ (oldval) : 0); \
(gboolean) __sync_bool_compare_and_swap ((atomic), (oldval), (newval)); \
}))
#define g_atomic_int_add(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (val) : 0); \
(gint) __sync_fetch_and_add ((atomic), (val)); \
}))
#define g_atomic_int_and(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (val) : 0); \
(guint) __sync_fetch_and_and ((atomic), (val)); \
}))
#define g_atomic_int_or(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (val) : 0); \
(guint) __sync_fetch_and_or ((atomic), (val)); \
}))
#define g_atomic_int_xor(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gint)); \
(void) (0 ? *(atomic) ^ (val) : 0); \
(guint) __sync_fetch_and_xor ((atomic), (val)); \
}))
#define g_atomic_pointer_get(atomic) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
__sync_synchronize (); \
(gpointer) *(atomic); \
}))
#define g_atomic_pointer_set(atomic, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
*(atomic) = (__typeof__ (*(atomic))) (gsize) (newval); \
__sync_synchronize (); \
}))
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
(gboolean) __sync_bool_compare_and_swap ((atomic), (oldval), (newval)); \
}))
#define g_atomic_pointer_add(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
(void) (0 ? (val) ^ (val) : 0); \
(gssize) __sync_fetch_and_add ((atomic), (val)); \
}))
#define g_atomic_pointer_and(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
(void) (0 ? (val) ^ (val) : 0); \
(gsize) __sync_fetch_and_and ((atomic), (val)); \
}))
#define g_atomic_pointer_or(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
(void) (0 ? (val) ^ (val) : 0); \
(gsize) __sync_fetch_and_or ((atomic), (val)); \
}))
#define g_atomic_pointer_xor(atomic, val) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(atomic) == sizeof (gpointer)); \
(void) (0 ? (gpointer) *(atomic) : 0); \
(void) (0 ? (val) ^ (val) : 0); \
(gsize) __sync_fetch_and_xor ((atomic), (val)); \
}))
#else /* defined(__GNUC__) && defined(G_ATOMIC_OP_USE_GCC_BUILTINS) */
#define g_atomic_int_get(atomic) \
(g_atomic_int_get ((gint *) (atomic)))
#define g_atomic_int_set(atomic, newval) \
(g_atomic_int_set ((gint *) (atomic), (gint) (newval)))
#define g_atomic_int_compare_and_exchange(atomic, oldval, newval) \
(g_atomic_int_compare_and_exchange ((gint *) (atomic), (oldval), (newval)))
#define g_atomic_int_add(atomic, val) \
(g_atomic_int_add ((gint *) (atomic), (val)))
#define g_atomic_int_and(atomic, val) \
(g_atomic_int_and ((gint *) (atomic), (val)))
#define g_atomic_int_or(atomic, val) \
(g_atomic_int_or ((gint *) (atomic), (val)))
#define g_atomic_int_xor(atomic, val) \
(g_atomic_int_xor ((gint *) (atomic), (val)))
#define g_atomic_int_inc(atomic) \
(g_atomic_int_inc ((gint *) (atomic)))
#define g_atomic_int_dec_and_test(atomic) \
(g_atomic_int_dec_and_test ((gint *) (atomic)))
#define g_atomic_pointer_get(atomic) \
(g_atomic_pointer_get (atomic))
#define g_atomic_pointer_set(atomic, newval) \
(g_atomic_pointer_set ((atomic), (gpointer) (newval)))
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
(g_atomic_pointer_compare_and_exchange ((atomic), (gpointer) (oldval), (gpointer) (newval)))
#define g_atomic_pointer_add(atomic, val) \
(g_atomic_pointer_add ((atomic), (gssize) (val)))
#define g_atomic_pointer_and(atomic, val) \
(g_atomic_pointer_and ((atomic), (gsize) (val)))
#define g_atomic_pointer_or(atomic, val) \
(g_atomic_pointer_or ((atomic), (gsize) (val)))
#define g_atomic_pointer_xor(atomic, val) \
(g_atomic_pointer_xor ((atomic), (gsize) (val)))
#endif /* defined(__GNUC__) && defined(G_ATOMIC_OP_USE_GCC_BUILTINS) */
#endif /* __G_ATOMIC_H__ */

61
deps/glib/gbacktrace.h vendored Normal file
View File

@ -0,0 +1,61 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_BACKTRACE_H__
#define __G_BACKTRACE_H__
#include <glib/gtypes.h>
#include <signal.h>
G_BEGIN_DECLS
/**
* G_BREAKPOINT:
*
* Inserts a breakpoint instruction into the code.
*
* On x86 and alpha systems this is implemented as a soft interrupt
* and on other architectures it raises a %SIGTRAP signal.
*/
#if (defined (__i386__) || defined (__x86_64__)) && defined (__GNUC__) && __GNUC__ >= 2
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
#elif (defined (_MSC_VER) || defined (__DMC__)) && defined (_M_IX86)
# define G_BREAKPOINT() G_STMT_START{ __asm int 3h }G_STMT_END
#elif defined (_MSC_VER)
# define G_BREAKPOINT() G_STMT_START{ __debugbreak(); }G_STMT_END
#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
#else /* !__i386__ && !__alpha__ */
# define G_BREAKPOINT() G_STMT_START{ raise (SIGTRAP); }G_STMT_END
#endif /* __i386__ */
G_END_DECLS
#endif /* __G_BACKTRACE_H__ */

535
deps/glib/gbitlock.c vendored Normal file
View File

@ -0,0 +1,535 @@
/*
* Copyright © 2008 Ryan Lortie
* Copyright © 2010 Codethink Limited
*
* 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 licence, 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.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#include "gbitlock.h"
#include <glib/gmessages.h>
#include <glib/gatomic.h>
#include <glib/gslist.h>
#include <glib/gthread.h>
#include "gthreadprivate.h"
#include "config.h"
#ifdef G_BIT_LOCK_FORCE_FUTEX_EMULATION
#undef HAVE_FUTEX
#endif
#ifndef HAVE_FUTEX
static GSList *g_futex_address_list = NULL;
static GMutex *g_futex_mutex = NULL;
#endif
void
_g_futex_thread_init (void) {
#ifndef HAVE_FUTEX
g_futex_mutex = g_mutex_new ();
#endif
}
#ifdef HAVE_FUTEX
/*
* We have headers for futex(2) on the build machine. This does not
* imply that every system that ever runs the resulting glib will have
* kernel support for futex, but you'd have to have a pretty old
* kernel in order for that not to be the case.
*
* If anyone actually gets bit by this, please file a bug. :)
*/
#include <linux/futex.h>
#include <sys/syscall.h>
#include <unistd.h>
/* < private >
* g_futex_wait:
* @address: a pointer to an integer
* @value: the value that should be at @address
*
* Atomically checks that the value stored at @address is equal to
* @value and then blocks. If the value stored at @address is not
* equal to @value then this function returns immediately.
*
* To unblock, call g_futex_wake() on @address.
*
* This call may spuriously unblock (for example, in response to the
* process receiving a signal) but this is not guaranteed. Unlike the
* Linux system call of a similar name, there is no guarantee that a
* waiting process will unblock due to a g_futex_wake() call in a
* separate process.
*/
static void
g_futex_wait (const volatile gint *address,
gint value)
{
syscall (__NR_futex, address, (gsize) FUTEX_WAIT, (gsize) value, NULL);
}
/* < private >
* g_futex_wake:
* @address: a pointer to an integer
*
* Nominally, wakes one thread that is blocked in g_futex_wait() on
* @address (if any thread is currently waiting).
*
* As mentioned in the documention for g_futex_wait(), spurious
* wakeups may occur. As such, this call may result in more than one
* thread being woken up.
*/
static void
g_futex_wake (const volatile gint *address)
{
syscall (__NR_futex, address, (gsize) FUTEX_WAKE, (gsize) 1, NULL);
}
#else
/* emulate futex(2) */
typedef struct
{
const volatile gint *address;
gint ref_count;
GCond *wait_queue;
} WaitAddress;
static WaitAddress *
g_futex_find_address (const volatile gint *address)
{
GSList *node;
for (node = g_futex_address_list; node; node = node->next)
{
WaitAddress *waiter = node->data;
if (waiter->address == address)
return waiter;
}
return NULL;
}
static void
g_futex_wait (const volatile gint *address,
gint value)
{
g_mutex_lock (g_futex_mutex);
if G_LIKELY (g_atomic_int_get (address) == value)
{
WaitAddress *waiter;
if ((waiter = g_futex_find_address (address)) == NULL)
{
waiter = g_slice_new (WaitAddress);
waiter->address = address;
waiter->wait_queue = g_cond_new ();
waiter->ref_count = 0;
g_futex_address_list =
g_slist_prepend (g_futex_address_list, waiter);
}
waiter->ref_count++;
g_cond_wait (waiter->wait_queue, g_futex_mutex);
if (!--waiter->ref_count)
{
g_futex_address_list =
g_slist_remove (g_futex_address_list, waiter);
g_cond_free (waiter->wait_queue);
g_slice_free (WaitAddress, waiter);
}
}
g_mutex_unlock (g_futex_mutex);
}
static void
g_futex_wake (const volatile gint *address)
{
WaitAddress *waiter;
/* need to lock here for two reasons:
* 1) need to acquire/release lock to ensure waiter is not in
* the process of registering a wait
* 2) need to -stay- locked until the end to ensure a wake()
* in another thread doesn't cause 'waiter' to stop existing
*/
g_mutex_lock (g_futex_mutex);
if ((waiter = g_futex_find_address (address)))
g_cond_signal (waiter->wait_queue);
g_mutex_unlock (g_futex_mutex);
}
#endif
#define CONTENTION_CLASSES 11
static volatile gint g_bit_lock_contended[CONTENTION_CLASSES];
#if (defined (i386) || defined (__amd64__))
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define USE_ASM_GOTO 1
#endif
#endif
/**
* g_bit_lock:
* @address: a pointer to an integer
* @lock_bit: a bit value between 0 and 31
*
* Sets the indicated @lock_bit in @address. If the bit is already
* set, this call will block until g_bit_unlock() unsets the
* corresponding bit.
*
* Attempting to lock on two different bits within the same integer is
* not supported and will very probably cause deadlocks.
*
* The value of the bit that is set is (1u << @bit). If @bit is not
* between 0 and 31 then the result is undefined.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Since: 2.24
**/
void
g_bit_lock (volatile gint *address,
gint lock_bit)
{
#ifdef USE_ASM_GOTO
retry:
asm volatile goto ("lock bts %1, (%0)\n"
"jc %l[contended]"
: /* no output */
: "r" (address), "r" (lock_bit)
: "cc", "memory"
: contended);
return;
contended:
{
guint mask = 1u << lock_bit;
guint v;
v = g_atomic_int_get (address);
if (v & mask)
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
g_atomic_int_add (&g_bit_lock_contended[class], +1);
g_futex_wait (address, v);
g_atomic_int_add (&g_bit_lock_contended[class], -1);
}
}
goto retry;
#else
guint mask = 1u << lock_bit;
guint v;
retry:
v = g_atomic_int_or (address, mask);
if (v & mask)
/* already locked */
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
g_atomic_int_add (&g_bit_lock_contended[class], +1);
g_futex_wait (address, v);
g_atomic_int_add (&g_bit_lock_contended[class], -1);
goto retry;
}
#endif
}
/**
* g_bit_trylock:
* @address: a pointer to an integer
* @lock_bit: a bit value between 0 and 31
* @returns: %TRUE if the lock was acquired
*
* Sets the indicated @lock_bit in @address, returning %TRUE if
* successful. If the bit is already set, returns %FALSE immediately.
*
* Attempting to lock on two different bits within the same integer is
* not supported.
*
* The value of the bit that is set is (1u << @bit). If @bit is not
* between 0 and 31 then the result is undefined.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Since: 2.24
**/
gboolean
g_bit_trylock (volatile gint *address,
gint lock_bit)
{
#ifdef USE_ASM_GOTO
gboolean result;
asm volatile ("lock bts %2, (%1)\n"
"setnc %%al\n"
"movzx %%al, %0"
: "=r" (result)
: "r" (address), "r" (lock_bit)
: "cc", "memory");
return result;
#else
guint mask = 1u << lock_bit;
guint v;
v = g_atomic_int_or (address, mask);
return ~v & mask;
#endif
}
/**
* g_bit_unlock:
* @address: a pointer to an integer
* @lock_bit: a bit value between 0 and 31
*
* Clears the indicated @lock_bit in @address. If another thread is
* currently blocked in g_bit_lock() on this same bit then it will be
* woken up.
*
* This function accesses @address atomically. All other accesses to
* @address must be atomic in order for this function to work
* reliably.
*
* Since: 2.24
**/
void
g_bit_unlock (volatile gint *address,
gint lock_bit)
{
#ifdef USE_ASM_GOTO
asm volatile ("lock btr %1, (%0)"
: /* no output */
: "r" (address), "r" (lock_bit)
: "cc", "memory");
#else
guint mask = 1u << lock_bit;
g_atomic_int_and (address, ~mask);
#endif
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
if (g_atomic_int_get (&g_bit_lock_contended[class]))
g_futex_wake (address);
}
}
/* We emulate pointer-sized futex(2) because the kernel API only
* supports integers.
*
* We assume that the 'interesting' part is always the lower order bits.
* This assumption holds because pointer bitlocks are restricted to
* using the low order bits of the pointer as the lock.
*
* On 32 bits, there is nothing to do since the pointer size is equal to
* the integer size. On little endian the lower-order bits don't move,
* so do nothing. Only on 64bit big endian do we need to do a bit of
* pointer arithmetic: the low order bits are shifted by 4 bytes. We
* have a helper function that always does the right thing here.
*
* Since we always consider the low-order bits of the integer value, a
* simple cast from (gsize) to (guint) always takes care of that.
*
* After that, pointer-sized futex becomes as simple as:
*
* g_futex_wait (g_futex_int_address (address), (guint) value);
*
* and
*
* g_futex_wake (g_futex_int_address (int_address));
*/
static const volatile gint *
g_futex_int_address (const volatile void *address)
{
const volatile gint *int_address = address;
#if G_BYTE_ORDER == G_BIG_ENDIAN && GLIB_SIZEOF_VOID_P == 8
int_address++;
#endif
return int_address;
}
/**
* g_pointer_bit_lock:
* @address: a pointer to a #gpointer-sized value
* @lock_bit: a bit value between 0 and 31
*
* This is equivalent to g_bit_lock, but working on pointers (or other
* pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Since: 2.30
**/
void
(g_pointer_bit_lock) (volatile void *address,
gint lock_bit)
{
g_return_if_fail (lock_bit < 32);
{
#ifdef USE_ASM_GOTO
retry:
asm volatile goto ("lock bts %1, (%0)\n"
"jc %l[contended]"
: /* no output */
: "r" (address), "r" ((gsize) lock_bit)
: "cc", "memory"
: contended);
return;
contended:
{
volatile gsize *pointer_address = address;
gsize mask = 1u << lock_bit;
gsize v;
v = (gsize) g_atomic_pointer_get (pointer_address);
if (v & mask)
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
g_atomic_int_add (&g_bit_lock_contended[class], +1);
g_futex_wait (g_futex_int_address (address), v);
g_atomic_int_add (&g_bit_lock_contended[class], -1);
}
}
goto retry;
#else
volatile gsize *pointer_address = address;
gsize mask = 1u << lock_bit;
gsize v;
retry:
v = g_atomic_pointer_or (pointer_address, mask);
if (v & mask)
/* already locked */
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
g_atomic_int_add (&g_bit_lock_contended[class], +1);
g_futex_wait (g_futex_int_address (address), (guint) v);
g_atomic_int_add (&g_bit_lock_contended[class], -1);
goto retry;
}
#endif
}
}
/**
* g_pointer_bit_trylock:
* @address: a pointer to a #gpointer-sized value
* @lock_bit: a bit value between 0 and 31
* @returns: %TRUE if the lock was acquired
*
* This is equivalent to g_bit_trylock, but working on pointers (or
* other pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Since: 2.30
**/
gboolean
(g_pointer_bit_trylock) (volatile void *address,
gint lock_bit)
{
g_return_val_if_fail (lock_bit < 32, FALSE);
{
#ifdef USE_ASM_GOTO
gboolean result;
asm volatile ("lock bts %2, (%1)\n"
"setnc %%al\n"
"movzx %%al, %0"
: "=r" (result)
: "r" (address), "r" ((gsize) lock_bit)
: "cc", "memory");
return result;
#else
volatile gsize *pointer_address = address;
gsize mask = 1u << lock_bit;
gsize v;
g_return_val_if_fail (lock_bit < 32, FALSE);
v = g_atomic_pointer_or (pointer_address, mask);
return ~v & mask;
#endif
}
}
/**
* g_pointer_bit_unlock:
* @address: a pointer to a #gpointer-sized value
* @lock_bit: a bit value between 0 and 31
*
* This is equivalent to g_bit_unlock, but working on pointers (or other
* pointer-sized values).
*
* For portability reasons, you may only lock on the bottom 32 bits of
* the pointer.
*
* Since: 2.30
**/
void
(g_pointer_bit_unlock) (volatile void *address,
gint lock_bit)
{
g_return_if_fail (lock_bit < 32);
{
#ifdef USE_ASM_GOTO
asm volatile ("lock btr %1, (%0)"
: /* no output */
: "r" (address), "r" ((gsize) lock_bit)
: "cc", "memory");
#else
volatile gsize *pointer_address = address;
gsize mask = 1u << lock_bit;
g_atomic_pointer_and (pointer_address, ~mask);
#endif
{
guint class = ((gsize) address) % G_N_ELEMENTS (g_bit_lock_contended);
if (g_atomic_int_get (&g_bit_lock_contended[class]))
g_futex_wake (g_futex_int_address (address));
}
}
}

72
deps/glib/gbitlock.h vendored Normal file
View File

@ -0,0 +1,72 @@
/*
* Copyright © 2008 Ryan Lortie
* Copyright © 2010 Codethink Limited
*
* 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 licence, 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.
*
* Author: Ryan Lortie <desrt@desrt.ca>
*/
#ifndef __G_BITLOCK_H__
#define __G_BITLOCK_H__
#include <glib/gtypes.h>
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
G_BEGIN_DECLS
void g_bit_lock (volatile gint *address,
gint lock_bit);
gboolean g_bit_trylock (volatile gint *address,
gint lock_bit);
void g_bit_unlock (volatile gint *address,
gint lock_bit);
void g_pointer_bit_lock (volatile void *address,
gint lock_bit);
gboolean g_pointer_bit_trylock (volatile void *address,
gint lock_bit);
void g_pointer_bit_unlock (volatile void *address,
gint lock_bit);
#ifdef __GNUC__
#define g_pointer_bit_lock(address, lock_bit) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
g_pointer_bit_lock ((address), (lock_bit)); \
}))
#define g_pointer_bit_trylock(address, lock_bit) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
g_pointer_bit_trylock ((address), (lock_bit)); \
}))
#define g_pointer_bit_unlock(address, lock_bit) \
(G_GNUC_EXTENSION ({ \
G_STATIC_ASSERT (sizeof *(address) == sizeof (gpointer)); \
g_pointer_bit_unlock ((address), (lock_bit)); \
}))
#endif
G_END_DECLS
#endif /* __G_BITLOCK_H_ */

31
deps/glib/gconvert.c vendored Normal file
View File

@ -0,0 +1,31 @@
#include "gstrfuncs.h"
#include "gconvert.h"
gchar*
g_convert_with_fallback (const gchar *str,
gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
const gchar *fallback,
gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
return g_strdup(str);
}
gchar*
g_locale_to_utf8 (const gchar *opsysstring,
gssize len,
gsize *bytes_read,
gsize *bytes_written,
GError **error)
{
return g_strdup(opsysstring);
}
gchar *
g_filename_display_name (const gchar *filename)
{
return g_strdup(filename);
}

94
deps/glib/gconvert.h vendored Normal file
View File

@ -0,0 +1,94 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* This file has been hacked up to contain a few stubs to get a
* standalone glib that does not care about string charset conversions
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_CONVERT_H__
#define __G_CONVERT_H__
#include <glib/gerror.h>
G_BEGIN_DECLS
/**
* GConvertError:
* @G_CONVERT_ERROR_NO_CONVERSION: Conversion between the requested character
* sets is not supported.
* @G_CONVERT_ERROR_ILLEGAL_SEQUENCE: Invalid byte sequence in conversion input.
* @G_CONVERT_ERROR_FAILED: Conversion failed for some reason.
* @G_CONVERT_ERROR_PARTIAL_INPUT: Partial character sequence at end of input.
* @G_CONVERT_ERROR_BAD_URI: URI is invalid.
* @G_CONVERT_ERROR_NOT_ABSOLUTE_PATH: Pathname is not an absolute path.
*
* Error codes returned by character set conversion routines.
*/
typedef enum
{
G_CONVERT_ERROR_NO_CONVERSION,
G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
G_CONVERT_ERROR_FAILED,
G_CONVERT_ERROR_PARTIAL_INPUT,
G_CONVERT_ERROR_BAD_URI,
G_CONVERT_ERROR_NOT_ABSOLUTE_PATH
} GConvertError;
/**
* G_CONVERT_ERROR:
*
* Error domain for character set conversions. Errors in this domain will
* be from the #GConvertError enumeration. See #GError for information on
* error domains.
*/
#define G_CONVERT_ERROR g_convert_error_quark()
GQuark g_convert_error_quark (void);
gchar* g_convert_with_fallback (const gchar *str,
gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
const gchar *fallback,
gsize *bytes_read,
gsize *bytes_written,
GError **error) G_GNUC_MALLOC;
gchar* g_locale_to_utf8 (const gchar *opsysstring,
gssize len,
gsize *bytes_read,
gsize *bytes_written,
GError **error) G_GNUC_MALLOC;
gchar *g_filename_display_name (const gchar *filename) G_GNUC_MALLOC;
G_END_DECLS
#endif /* __G_CONVERT_H__ */

1361
deps/glib/gdataset.c vendored Normal file

File diff suppressed because it is too large Load Diff

122
deps/glib/gdataset.h vendored Normal file
View File

@ -0,0 +1,122 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_DATASET_H__
#define __G_DATASET_H__
#include <glib/gquark.h>
G_BEGIN_DECLS
typedef struct _GData GData;
typedef void (*GDataForeachFunc) (GQuark key_id,
gpointer data,
gpointer user_data);
/* Keyed Data List
*/
void g_datalist_init (GData **datalist);
void g_datalist_clear (GData **datalist);
gpointer g_datalist_id_get_data (GData **datalist,
GQuark key_id);
void g_datalist_id_set_data_full (GData **datalist,
GQuark key_id,
gpointer data,
GDestroyNotify destroy_func);
gpointer g_datalist_id_remove_no_notify (GData **datalist,
GQuark key_id);
void g_datalist_foreach (GData **datalist,
GDataForeachFunc func,
gpointer user_data);
/**
* G_DATALIST_FLAGS_MASK:
*
* A bitmask that restricts the possible flags passed to
* g_datalist_set_flags(). Passing a flags value where
* flags & ~G_DATALIST_FLAGS_MASK != 0 is an error.
*/
#define G_DATALIST_FLAGS_MASK 0x3
void g_datalist_set_flags (GData **datalist,
guint flags);
void g_datalist_unset_flags (GData **datalist,
guint flags);
guint g_datalist_get_flags (GData **datalist);
#define g_datalist_id_set_data(dl, q, d) \
g_datalist_id_set_data_full ((dl), (q), (d), NULL)
#define g_datalist_id_remove_data(dl, q) \
g_datalist_id_set_data ((dl), (q), NULL)
#define g_datalist_set_data_full(dl, k, d, f) \
g_datalist_id_set_data_full ((dl), g_quark_from_string (k), (d), (f))
#define g_datalist_remove_no_notify(dl, k) \
g_datalist_id_remove_no_notify ((dl), g_quark_try_string (k))
#define g_datalist_set_data(dl, k, d) \
g_datalist_set_data_full ((dl), (k), (d), NULL)
#define g_datalist_remove_data(dl, k) \
g_datalist_id_set_data ((dl), g_quark_try_string (k), NULL)
/* Location Associated Keyed Data
*/
void g_dataset_destroy (gconstpointer dataset_location);
gpointer g_dataset_id_get_data (gconstpointer dataset_location,
GQuark key_id);
gpointer g_datalist_get_data (GData **datalist,
const gchar *key);
void g_dataset_id_set_data_full (gconstpointer dataset_location,
GQuark key_id,
gpointer data,
GDestroyNotify destroy_func);
gpointer g_dataset_id_remove_no_notify (gconstpointer dataset_location,
GQuark key_id);
void g_dataset_foreach (gconstpointer dataset_location,
GDataForeachFunc func,
gpointer user_data);
#define g_dataset_id_set_data(l, k, d) \
g_dataset_id_set_data_full ((l), (k), (d), NULL)
#define g_dataset_id_remove_data(l, k) \
g_dataset_id_set_data ((l), (k), NULL)
#define g_dataset_get_data(l, k) \
(g_dataset_id_get_data ((l), g_quark_try_string (k)))
#define g_dataset_set_data_full(l, k, d, f) \
g_dataset_id_set_data_full ((l), g_quark_from_string (k), (d), (f))
#define g_dataset_remove_no_notify(l, k) \
g_dataset_id_remove_no_notify ((l), g_quark_try_string (k))
#define g_dataset_set_data(l, k, d) \
g_dataset_set_data_full ((l), (k), (d), NULL)
#define g_dataset_remove_data(l, k) \
g_dataset_id_set_data ((l), g_quark_try_string (k), NULL)
G_END_DECLS
#endif /* __G_DATASET_H__ */

44
deps/glib/gdatasetprivate.h vendored Normal file
View File

@ -0,0 +1,44 @@
/* GLIB - Library of useful routines for C programming
* gdataset-private.h: Internal macros for accessing dataset values
* Copyright (C) 2005 Red Hat
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __G_DATASETPRIVATE_H__
#define __G_DATASETPRIVATE_H__
#include <gatomic.h>
G_BEGIN_DECLS
/* GET_FLAGS is implemented via atomic pointer access, to allow memory
* barriers to take effect without acquiring the global dataset mutex.
*/
#define G_DATALIST_GET_FLAGS(datalist) \
((gsize) g_atomic_pointer_get (datalist) & G_DATALIST_FLAGS_MASK)
G_END_DECLS
#endif /* __G_DATASETPRIVATE_H__ */

59
deps/glib/gdebug.h vendored Normal file
View File

@ -0,0 +1,59 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __G_DEBUG_H__
#define __G_DEBUG_H__
G_BEGIN_DECLS
typedef enum {
G_DEBUG_FATAL_WARNINGS = 1 << 0,
G_DEBUG_FATAL_CRITICALS = 1 << 1
} GDebugFlag;
#ifdef G_ENABLE_DEBUG
#define G_NOTE(type, action) G_STMT_START { \
if (!_g_debug_initialized) \
{ _g_debug_init (); } \
if (_g_debug_flags & G_DEBUG_##type) \
{ action; }; } G_STMT_END
#else /* !G_ENABLE_DEBUG */
#define G_NOTE(type, action)
#endif /* G_ENABLE_DEBUG */
GLIB_VAR gboolean _g_debug_initialized;
GLIB_VAR guint _g_debug_flags;
G_GNUC_INTERNAL void _g_debug_init (void);
G_END_DECLS
#endif /* __G_DEBUG_H__ */

711
deps/glib/gerror.c vendored Normal file
View File

@ -0,0 +1,711 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/**
* SECTION:error_reporting
* @Title: Error Reporting
* @Short_description: a system for reporting errors
*
* GLib provides a standard method of reporting errors from a called
* function to the calling code. (This is the same problem solved by
* exceptions in other languages.) It's important to understand that
* this method is both a <emphasis>data type</emphasis> (the #GError
* object) and a <emphasis>set of rules.</emphasis> If you use #GError
* incorrectly, then your code will not properly interoperate with other
* code that uses #GError, and users of your API will probably get confused.
*
* First and foremost: <emphasis>#GError should only be used to report
* recoverable runtime errors, never to report programming
* errors.</emphasis> If the programmer has screwed up, then you should
* use g_warning(), g_return_if_fail(), g_assert(), g_error(), or some
* similar facility. (Incidentally, remember that the g_error() function
* should <emphasis>only</emphasis> be used for programming errors, it
* should not be used to print any error reportable via #GError.)
*
* Examples of recoverable runtime errors are "file not found" or
* "failed to parse input." Examples of programming errors are "NULL
* passed to strcmp()" or "attempted to free the same pointer twice."
* These two kinds of errors are fundamentally different: runtime errors
* should be handled or reported to the user, programming errors should
* be eliminated by fixing the bug in the program. This is why most
* functions in GLib and GTK+ do not use the #GError facility.
*
* Functions that can fail take a return location for a #GError as their
* last argument. For example:
* |[
* gboolean g_file_get_contents (const gchar *filename,
* gchar **contents,
* gsize *length,
* GError **error);
* ]|
* If you pass a non-%NULL value for the <literal>error</literal>
* argument, it should point to a location where an error can be placed.
* For example:
* |[
* gchar *contents;
* GError *err = NULL;
* g_file_get_contents ("foo.txt", &amp;contents, NULL, &amp;err);
* g_assert ((contents == NULL &amp;&amp; err != NULL) || (contents != NULL &amp;&amp; err == NULL));
* if (err != NULL)
* {
* /&ast; Report error to user, and free error &ast;/
* g_assert (contents == NULL);
* fprintf (stderr, "Unable to read file: &percnt;s\n", err->message);
* g_error_free (err);
* }
* else
* {
* /&ast; Use file contents &ast;/
* g_assert (contents != NULL);
* }
* ]|
* Note that <literal>err != NULL</literal> in this example is a
* <emphasis>reliable</emphasis> indicator of whether
* g_file_get_contents() failed. Additionally, g_file_get_contents()
* returns a boolean which indicates whether it was successful.
*
* Because g_file_get_contents() returns %FALSE on failure, if you
* are only interested in whether it failed and don't need to display
* an error message, you can pass %NULL for the <literal>error</literal>
* argument:
* |[
* if (g_file_get_contents ("foo.txt", &amp;contents, NULL, NULL)) /&ast; ignore errors &ast;/
* /&ast; no error occurred &ast;/ ;
* else
* /&ast; error &ast;/ ;
* ]|
*
* The #GError object contains three fields: <literal>domain</literal>
* indicates the module the error-reporting function is located in,
* <literal>code</literal> indicates the specific error that occurred,
* and <literal>message</literal> is a user-readable error message with
* as many details as possible. Several functions are provided to deal
* with an error received from a called function: g_error_matches()
* returns %TRUE if the error matches a given domain and code,
* g_propagate_error() copies an error into an error location (so the
* calling function will receive it), and g_clear_error() clears an
* error location by freeing the error and resetting the location to
* %NULL. To display an error to the user, simply display
* <literal>error-&gt;message</literal>, perhaps along with additional
* context known only to the calling function (the file being opened,
* or whatever -- though in the g_file_get_contents() case,
* <literal>error-&gt;message</literal> already contains a filename).
*
* When implementing a function that can report errors, the basic
* tool is g_set_error(). Typically, if a fatal error occurs you
* want to g_set_error(), then return immediately. g_set_error()
* does nothing if the error location passed to it is %NULL.
* Here's an example:
* |[
* gint
* foo_open_file (GError **error)
* {
* gint fd;
*
* fd = open ("file.txt", O_RDONLY);
*
* if (fd &lt; 0)
* {
* g_set_error (error,
* FOO_ERROR, /&ast; error domain &ast;/
* FOO_ERROR_BLAH, /&ast; error code &ast;/
* "Failed to open file: &percnt;s", /&ast; error message format string &ast;/
* g_strerror (errno));
* return -1;
* }
* else
* return fd;
* }
* ]|
*
* Things are somewhat more complicated if you yourself call another
* function that can report a #GError. If the sub-function indicates
* fatal errors in some way other than reporting a #GError, such as
* by returning %TRUE on success, you can simply do the following:
* |[
* gboolean
* my_function_that_can_fail (GError **err)
* {
* g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
*
* if (!sub_function_that_can_fail (err))
* {
* /&ast; assert that error was set by the sub-function &ast;/
* g_assert (err == NULL || *err != NULL);
* return FALSE;
* }
*
* /&ast; otherwise continue, no error occurred &ast;/
* g_assert (err == NULL || *err == NULL);
* }
* ]|
*
* If the sub-function does not indicate errors other than by
* reporting a #GError, you need to create a temporary #GError
* since the passed-in one may be %NULL. g_propagate_error() is
* intended for use in this case.
* |[
* gboolean
* my_function_that_can_fail (GError **err)
* {
* GError *tmp_error;
*
* g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
*
* tmp_error = NULL;
* sub_function_that_can_fail (&amp;tmp_error);
*
* if (tmp_error != NULL)
* {
* /&ast; store tmp_error in err, if err != NULL,
* &ast; otherwise call g_error_free() on tmp_error
* &ast;/
* g_propagate_error (err, tmp_error);
* return FALSE;
* }
*
* /&ast; otherwise continue, no error occurred &ast;/
* }
* ]|
*
* Error pileups are always a bug. For example, this code is incorrect:
* |[
* gboolean
* my_function_that_can_fail (GError **err)
* {
* GError *tmp_error;
*
* g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
*
* tmp_error = NULL;
* sub_function_that_can_fail (&amp;tmp_error);
* other_function_that_can_fail (&amp;tmp_error);
*
* if (tmp_error != NULL)
* {
* g_propagate_error (err, tmp_error);
* return FALSE;
* }
* }
* ]|
* <literal>tmp_error</literal> should be checked immediately after
* sub_function_that_can_fail(), and either cleared or propagated
* upward. The rule is: <emphasis>after each error, you must either
* handle the error, or return it to the calling function</emphasis>.
* Note that passing %NULL for the error location is the equivalent
* of handling an error by always doing nothing about it. So the
* following code is fine, assuming errors in sub_function_that_can_fail()
* are not fatal to my_function_that_can_fail():
* |[
* gboolean
* my_function_that_can_fail (GError **err)
* {
* GError *tmp_error;
*
* g_return_val_if_fail (err == NULL || *err == NULL, FALSE);
*
* sub_function_that_can_fail (NULL); /&ast; ignore errors &ast;/
*
* tmp_error = NULL;
* other_function_that_can_fail (&amp;tmp_error);
*
* if (tmp_error != NULL)
* {
* g_propagate_error (err, tmp_error);
* return FALSE;
* }
* }
* ]|
*
* Note that passing %NULL for the error location
* <emphasis>ignores</emphasis> errors; it's equivalent to
* <literal>try { sub_function_that_can_fail (); } catch (...) {}</literal>
* in C++. It does <emphasis>not</emphasis> mean to leave errors
* unhandled; it means to handle them by doing nothing.
*
* Error domains and codes are conventionally named as follows:
* <itemizedlist>
* <listitem><para>
* The error domain is called
* <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR</literal>,
* for example %G_SPAWN_ERROR or %G_THREAD_ERROR:
* |[
* #define G_SPAWN_ERROR g_spawn_error_quark ()
*
* GQuark
* g_spawn_error_quark (void)
* {
* return g_quark_from_static_string ("g-spawn-error-quark");
* }
* ]|
* </para></listitem>
* <listitem><para>
* The quark function for the error domain is called
* <literal>&lt;namespace&gt;_&lt;module&gt;_error_quark</literal>,
* for example g_spawn_error_quark() or %g_thread_error_quark().
* </para></listitem>
* <listitem><para>
* The error codes are in an enumeration called
* <literal>&lt;Namespace&gt;&lt;Module&gt;Error</literal>;
* for example,#GThreadError or #GSpawnError.
* </para></listitem>
* <listitem><para>
* Members of the error code enumeration are called
* <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_&lt;CODE&gt;</literal>,
* for example %G_SPAWN_ERROR_FORK or %G_THREAD_ERROR_AGAIN.
* </para></listitem>
* <listitem><para>
* If there's a "generic" or "unknown" error code for unrecoverable
* errors it doesn't make sense to distinguish with specific codes,
* it should be called <literal>&lt;NAMESPACE&gt;_&lt;MODULE&gt;_ERROR_FAILED</literal>,
* for example %G_SPAWN_ERROR_FAILED or %G_THREAD_ERROR_FAILED.
* </para></listitem>
* </itemizedlist>
*
* Summary of rules for use of #GError:
* <itemizedlist>
* <listitem><para>
* Do not report programming errors via #GError.
* </para></listitem>
* <listitem><para>
* The last argument of a function that returns an error should
* be a location where a #GError can be placed (i.e. "#GError** error").
* If #GError is used with varargs, the #GError** should be the last
* argument before the "...".
* </para></listitem>
* <listitem><para>
* The caller may pass %NULL for the #GError** if they are not interested
* in details of the exact error that occurred.
* </para></listitem>
* <listitem><para>
* If %NULL is passed for the #GError** argument, then errors should
* not be returned to the caller, but your function should still
* abort and return if an error occurs. That is, control flow should
* not be affected by whether the caller wants to get a #GError.
* </para></listitem>
* <listitem><para>
* If a #GError is reported, then your function by definition
* <emphasis>had a fatal failure and did not complete whatever
* it was supposed to do</emphasis>. If the failure was not fatal,
* then you handled it and you should not report it. If it was fatal,
* then you must report it and discontinue whatever you were doing
* immediately.
* </para></listitem>
* <listitem><para>
* A #GError* must be initialized to %NULL before passing its address
* to a function that can report errors.
* </para></listitem>
* <listitem><para>
* "Piling up" errors is always a bug. That is, if you assign a
* new #GError to a #GError* that is non-%NULL, thus overwriting
* the previous error, it indicates that you should have aborted
* the operation instead of continuing. If you were able to continue,
* you should have cleared the previous error with g_clear_error().
* g_set_error() will complain if you pile up errors.
* </para></listitem>
* <listitem><para>
* By convention, if you return a boolean value indicating success
* then %TRUE means success and %FALSE means failure. If %FALSE is
* returned, the error <emphasis>must</emphasis> be set to a non-%NULL
* value.
* </para></listitem>
* <listitem><para>
* A %NULL return value is also frequently used to mean that an error
* occurred. You should make clear in your documentation whether %NULL
* is a valid return value in non-error cases; if %NULL is a valid value,
* then users must check whether an error was returned to see if the
* function succeeded.
* </para></listitem>
* <listitem><para>
* When implementing a function that can report errors, you may want
* to add a check at the top of your function that the error return
* location is either %NULL or contains a %NULL error (e.g.
* <literal>g_return_if_fail (error == NULL || *error == NULL);</literal>).
* </para></listitem>
* </itemizedlist>
*/
#include "config.h"
#include "gerror.h"
#include "gstrfuncs.h"
#include "gtestutils.h"
/**
* g_error_new_valist:
* @domain: error domain
* @code: error code
* @format: printf()-style format for error message
* @args: #va_list of parameters for the message format
*
* Creates a new #GError with the given @domain and @code,
* and a message formatted with @format.
*
* Returns: a new #GError
*
* Since: 2.22
*/
GError*
g_error_new_valist (GQuark domain,
gint code,
const gchar *format,
va_list args)
{
GError *error;
error = g_slice_new (GError);
error->domain = domain;
error->code = code;
error->message = g_strdup_vprintf (format, args);
return error;
}
/**
* g_error_new:
* @domain: error domain
* @code: error code
* @format: printf()-style format for error message
* @...: parameters for message format
*
* Creates a new #GError with the given @domain and @code,
* and a message formatted with @format.
*
* Return value: a new #GError
*/
GError*
g_error_new (GQuark domain,
gint code,
const gchar *format,
...)
{
GError* error;
va_list args;
g_return_val_if_fail (format != NULL, NULL);
g_return_val_if_fail (domain != 0, NULL);
va_start (args, format);
error = g_error_new_valist (domain, code, format, args);
va_end (args);
return error;
}
/**
* g_error_new_literal:
* @domain: error domain
* @code: error code
* @message: error message
*
* Creates a new #GError; unlike g_error_new(), @message is
* not a printf()-style format string. Use this function if
* @message contains text you don't have control over,
* that could include printf() escape sequences.
*
* Return value: a new #GError
**/
GError*
g_error_new_literal (GQuark domain,
gint code,
const gchar *message)
{
GError* err;
g_return_val_if_fail (message != NULL, NULL);
g_return_val_if_fail (domain != 0, NULL);
err = g_slice_new (GError);
err->domain = domain;
err->code = code;
err->message = g_strdup (message);
return err;
}
/**
* g_error_free:
* @error: a #GError
*
* Frees a #GError and associated resources.
*/
void
g_error_free (GError *error)
{
g_return_if_fail (error != NULL);
g_free (error->message);
g_slice_free (GError, error);
}
/**
* g_error_copy:
* @error: a #GError
*
* Makes a copy of @error.
*
* Return value: a new #GError
*/
GError*
g_error_copy (const GError *error)
{
GError *copy;
g_return_val_if_fail (error != NULL, NULL);
copy = g_slice_new (GError);
*copy = *error;
copy->message = g_strdup (error->message);
return copy;
}
/**
* g_error_matches:
* @error: a #GError or %NULL
* @domain: an error domain
* @code: an error code
*
* Returns %TRUE if @error matches @domain and @code, %FALSE
* otherwise. In particular, when @error is %NULL, %FALSE will
* be returned.
*
* Return value: whether @error has @domain and @code
*/
gboolean
g_error_matches (const GError *error,
GQuark domain,
gint code)
{
return error &&
error->domain == domain &&
error->code == code;
}
#define ERROR_OVERWRITTEN_WARNING "GError set over the top of a previous GError or uninitialized memory.\n" \
"This indicates a bug in someone's code. You must ensure an error is NULL before it's set.\n" \
"The overwriting error message was: %s"
/**
* g_set_error:
* @err: a return location for a #GError, or %NULL
* @domain: error domain
* @code: error code
* @format: printf()-style format
* @...: args for @format
*
* Does nothing if @err is %NULL; if @err is non-%NULL, then *@err
* must be %NULL. A new #GError is created and assigned to *@err.
*/
void
g_set_error (GError **err,
GQuark domain,
gint code,
const gchar *format,
...)
{
GError *new;
va_list args;
if (err == NULL)
return;
va_start (args, format);
new = g_error_new_valist (domain, code, format, args);
va_end (args);
if (*err == NULL)
*err = new;
else
g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
}
/**
* g_set_error_literal:
* @err: a return location for a #GError, or %NULL
* @domain: error domain
* @code: error code
* @message: error message
*
* Does nothing if @err is %NULL; if @err is non-%NULL, then *@err
* must be %NULL. A new #GError is created and assigned to *@err.
* Unlike g_set_error(), @message is not a printf()-style format string.
* Use this function if @message contains text you don't have control over,
* that could include printf() escape sequences.
*
* Since: 2.18
*/
void
g_set_error_literal (GError **err,
GQuark domain,
gint code,
const gchar *message)
{
GError *new;
if (err == NULL)
return;
new = g_error_new_literal (domain, code, message);
if (*err == NULL)
*err = new;
else
g_warning (ERROR_OVERWRITTEN_WARNING, new->message);
}
/**
* g_propagate_error:
* @dest: error return location
* @src: error to move into the return location
*
* If @dest is %NULL, free @src; otherwise, moves @src into *@dest.
* The error variable @dest points to must be %NULL.
*/
void
g_propagate_error (GError **dest,
GError *src)
{
g_return_if_fail (src != NULL);
if (dest == NULL)
{
if (src)
g_error_free (src);
return;
}
else
{
if (*dest != NULL)
g_warning (ERROR_OVERWRITTEN_WARNING, src->message);
else
*dest = src;
}
}
/**
* g_clear_error:
* @err: a #GError return location
*
* If @err is %NULL, does nothing. If @err is non-%NULL,
* calls g_error_free() on *@err and sets *@err to %NULL.
*/
void
g_clear_error (GError **err)
{
if (err && *err)
{
g_error_free (*err);
*err = NULL;
}
}
static void
g_error_add_prefix (gchar **string,
const gchar *format,
va_list ap)
{
gchar *oldstring;
gchar *prefix;
prefix = g_strdup_vprintf (format, ap);
oldstring = *string;
*string = g_strconcat (prefix, oldstring, NULL);
g_free (oldstring);
g_free (prefix);
}
/**
* g_prefix_error:
* @err: a return location for a #GError, or %NULL
* @format: printf()-style format string
* @...: arguments to @format
*
* Formats a string according to @format and
* prefix it to an existing error message. If
* @err is %NULL (ie: no error variable) then do
* nothing.
*
* If *@err is %NULL (ie: an error variable is
* present but there is no error condition) then
* also do nothing. Whether or not it makes
* sense to take advantage of this feature is up
* to you.
*
* Since: 2.16
*/
void
g_prefix_error (GError **err,
const gchar *format,
...)
{
if (err && *err)
{
va_list ap;
va_start (ap, format);
g_error_add_prefix (&(*err)->message, format, ap);
va_end (ap);
}
}
/**
* g_propagate_prefixed_error:
* @dest: error return location
* @src: error to move into the return location
* @format: printf()-style format string
* @...: arguments to @format
*
* If @dest is %NULL, free @src; otherwise,
* moves @src into *@dest. *@dest must be %NULL.
* After the move, add a prefix as with
* g_prefix_error().
*
* Since: 2.16
**/
void
g_propagate_prefixed_error (GError **dest,
GError *src,
const gchar *format,
...)
{
g_propagate_error (dest, src);
if (dest && *dest)
{
va_list ap;
va_start (ap, format);
g_error_add_prefix (&(*dest)->message, format, ap);
va_end (ap);
}
}

107
deps/glib/gerror.h vendored Normal file
View File

@ -0,0 +1,107 @@
/* gerror.h - Error reporting system
*
* Copyright 2000 Red Hat, Inc.
*
* The Gnome 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.
*
* The Gnome 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 the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_ERROR_H__
#define __G_ERROR_H__
#include <stdarg.h>
#include <glib/gquark.h>
G_BEGIN_DECLS
/**
* GError:
* @domain: error domain, e.g. #G_FILE_ERROR
* @code: error code, e.g. %G_FILE_ERROR_NOENT
* @message: human-readable informative error message
*
* The <structname>GError</structname> structure contains
* information about an error that has occurred.
*/
typedef struct _GError GError;
struct _GError
{
GQuark domain;
gint code;
gchar *message;
};
GError* g_error_new (GQuark domain,
gint code,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
GError* g_error_new_literal (GQuark domain,
gint code,
const gchar *message);
GError* g_error_new_valist (GQuark domain,
gint code,
const gchar *format,
va_list args);
void g_error_free (GError *error);
GError* g_error_copy (const GError *error);
gboolean g_error_matches (const GError *error,
GQuark domain,
gint code);
/* if (err) *err = g_error_new(domain, code, format, ...), also has
* some sanity checks.
*/
void g_set_error (GError **err,
GQuark domain,
gint code,
const gchar *format,
...) G_GNUC_PRINTF (4, 5);
void g_set_error_literal (GError **err,
GQuark domain,
gint code,
const gchar *message);
/* if (dest) *dest = src; also has some sanity checks.
*/
void g_propagate_error (GError **dest,
GError *src);
/* if (err && *err) { g_error_free(*err); *err = NULL; } */
void g_clear_error (GError **err);
/* if (err) prefix the formatted string to the ->message */
void g_prefix_error (GError **err,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
/* g_propagate_error then g_error_prefix on dest */
void g_propagate_prefixed_error (GError **dest,
GError *src,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
G_END_DECLS
#endif /* __G_ERROR_H__ */

2328
deps/glib/gfileutils.c vendored Normal file

File diff suppressed because it is too large Load Diff

150
deps/glib/gfileutils.h vendored Normal file
View File

@ -0,0 +1,150 @@
/* gfileutils.h - File utility functions
*
* Copyright 2000 Red Hat, Inc.
*
* GLib 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.
*
* GLib 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 GLib; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_FILEUTILS_H__
#define __G_FILEUTILS_H__
#include <glib/gerror.h>
G_BEGIN_DECLS
#define G_FILE_ERROR g_file_error_quark ()
typedef enum
{
G_FILE_ERROR_EXIST,
G_FILE_ERROR_ISDIR,
G_FILE_ERROR_ACCES,
G_FILE_ERROR_NAMETOOLONG,
G_FILE_ERROR_NOENT,
G_FILE_ERROR_NOTDIR,
G_FILE_ERROR_NXIO,
G_FILE_ERROR_NODEV,
G_FILE_ERROR_ROFS,
G_FILE_ERROR_TXTBSY,
G_FILE_ERROR_FAULT,
G_FILE_ERROR_LOOP,
G_FILE_ERROR_NOSPC,
G_FILE_ERROR_NOMEM,
G_FILE_ERROR_MFILE,
G_FILE_ERROR_NFILE,
G_FILE_ERROR_BADF,
G_FILE_ERROR_INVAL,
G_FILE_ERROR_PIPE,
G_FILE_ERROR_AGAIN,
G_FILE_ERROR_INTR,
G_FILE_ERROR_IO,
G_FILE_ERROR_PERM,
G_FILE_ERROR_NOSYS,
G_FILE_ERROR_FAILED
} GFileError;
/* For backward-compat reasons, these are synced to an old
* anonymous enum in libgnome. But don't use that enum
* in new code.
*/
typedef enum
{
G_FILE_TEST_IS_REGULAR = 1 << 0,
G_FILE_TEST_IS_SYMLINK = 1 << 1,
G_FILE_TEST_IS_DIR = 1 << 2,
G_FILE_TEST_IS_EXECUTABLE = 1 << 3,
G_FILE_TEST_EXISTS = 1 << 4
} GFileTest;
GQuark g_file_error_quark (void);
/* So other code can generate a GFileError */
GFileError g_file_error_from_errno (gint err_no);
#ifndef __GTK_DOC_IGNORE__
#ifdef G_OS_WIN32
#define g_file_test g_file_test_utf8
#define g_file_get_contents g_file_get_contents_utf8
#define g_mkstemp g_mkstemp_utf8
#define g_file_open_tmp g_file_open_tmp_utf8
#endif
#endif
gboolean g_file_test (const gchar *filename,
GFileTest test);
gboolean g_file_get_contents (const gchar *filename,
gchar **contents,
gsize *length,
GError **error);
gboolean g_file_set_contents (const gchar *filename,
const gchar *contents,
gssize length,
GError **error);
gchar *g_file_read_link (const gchar *filename,
GError **error);
/* Wrapper / workalike for mkdtemp() */
gchar *g_mkdtemp (gchar *tmpl);
gchar *g_mkdtemp_full (gchar *tmpl,
gint mode);
/* Wrapper / workalike for mkstemp() */
gint g_mkstemp (gchar *tmpl);
gint g_mkstemp_full (gchar *tmpl,
gint flags,
gint mode);
/* Wrappers for g_mkstemp and g_mkdtemp() */
gint g_file_open_tmp (const gchar *tmpl,
gchar **name_used,
GError **error);
gchar *g_dir_make_tmp (const gchar *tmpl,
GError **error);
typedef enum
{
G_FORMAT_SIZE_DEFAULT = 0,
G_FORMAT_SIZE_LONG_FORMAT = 1 << 0,
G_FORMAT_SIZE_IEC_UNITS = 1 << 1
} GFormatSizeFlags;
gchar * g_format_size_full (guint64 size,
GFormatSizeFlags flags);
gchar * g_format_size (guint64 size);
#ifndef G_DISABLE_DEPRECATED
char *g_format_size_for_display (goffset size);
#endif
gchar *g_build_path (const gchar *separator,
const gchar *first_element,
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
gchar *g_build_pathv (const gchar *separator,
gchar **args) G_GNUC_MALLOC;
gchar *g_build_filename (const gchar *first_element,
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
gchar *g_build_filenamev (gchar **args) G_GNUC_MALLOC;
int g_mkdir_with_parents (const gchar *pathname,
int mode);
G_END_DECLS
#endif /* __G_FILEUTILS_H__ */

1575
deps/glib/ghash.c vendored Normal file

File diff suppressed because it is too large Load Diff

168
deps/glib/ghash.h vendored Normal file
View File

@ -0,0 +1,168 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_HASH_H__
#define __G_HASH_H__
#include <glib/gtypes.h>
#include <glib/glist.h>
G_BEGIN_DECLS
typedef struct _GHashTable GHashTable;
typedef gboolean (*GHRFunc) (gpointer key,
gpointer value,
gpointer user_data);
typedef struct _GHashTableIter GHashTableIter;
struct _GHashTableIter
{
/*< private >*/
gpointer dummy1;
gpointer dummy2;
gpointer dummy3;
int dummy4;
gboolean dummy5;
gpointer dummy6;
};
/* Hash tables
*/
GHashTable* g_hash_table_new (GHashFunc hash_func,
GEqualFunc key_equal_func);
GHashTable* g_hash_table_new_full (GHashFunc hash_func,
GEqualFunc key_equal_func,
GDestroyNotify key_destroy_func,
GDestroyNotify value_destroy_func);
void g_hash_table_destroy (GHashTable *hash_table);
void g_hash_table_insert (GHashTable *hash_table,
gpointer key,
gpointer value);
void g_hash_table_replace (GHashTable *hash_table,
gpointer key,
gpointer value);
gboolean g_hash_table_remove (GHashTable *hash_table,
gconstpointer key);
void g_hash_table_remove_all (GHashTable *hash_table);
gboolean g_hash_table_steal (GHashTable *hash_table,
gconstpointer key);
void g_hash_table_steal_all (GHashTable *hash_table);
gpointer g_hash_table_lookup (GHashTable *hash_table,
gconstpointer key);
gboolean g_hash_table_lookup_extended (GHashTable *hash_table,
gconstpointer lookup_key,
gpointer *orig_key,
gpointer *value);
void g_hash_table_foreach (GHashTable *hash_table,
GHFunc func,
gpointer user_data);
gpointer g_hash_table_find (GHashTable *hash_table,
GHRFunc predicate,
gpointer user_data);
guint g_hash_table_foreach_remove (GHashTable *hash_table,
GHRFunc func,
gpointer user_data);
guint g_hash_table_foreach_steal (GHashTable *hash_table,
GHRFunc func,
gpointer user_data);
guint g_hash_table_size (GHashTable *hash_table);
GList * g_hash_table_get_keys (GHashTable *hash_table);
GList * g_hash_table_get_values (GHashTable *hash_table);
void g_hash_table_iter_init (GHashTableIter *iter,
GHashTable *hash_table);
gboolean g_hash_table_iter_next (GHashTableIter *iter,
gpointer *key,
gpointer *value);
GHashTable* g_hash_table_iter_get_hash_table (GHashTableIter *iter);
void g_hash_table_iter_remove (GHashTableIter *iter);
void g_hash_table_iter_replace (GHashTableIter *iter,
gpointer value);
void g_hash_table_iter_steal (GHashTableIter *iter);
/* keeping hash tables alive */
GHashTable* g_hash_table_ref (GHashTable *hash_table);
void g_hash_table_unref (GHashTable *hash_table);
#ifndef G_DISABLE_DEPRECATED
/**
* g_hash_table_freeze:
* @hash_table: a #GHashTable
*
* This function is deprecated and will be removed in the next major
* release of GLib. It does nothing.
**/
#define g_hash_table_freeze(hash_table) ((void)0)
/**
* g_hash_table_thaw:
* @hash_table: a #GHashTable
*
* This function is deprecated and will be removed in the next major
* release of GLib. It does nothing.
**/
#define g_hash_table_thaw(hash_table) ((void)0)
#endif /* G_DISABLE_DEPRECATED */
/* Hash Functions
*/
gboolean g_str_equal (gconstpointer v1,
gconstpointer v2);
guint g_str_hash (gconstpointer v);
gboolean g_int_equal (gconstpointer v1,
gconstpointer v2);
guint g_int_hash (gconstpointer v);
gboolean g_int64_equal (gconstpointer v1,
gconstpointer v2);
guint g_int64_hash (gconstpointer v);
gboolean g_double_equal (gconstpointer v1,
gconstpointer v2);
guint g_double_hash (gconstpointer v);
/* This "hash" function will just return the key's address as an
* unsigned integer. Useful for hashing on plain addresses or
* simple integer values.
* Passing NULL into g_hash_table_new() as GHashFunc has the
* same effect as passing g_direct_hash().
*/
guint g_direct_hash (gconstpointer v) G_GNUC_CONST;
gboolean g_direct_equal (gconstpointer v1,
gconstpointer v2) G_GNUC_CONST;
G_END_DECLS
#endif /* __G_HASH_H__ */

636
deps/glib/ghook.c vendored Normal file
View File

@ -0,0 +1,636 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GHook: Callback maintenance functions
* Copyright (C) 1998 Tim Janik
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include "ghook.h"
#include "gtestutils.h"
/* --- functions --- */
static void
default_finalize_hook (GHookList *hook_list,
GHook *hook)
{
GDestroyNotify destroy = hook->destroy;
if (destroy)
{
hook->destroy = NULL;
destroy (hook->data);
}
}
void
g_hook_list_init (GHookList *hook_list,
guint hook_size)
{
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_size >= sizeof (GHook));
hook_list->seq_id = 1;
hook_list->hook_size = hook_size;
hook_list->is_setup = TRUE;
hook_list->hooks = NULL;
hook_list->dummy3 = NULL;
hook_list->finalize_hook = default_finalize_hook;
hook_list->dummy[0] = NULL;
hook_list->dummy[1] = NULL;
}
void
g_hook_list_clear (GHookList *hook_list)
{
g_return_if_fail (hook_list != NULL);
if (hook_list->is_setup)
{
GHook *hook;
hook_list->is_setup = FALSE;
hook = hook_list->hooks;
if (!hook)
{
/* destroy hook_list->hook_memchunk */
}
else
do
{
GHook *tmp;
g_hook_ref (hook_list, hook);
g_hook_destroy_link (hook_list, hook);
tmp = hook->next;
g_hook_unref (hook_list, hook);
hook = tmp;
}
while (hook);
}
}
GHook*
g_hook_alloc (GHookList *hook_list)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (hook_list->is_setup, NULL);
hook = g_slice_alloc0 (hook_list->hook_size);
hook->data = NULL;
hook->next = NULL;
hook->prev = NULL;
hook->flags = G_HOOK_FLAG_ACTIVE;
hook->ref_count = 0;
hook->hook_id = 0;
hook->func = NULL;
hook->destroy = NULL;
return hook;
}
void
g_hook_free (GHookList *hook_list,
GHook *hook)
{
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
g_return_if_fail (hook != NULL);
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
g_return_if_fail (!G_HOOK_IN_CALL (hook));
if(hook_list->finalize_hook != NULL)
hook_list->finalize_hook (hook_list, hook);
g_slice_free1 (hook_list->hook_size, hook);
}
void
g_hook_destroy_link (GHookList *hook_list,
GHook *hook)
{
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook != NULL);
hook->flags &= ~G_HOOK_FLAG_ACTIVE;
if (hook->hook_id)
{
hook->hook_id = 0;
g_hook_unref (hook_list, hook); /* counterpart to g_hook_insert_before */
}
}
gboolean
g_hook_destroy (GHookList *hook_list,
gulong hook_id)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, FALSE);
g_return_val_if_fail (hook_id > 0, FALSE);
hook = g_hook_get (hook_list, hook_id);
if (hook)
{
g_hook_destroy_link (hook_list, hook);
return TRUE;
}
return FALSE;
}
void
g_hook_unref (GHookList *hook_list,
GHook *hook)
{
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook != NULL);
g_return_if_fail (hook->ref_count > 0);
hook->ref_count--;
if (!hook->ref_count)
{
g_return_if_fail (hook->hook_id == 0);
g_return_if_fail (!G_HOOK_IN_CALL (hook));
if (hook->prev)
hook->prev->next = hook->next;
else
hook_list->hooks = hook->next;
if (hook->next)
{
hook->next->prev = hook->prev;
hook->next = NULL;
}
hook->prev = NULL;
if (!hook_list->is_setup)
{
hook_list->is_setup = TRUE;
g_hook_free (hook_list, hook);
hook_list->is_setup = FALSE;
if (!hook_list->hooks)
{
/* destroy hook_list->hook_memchunk */
}
}
else
g_hook_free (hook_list, hook);
}
}
GHook *
g_hook_ref (GHookList *hook_list,
GHook *hook)
{
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (hook != NULL, NULL);
g_return_val_if_fail (hook->ref_count > 0, NULL);
hook->ref_count++;
return hook;
}
void
g_hook_prepend (GHookList *hook_list,
GHook *hook)
{
g_return_if_fail (hook_list != NULL);
g_hook_insert_before (hook_list, hook_list->hooks, hook);
}
void
g_hook_insert_before (GHookList *hook_list,
GHook *sibling,
GHook *hook)
{
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
g_return_if_fail (hook != NULL);
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
g_return_if_fail (hook->ref_count == 0);
hook->hook_id = hook_list->seq_id++;
hook->ref_count = 1; /* counterpart to g_hook_destroy_link */
if (sibling)
{
if (sibling->prev)
{
hook->prev = sibling->prev;
hook->prev->next = hook;
hook->next = sibling;
sibling->prev = hook;
}
else
{
hook_list->hooks = hook;
hook->next = sibling;
sibling->prev = hook;
}
}
else
{
if (hook_list->hooks)
{
sibling = hook_list->hooks;
while (sibling->next)
sibling = sibling->next;
hook->prev = sibling;
sibling->next = hook;
}
else
hook_list->hooks = hook;
}
}
void
g_hook_list_invoke (GHookList *hook_list,
gboolean may_recurse)
{
GHook *hook;
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
hook = g_hook_first_valid (hook_list, may_recurse);
while (hook)
{
GHookFunc func;
gboolean was_in_call;
func = (GHookFunc) hook->func;
was_in_call = G_HOOK_IN_CALL (hook);
hook->flags |= G_HOOK_FLAG_IN_CALL;
func (hook->data);
if (!was_in_call)
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
hook = g_hook_next_valid (hook_list, hook, may_recurse);
}
}
void
g_hook_list_invoke_check (GHookList *hook_list,
gboolean may_recurse)
{
GHook *hook;
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
hook = g_hook_first_valid (hook_list, may_recurse);
while (hook)
{
GHookCheckFunc func;
gboolean was_in_call;
gboolean need_destroy;
func = (GHookCheckFunc) hook->func;
was_in_call = G_HOOK_IN_CALL (hook);
hook->flags |= G_HOOK_FLAG_IN_CALL;
need_destroy = !func (hook->data);
if (!was_in_call)
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
if (need_destroy)
g_hook_destroy_link (hook_list, hook);
hook = g_hook_next_valid (hook_list, hook, may_recurse);
}
}
void
g_hook_list_marshal_check (GHookList *hook_list,
gboolean may_recurse,
GHookCheckMarshaller marshaller,
gpointer data)
{
GHook *hook;
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
g_return_if_fail (marshaller != NULL);
hook = g_hook_first_valid (hook_list, may_recurse);
while (hook)
{
gboolean was_in_call;
gboolean need_destroy;
was_in_call = G_HOOK_IN_CALL (hook);
hook->flags |= G_HOOK_FLAG_IN_CALL;
need_destroy = !marshaller (hook, data);
if (!was_in_call)
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
if (need_destroy)
g_hook_destroy_link (hook_list, hook);
hook = g_hook_next_valid (hook_list, hook, may_recurse);
}
}
void
g_hook_list_marshal (GHookList *hook_list,
gboolean may_recurse,
GHookMarshaller marshaller,
gpointer data)
{
GHook *hook;
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
g_return_if_fail (marshaller != NULL);
hook = g_hook_first_valid (hook_list, may_recurse);
while (hook)
{
gboolean was_in_call;
was_in_call = G_HOOK_IN_CALL (hook);
hook->flags |= G_HOOK_FLAG_IN_CALL;
marshaller (hook, data);
if (!was_in_call)
hook->flags &= ~G_HOOK_FLAG_IN_CALL;
hook = g_hook_next_valid (hook_list, hook, may_recurse);
}
}
GHook*
g_hook_first_valid (GHookList *hook_list,
gboolean may_be_in_call)
{
g_return_val_if_fail (hook_list != NULL, NULL);
if (hook_list->is_setup)
{
GHook *hook;
hook = hook_list->hooks;
if (hook)
{
g_hook_ref (hook_list, hook);
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
return hook;
else
return g_hook_next_valid (hook_list, hook, may_be_in_call);
}
}
return NULL;
}
GHook*
g_hook_next_valid (GHookList *hook_list,
GHook *hook,
gboolean may_be_in_call)
{
GHook *ohook = hook;
g_return_val_if_fail (hook_list != NULL, NULL);
if (!hook)
return NULL;
hook = hook->next;
while (hook)
{
if (G_HOOK_IS_VALID (hook) && (may_be_in_call || !G_HOOK_IN_CALL (hook)))
{
g_hook_ref (hook_list, hook);
g_hook_unref (hook_list, ohook);
return hook;
}
hook = hook->next;
}
g_hook_unref (hook_list, ohook);
return NULL;
}
GHook*
g_hook_get (GHookList *hook_list,
gulong hook_id)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (hook_id > 0, NULL);
hook = hook_list->hooks;
while (hook)
{
if (hook->hook_id == hook_id)
return hook;
hook = hook->next;
}
return NULL;
}
GHook*
g_hook_find (GHookList *hook_list,
gboolean need_valids,
GHookFindFunc func,
gpointer data)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
hook = hook_list->hooks;
while (hook)
{
GHook *tmp;
/* test only non-destroyed hooks */
if (!hook->hook_id)
{
hook = hook->next;
continue;
}
g_hook_ref (hook_list, hook);
if (func (hook, data) && hook->hook_id && (!need_valids || G_HOOK_ACTIVE (hook)))
{
g_hook_unref (hook_list, hook);
return hook;
}
tmp = hook->next;
g_hook_unref (hook_list, hook);
hook = tmp;
}
return NULL;
}
GHook*
g_hook_find_data (GHookList *hook_list,
gboolean need_valids,
gpointer data)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
hook = hook_list->hooks;
while (hook)
{
/* test only non-destroyed hooks */
if (hook->data == data &&
hook->hook_id &&
(!need_valids || G_HOOK_ACTIVE (hook)))
return hook;
hook = hook->next;
}
return NULL;
}
GHook*
g_hook_find_func (GHookList *hook_list,
gboolean need_valids,
gpointer func)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
hook = hook_list->hooks;
while (hook)
{
/* test only non-destroyed hooks */
if (hook->func == func &&
hook->hook_id &&
(!need_valids || G_HOOK_ACTIVE (hook)))
return hook;
hook = hook->next;
}
return NULL;
}
GHook*
g_hook_find_func_data (GHookList *hook_list,
gboolean need_valids,
gpointer func,
gpointer data)
{
GHook *hook;
g_return_val_if_fail (hook_list != NULL, NULL);
g_return_val_if_fail (func != NULL, NULL);
hook = hook_list->hooks;
while (hook)
{
/* test only non-destroyed hooks */
if (hook->data == data &&
hook->func == func &&
hook->hook_id &&
(!need_valids || G_HOOK_ACTIVE (hook)))
return hook;
hook = hook->next;
}
return NULL;
}
void
g_hook_insert_sorted (GHookList *hook_list,
GHook *hook,
GHookCompareFunc func)
{
GHook *sibling;
g_return_if_fail (hook_list != NULL);
g_return_if_fail (hook_list->is_setup);
g_return_if_fail (hook != NULL);
g_return_if_fail (G_HOOK_IS_UNLINKED (hook));
g_return_if_fail (hook->func != NULL);
g_return_if_fail (func != NULL);
/* first non-destroyed hook */
sibling = hook_list->hooks;
while (sibling && !sibling->hook_id)
sibling = sibling->next;
while (sibling)
{
GHook *tmp;
g_hook_ref (hook_list, sibling);
if (func (hook, sibling) <= 0 && sibling->hook_id)
{
g_hook_unref (hook_list, sibling);
break;
}
/* next non-destroyed hook */
tmp = sibling->next;
while (tmp && !tmp->hook_id)
tmp = tmp->next;
g_hook_unref (hook_list, sibling);
sibling = tmp;
}
g_hook_insert_before (hook_list, sibling, hook);
}
gint
g_hook_compare_ids (GHook *new_hook,
GHook *sibling)
{
if (new_hook->hook_id < sibling->hook_id)
return -1;
else if (new_hook->hook_id > sibling->hook_id)
return 1;
return 0;
}

181
deps/glib/ghook.h vendored Normal file
View File

@ -0,0 +1,181 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_HOOK_H__
#define __G_HOOK_H__
#include <glib/gmem.h>
G_BEGIN_DECLS
/* --- typedefs --- */
typedef struct _GHook GHook;
typedef struct _GHookList GHookList;
typedef gint (*GHookCompareFunc) (GHook *new_hook,
GHook *sibling);
typedef gboolean (*GHookFindFunc) (GHook *hook,
gpointer data);
typedef void (*GHookMarshaller) (GHook *hook,
gpointer marshal_data);
typedef gboolean (*GHookCheckMarshaller) (GHook *hook,
gpointer marshal_data);
typedef void (*GHookFunc) (gpointer data);
typedef gboolean (*GHookCheckFunc) (gpointer data);
typedef void (*GHookFinalizeFunc) (GHookList *hook_list,
GHook *hook);
typedef enum
{
G_HOOK_FLAG_ACTIVE = 1 << 0,
G_HOOK_FLAG_IN_CALL = 1 << 1,
G_HOOK_FLAG_MASK = 0x0f
} GHookFlagMask;
#define G_HOOK_FLAG_USER_SHIFT (4)
/* --- structures --- */
struct _GHookList
{
gulong seq_id;
guint hook_size : 16;
guint is_setup : 1;
GHook *hooks;
gpointer dummy3;
GHookFinalizeFunc finalize_hook;
gpointer dummy[2];
};
struct _GHook
{
gpointer data;
GHook *next;
GHook *prev;
guint ref_count;
gulong hook_id;
guint flags;
gpointer func;
GDestroyNotify destroy;
};
/* --- macros --- */
#define G_HOOK(hook) ((GHook*) (hook))
#define G_HOOK_FLAGS(hook) (G_HOOK (hook)->flags)
#define G_HOOK_ACTIVE(hook) ((G_HOOK_FLAGS (hook) & \
G_HOOK_FLAG_ACTIVE) != 0)
#define G_HOOK_IN_CALL(hook) ((G_HOOK_FLAGS (hook) & \
G_HOOK_FLAG_IN_CALL) != 0)
#define G_HOOK_IS_VALID(hook) (G_HOOK (hook)->hook_id != 0 && \
(G_HOOK_FLAGS (hook) & \
G_HOOK_FLAG_ACTIVE))
#define G_HOOK_IS_UNLINKED(hook) (G_HOOK (hook)->next == NULL && \
G_HOOK (hook)->prev == NULL && \
G_HOOK (hook)->hook_id == 0 && \
G_HOOK (hook)->ref_count == 0)
/* --- prototypes --- */
/* callback maintenance functions */
void g_hook_list_init (GHookList *hook_list,
guint hook_size);
void g_hook_list_clear (GHookList *hook_list);
GHook* g_hook_alloc (GHookList *hook_list);
void g_hook_free (GHookList *hook_list,
GHook *hook);
GHook * g_hook_ref (GHookList *hook_list,
GHook *hook);
void g_hook_unref (GHookList *hook_list,
GHook *hook);
gboolean g_hook_destroy (GHookList *hook_list,
gulong hook_id);
void g_hook_destroy_link (GHookList *hook_list,
GHook *hook);
void g_hook_prepend (GHookList *hook_list,
GHook *hook);
void g_hook_insert_before (GHookList *hook_list,
GHook *sibling,
GHook *hook);
void g_hook_insert_sorted (GHookList *hook_list,
GHook *hook,
GHookCompareFunc func);
GHook* g_hook_get (GHookList *hook_list,
gulong hook_id);
GHook* g_hook_find (GHookList *hook_list,
gboolean need_valids,
GHookFindFunc func,
gpointer data);
GHook* g_hook_find_data (GHookList *hook_list,
gboolean need_valids,
gpointer data);
GHook* g_hook_find_func (GHookList *hook_list,
gboolean need_valids,
gpointer func);
GHook* g_hook_find_func_data (GHookList *hook_list,
gboolean need_valids,
gpointer func,
gpointer data);
/* return the first valid hook, and increment its reference count */
GHook* g_hook_first_valid (GHookList *hook_list,
gboolean may_be_in_call);
/* return the next valid hook with incremented reference count, and
* decrement the reference count of the original hook
*/
GHook* g_hook_next_valid (GHookList *hook_list,
GHook *hook,
gboolean may_be_in_call);
/* GHookCompareFunc implementation to insert hooks sorted by their id */
gint g_hook_compare_ids (GHook *new_hook,
GHook *sibling);
/* convenience macros */
#define g_hook_append( hook_list, hook ) \
g_hook_insert_before ((hook_list), NULL, (hook))
/* invoke all valid hooks with the (*GHookFunc) signature.
*/
void g_hook_list_invoke (GHookList *hook_list,
gboolean may_recurse);
/* invoke all valid hooks with the (*GHookCheckFunc) signature,
* and destroy the hook if FALSE is returned.
*/
void g_hook_list_invoke_check (GHookList *hook_list,
gboolean may_recurse);
/* invoke a marshaller on all valid hooks.
*/
void g_hook_list_marshal (GHookList *hook_list,
gboolean may_recurse,
GHookMarshaller marshaller,
gpointer marshal_data);
void g_hook_list_marshal_check (GHookList *hook_list,
gboolean may_recurse,
GHookCheckMarshaller marshaller,
gpointer marshal_data);
G_END_DECLS
#endif /* __G_HOOK_H__ */

38
deps/glib/gi18n-lib.h vendored Normal file
View File

@ -0,0 +1,38 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997, 2002 Peter Mattis, 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 __G_I18N_LIB_H__
#define __G_I18N_LIB_H__
#include <glib.h>
#include <libintl.h>
#include <string.h>
#ifndef GETTEXT_PACKAGE
#error You must define GETTEXT_PACKAGE before including gi18n-lib.h. Did you forget to include config.h?
#endif
#define _(String) ((char *) g_dgettext (GETTEXT_PACKAGE, String))
#define Q_(String) g_dpgettext (GETTEXT_PACKAGE, String, 0)
#define N_(String) (String)
#define C_(Context,String) g_dpgettext (GETTEXT_PACKAGE, Context "\004" String, strlen (Context) + 1)
#define NC_(Context, String) (String)
#endif /* __G_I18N_LIB_H__ */

6
deps/glib/glib-object.h vendored Normal file
View File

@ -0,0 +1,6 @@
#ifndef __GLIB_OBJECT_H__
#define __GLIB_OBJECT_H__
#include "glib.h"
#endif /* __GLIB_OBJECT_H__ */

29
deps/glib/glib.h vendored Normal file
View File

@ -0,0 +1,29 @@
#ifndef __GLIB_H__
#define __GLIB_H__
#define __GLIB_H_INSIDE__
#include "gtypes.h"
#include "glibconfig.h"
#include "gmacros.h"
#include "gquark.h"
#include "gstrfuncs.h"
#include "gmessages.h"
#include "gmem.h"
#include "galloca.h"
#include "gslice.h"
#include "gstring.h"
#include "ghook.h"
#include "garray.h"
#include "gslist.h"
#include "glist.h"
#include "gqueue.h"
#include "gtestutils.h"
#include "gqsort.h"
#include "gatomic.h"
#include "gthread.h"
#include "ghash.h"
#include "gfileutils.h"
#include "gconvert.h"
#endif /* __GLIB_H__ */

43
deps/glib/glib_trace.h vendored Normal file
View File

@ -0,0 +1,43 @@
/* GLIB - Library of useful routines for C programming
*
* Copyright (C) 2009,2010 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.
*
* Author: Alexander Larsson <alexl@redhat.com>
*/
#ifndef __GLIBTRACE_H__
#define __GLIBTRACE_H__
#ifndef SIZEOF_CHAR
#error "config.h must be included prior to glib_trace.h"
#endif
#ifdef HAVE_DTRACE
/* include the generated probes header and put markers in code */
#include "glib_probes.h"
#define TRACE(probe) probe
#else
/* Wrap the probe to allow it to be removed when no systemtap available */
#define TRACE(probe)
#endif
#endif /* __GLIBTRACE_H__ */

42
deps/glib/glibintl.h vendored Normal file
View File

@ -0,0 +1,42 @@
#ifndef __GLIBINTL_H__
#define __GLIBINTL_H__
#ifndef SIZEOF_CHAR
#error "config.h must be included prior to glibintl.h"
#endif
const gchar * glib_gettext (const gchar *str) G_GNUC_FORMAT(1);
const gchar * glib_pgettext (const gchar *msgctxtid,
gsize msgidoffset) G_GNUC_FORMAT(1);
#ifdef ENABLE_NLS
#include <libintl.h>
#define _(String) glib_gettext(String)
/* Split out this in the code, but keep it in the same domain for now */
#define P_(String) glib_gettext(String)
#define C_(Context,String) glib_pgettext (Context "\004" String, strlen (Context) + 1)
#ifdef gettext_noop
#define N_(String) gettext_noop(String)
#else
#define N_(String) (String)
#endif
#else /* NLS is disabled */
#define _(String) (String)
#define N_(String) (String)
#define P_(String) (String)
#define C_(Context,String) (String)
#define textdomain(String) ((String) ? (String) : "messages")
#define gettext(String) (String)
#define dgettext(Domain,String) (String)
#define dcgettext(Domain,String,Type) (String)
#define dngettext(Domain,String1,String2,N) ((N) == 1 ? (String1) : (String2))
#define bindtextdomain(Domain,Directory)
#define bind_textdomain_codeset(Domain,Codeset)
#endif
/* not really I18N-related, but also a string marker macro */
#define I_(string) g_intern_static_string (string)
#endif /* __GLIBINTL_H__ */

1170
deps/glib/glist.c vendored Normal file

File diff suppressed because it is too large Load Diff

122
deps/glib/glist.h vendored Normal file
View File

@ -0,0 +1,122 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_LIST_H__
#define __G_LIST_H__
#include <glib/gmem.h>
G_BEGIN_DECLS
typedef struct _GList GList;
struct _GList
{
gpointer data;
GList *next;
GList *prev;
};
/* Doubly linked lists
*/
GList* g_list_alloc (void) G_GNUC_WARN_UNUSED_RESULT;
void g_list_free (GList *list);
void g_list_free_1 (GList *list);
#define g_list_free1 g_list_free_1
void g_list_free_full (GList *list,
GDestroyNotify free_func);
GList* g_list_append (GList *list,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_prepend (GList *list,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_insert (GList *list,
gpointer data,
gint position) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_insert_sorted (GList *list,
gpointer data,
GCompareFunc func) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_insert_sorted_with_data (GList *list,
gpointer data,
GCompareDataFunc func,
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_insert_before (GList *list,
GList *sibling,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_concat (GList *list1,
GList *list2) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_remove (GList *list,
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_remove_all (GList *list,
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_remove_link (GList *list,
GList *llink) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_delete_link (GList *list,
GList *link_) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_reverse (GList *list) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_copy (GList *list) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_nth (GList *list,
guint n);
GList* g_list_nth_prev (GList *list,
guint n);
GList* g_list_find (GList *list,
gconstpointer data);
GList* g_list_find_custom (GList *list,
gconstpointer data,
GCompareFunc func);
gint g_list_position (GList *list,
GList *llink);
gint g_list_index (GList *list,
gconstpointer data);
GList* g_list_last (GList *list);
GList* g_list_first (GList *list);
guint g_list_length (GList *list);
void g_list_foreach (GList *list,
GFunc func,
gpointer user_data);
GList* g_list_sort (GList *list,
GCompareFunc compare_func) G_GNUC_WARN_UNUSED_RESULT;
GList* g_list_sort_with_data (GList *list,
GCompareDataFunc compare_func,
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
gpointer g_list_nth_data (GList *list,
guint n);
#define g_list_previous(list) ((list) ? (((GList *)(list))->prev) : NULL)
#define g_list_next(list) ((list) ? (((GList *)(list))->next) : NULL)
#ifndef G_DISABLE_DEPRECATED
void g_list_push_allocator (gpointer allocator);
void g_list_pop_allocator (void);
#endif
G_END_DECLS
#endif /* __G_LIST_H__ */

290
deps/glib/gmacros.h vendored Normal file
View File

@ -0,0 +1,290 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/* This file must not include any other glib header file and must thus
* not refer to variables from glibconfig.h
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_MACROS_H__
#define __G_MACROS_H__
/* We include stddef.h to get the system's definition of NULL
*/
#include <stddef.h>
/* Here we provide G_GNUC_EXTENSION as an alias for __extension__,
* where this is valid. This allows for warningless compilation of
* "long long" types even in the presence of '-ansi -pedantic'.
*/
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 8)
# define G_GNUC_EXTENSION __extension__
#else
# define G_GNUC_EXTENSION
#endif
/* Provide macros to feature the GCC function attribute.
*/
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96)
#define G_GNUC_PURE \
__attribute__((__pure__))
#define G_GNUC_MALLOC \
__attribute__((__malloc__))
#else
#define G_GNUC_PURE
#define G_GNUC_MALLOC
#endif
#if __GNUC__ >= 4
#define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__))
#else
#define G_GNUC_NULL_TERMINATED
#endif
#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
#define G_GNUC_ALLOC_SIZE(x) __attribute__((__alloc_size__(x)))
#define G_GNUC_ALLOC_SIZE2(x,y) __attribute__((__alloc_size__(x,y)))
#else
#define G_GNUC_ALLOC_SIZE(x)
#define G_GNUC_ALLOC_SIZE2(x,y)
#endif
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ > 4)
#define G_GNUC_PRINTF( format_idx, arg_idx ) \
__attribute__((__format__ (__printf__, format_idx, arg_idx)))
#define G_GNUC_SCANF( format_idx, arg_idx ) \
__attribute__((__format__ (__scanf__, format_idx, arg_idx)))
#define G_GNUC_FORMAT( arg_idx ) \
__attribute__((__format_arg__ (arg_idx)))
#define G_GNUC_NORETURN \
__attribute__((__noreturn__))
#define G_GNUC_CONST \
__attribute__((__const__))
#define G_GNUC_UNUSED \
__attribute__((__unused__))
#define G_GNUC_NO_INSTRUMENT \
__attribute__((__no_instrument_function__))
#else /* !__GNUC__ */
#define G_GNUC_PRINTF( format_idx, arg_idx )
#define G_GNUC_SCANF( format_idx, arg_idx )
#define G_GNUC_FORMAT( arg_idx )
#define G_GNUC_NORETURN
#define G_GNUC_CONST
#define G_GNUC_UNUSED
#define G_GNUC_NO_INSTRUMENT
#endif /* !__GNUC__ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
#define G_GNUC_DEPRECATED \
__attribute__((__deprecated__))
#else
#define G_GNUC_DEPRECATED
#endif /* __GNUC__ */
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5)
#define G_GNUC_DEPRECATED_FOR(f) \
__attribute__((deprecated("Use " #f " instead")))
#else
#define G_GNUC_DEPRECATED_FOR(f) G_GNUC_DEPRECATED
#endif /* __GNUC__ */
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
# define G_GNUC_MAY_ALIAS __attribute__((may_alias))
#else
# define G_GNUC_MAY_ALIAS
#endif
#if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)
#define G_GNUC_WARN_UNUSED_RESULT \
__attribute__((warn_unused_result))
#else
#define G_GNUC_WARN_UNUSED_RESULT
#endif /* __GNUC__ */
#ifndef G_DISABLE_DEPRECATED
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
* macros, so we can refer to them as strings unconditionally.
* usage not-recommended since gcc-3.0
*/
#if defined (__GNUC__) && (__GNUC__ < 3)
#define G_GNUC_FUNCTION __FUNCTION__
#define G_GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else /* !__GNUC__ */
#define G_GNUC_FUNCTION ""
#define G_GNUC_PRETTY_FUNCTION ""
#endif /* !__GNUC__ */
#endif /* !G_DISABLE_DEPRECATED */
#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
#define G_STRINGIFY_ARG(contents) #contents
#ifndef __GI_SCANNER__ /* The static assert macro really confuses the introspection parser */
#define G_PASTE_ARGS(identifier1,identifier2) identifier1 ## identifier2
#define G_PASTE(identifier1,identifier2) G_PASTE_ARGS (identifier1, identifier2)
#ifdef __COUNTER__
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __COUNTER__)[(expr) ? 1 : -1]
#else
#define G_STATIC_ASSERT(expr) typedef char G_PASTE (_GStaticAssertCompileTimeAssertion_, __LINE__)[(expr) ? 1 : -1]
#endif
#define G_STATIC_ASSERT_EXPR(expr) ((void) sizeof (char[(expr) ? 1 : -1]))
#endif
/* Provide a string identifying the current code position */
#if defined(__GNUC__) && (__GNUC__ < 3) && !defined(__cplusplus)
# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__) ":" __PRETTY_FUNCTION__ "()"
#else
# define G_STRLOC __FILE__ ":" G_STRINGIFY (__LINE__)
#endif
/* Provide a string identifying the current function, non-concatenatable */
#if defined (__GNUC__)
# define G_STRFUNC ((const char*) (__PRETTY_FUNCTION__))
#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 19901L
# define G_STRFUNC ((const char*) (__func__))
#else
# define G_STRFUNC ((const char*) ("???"))
#endif
/* Guard C code in headers, while including them from C++ */
#ifdef __cplusplus
# define G_BEGIN_DECLS extern "C" {
# define G_END_DECLS }
#else
# define G_BEGIN_DECLS
# define G_END_DECLS
#endif
/* Provide definitions for some commonly used macros.
* Some of them are only provided if they haven't already
* been defined. It is assumed that if they are already
* defined then the current definition is correct.
*/
#ifndef NULL
# ifdef __cplusplus
# define NULL (0L)
# else /* !__cplusplus */
# define NULL ((void*) 0)
# endif /* !__cplusplus */
#endif
#ifndef FALSE
#define FALSE (0)
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
#undef MAX
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#undef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#undef ABS
#define ABS(a) (((a) < 0) ? -(a) : (a))
#undef CLAMP
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
/* Count the number of elements in an array. The array must be defined
* as such; using this with a dynamically allocated array will give
* incorrect results.
*/
#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
/* Macros by analogy to GINT_TO_POINTER, GPOINTER_TO_INT
*/
#define GPOINTER_TO_SIZE(p) ((gsize) (p))
#define GSIZE_TO_POINTER(s) ((gpointer) (gsize) (s))
/* Provide convenience macros for handling structure
* fields through their offsets.
*/
#if defined(__GNUC__) && __GNUC__ >= 4
# define G_STRUCT_OFFSET(struct_type, member) \
((glong) offsetof (struct_type, member))
#else
# define G_STRUCT_OFFSET(struct_type, member) \
((glong) ((guint8*) &((struct_type*) 0)->member))
#endif
#define G_STRUCT_MEMBER_P(struct_p, struct_offset) \
((gpointer) ((guint8*) (struct_p) + (glong) (struct_offset)))
#define G_STRUCT_MEMBER(member_type, struct_p, struct_offset) \
(*(member_type*) G_STRUCT_MEMBER_P ((struct_p), (struct_offset)))
/* Provide simple macro statement wrappers:
* G_STMT_START { statements; } G_STMT_END;
* This can be used as a single statement, like:
* if (x) G_STMT_START { ... } G_STMT_END; else ...
* This intentionally does not use compiler extensions like GCC's '({...})' to
* avoid portability issue or side effects when compiled with different compilers.
*/
#if !(defined (G_STMT_START) && defined (G_STMT_END))
# define G_STMT_START do
# define G_STMT_END while (0)
#endif
/* Deprecated -- do not use. */
#ifndef G_DISABLE_DEPRECATED
#ifdef G_DISABLE_CONST_RETURNS
#define G_CONST_RETURN
#else
#define G_CONST_RETURN const
#endif
#endif
/*
* The G_LIKELY and G_UNLIKELY macros let the programmer give hints to
* the compiler about the expected result of an expression. Some compilers
* can use this information for optimizations.
*
* The _G_BOOLEAN_EXPR macro is intended to trigger a gcc warning when
* putting assignments in g_return_if_fail ().
*/
#if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
#define _G_BOOLEAN_EXPR(expr) \
G_GNUC_EXTENSION ({ \
int _g_boolean_var_; \
if (expr) \
_g_boolean_var_ = 1; \
else \
_g_boolean_var_ = 0; \
_g_boolean_var_; \
})
#define G_LIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 1))
#define G_UNLIKELY(expr) (__builtin_expect (_G_BOOLEAN_EXPR(expr), 0))
#else
#define G_LIKELY(expr) (expr)
#define G_UNLIKELY(expr) (expr)
#endif
#endif /* __G_MACROS_H__ */

88
deps/glib/gmain.c vendored Normal file
View File

@ -0,0 +1,88 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* gmain.c: Main loop abstraction, timeouts, and idle functions
* Copyright 1998 Owen Taylor
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include "glibconfig.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
#ifdef G_OS_WIN32
#define STRICT
#include <windows.h>
#endif /* G_OS_WIN32 */
#include "gmessages.h"
#include "gmain.h"
/**
* g_get_current_time:
* @result: #GTimeVal structure in which to store current time.
*
* Equivalent to the UNIX gettimeofday() function, but portable.
*
* You may find g_get_real_time() to be more convenient.
**/
void
g_get_current_time (GTimeVal *result)
{
#ifndef G_OS_WIN32
struct timeval r;
g_return_if_fail (result != NULL);
/*this is required on alpha, there the timeval structs are int's
not longs and a cast only would fail horribly*/
gettimeofday (&r, NULL);
result->tv_sec = r.tv_sec;
result->tv_usec = r.tv_usec;
#else
FILETIME ft;
guint64 time64;
g_return_if_fail (result != NULL);
GetSystemTimeAsFileTime (&ft);
memmove (&time64, &ft, sizeof (FILETIME));
/* Convert from 100s of nanoseconds since 1601-01-01
* to Unix epoch. Yes, this is Y2038 unsafe.
*/
time64 -= G_GINT64_CONSTANT (116444736000000000);
time64 /= 10;
result->tv_sec = time64 / 1000000;
result->tv_usec = time64 % 1000000;
#endif
}

37
deps/glib/gmain.h vendored Normal file
View File

@ -0,0 +1,37 @@
/* gmain.h - the GLib Main loop
* Copyright (C) 1998-2000 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library 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.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_MAIN_H__
#define __G_MAIN_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
/* Miscellaneous functions
*/
void g_get_current_time (GTimeVal *result);
G_END_DECLS
#endif /* __G_MAIN_H__ */

1397
deps/glib/gmem.c vendored Normal file

File diff suppressed because it is too large Load Diff

309
deps/glib/gmem.h vendored Normal file
View File

@ -0,0 +1,309 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_MEM_H__
#define __G_MEM_H__
#include <glib/gslice.h>
#include <glib/gtypes.h>
G_BEGIN_DECLS
/**
* GMemVTable:
* @malloc: function to use for allocating memory.
* @realloc: function to use for reallocating memory.
* @free: function to use to free memory.
* @calloc: function to use for allocating zero-filled memory.
* @try_malloc: function to use for allocating memory without a default error handler.
* @try_realloc: function to use for reallocating memory without a default error handler.
*
* A set of functions used to perform memory allocation. The same #GMemVTable must
* be used for all allocations in the same program; a call to g_mem_set_vtable(),
* if it exists, should be prior to any use of GLib.
*/
typedef struct _GMemVTable GMemVTable;
#if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
/**
* G_MEM_ALIGN:
*
* Indicates the number of bytes to which memory will be aligned on the
* current platform.
*/
# define G_MEM_ALIGN GLIB_SIZEOF_VOID_P
#else /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
# define G_MEM_ALIGN GLIB_SIZEOF_LONG
#endif /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
/* Memory allocation functions
*/
void g_free (gpointer mem);
gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_realloc (gpointer mem,
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
gpointer g_try_malloc (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_try_malloc0 (gsize n_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_try_realloc (gpointer mem,
gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
gpointer g_malloc_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
gpointer g_malloc0_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
gpointer g_realloc_n (gpointer mem,
gsize n_blocks,
gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
gpointer g_try_malloc_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
gpointer g_try_malloc0_n (gsize n_blocks,
gsize n_block_bytes) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE2(1,2);
gpointer g_try_realloc_n (gpointer mem,
gsize n_blocks,
gsize n_block_bytes) G_GNUC_WARN_UNUSED_RESULT;
/* Optimise: avoid the call to the (slower) _n function if we can
* determine at compile-time that no overflow happens.
*/
#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
# define _G_NEW(struct_type, n_structs, func) \
(struct_type *) (G_GNUC_EXTENSION ({ \
gsize __n = (gsize) (n_structs); \
gsize __s = sizeof (struct_type); \
gpointer __p; \
if (__s == 1) \
__p = g_##func (__n); \
else if (__builtin_constant_p (__n) && \
(__s == 0 || __n <= G_MAXSIZE / __s)) \
__p = g_##func (__n * __s); \
else \
__p = g_##func##_n (__n, __s); \
__p; \
}))
# define _G_RENEW(struct_type, mem, n_structs, func) \
(struct_type *) (G_GNUC_EXTENSION ({ \
gsize __n = (gsize) (n_structs); \
gsize __s = sizeof (struct_type); \
gpointer __p = (gpointer) (mem); \
if (__s == 1) \
__p = g_##func (__p, __n); \
else if (__builtin_constant_p (__n) && \
(__s == 0 || __n <= G_MAXSIZE / __s)) \
__p = g_##func (__p, __n * __s); \
else \
__p = g_##func##_n (__p, __n, __s); \
__p; \
}))
#else
/* Unoptimised version: always call the _n() function. */
#define _G_NEW(struct_type, n_structs, func) \
((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))
#define _G_RENEW(struct_type, mem, n_structs, func) \
((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_type)))
#endif
/**
* g_new:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Allocates @n_structs elements of type @struct_type.
* The returned pointer is cast to a pointer to the given type.
* If @n_structs is 0 it returns %NULL.
* Care is taken to avoid overflow when calculating the size of the allocated block.
*
* Since the returned pointer is already casted to the right type,
* it is normally unnecessary to cast it explicitly, and doing
* so might hide memory allocation errors.
*
* Returns: a pointer to the allocated memory, cast to a pointer to @struct_type
*/
#define g_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc)
/**
* g_new0:
* @struct_type: the type of the elements to allocate.
* @n_structs: the number of elements to allocate.
*
* Allocates @n_structs elements of type @struct_type, initialized to 0's.
* The returned pointer is cast to a pointer to the given type.
* If @n_structs is 0 it returns %NULL.
* Care is taken to avoid overflow when calculating the size of the allocated block.
*
* Since the returned pointer is already casted to the right type,
* it is normally unnecessary to cast it explicitly, and doing
* so might hide memory allocation errors.
*
* Returns: a pointer to the allocated memory, cast to a pointer to @struct_type.
*/
#define g_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, malloc0)
/**
* g_renew:
* @struct_type: the type of the elements to allocate
* @mem: the currently allocated memory
* @n_structs: the number of elements to allocate
*
* Reallocates the memory pointed to by @mem, so that it now has space for
* @n_structs elements of type @struct_type. It returns the new address of
* the memory, which may have been moved.
* Care is taken to avoid overflow when calculating the size of the allocated block.
*
* Returns: a pointer to the new allocated memory, cast to a pointer to @struct_type
*/
#define g_renew(struct_type, mem, n_structs) _G_RENEW (struct_type, mem, n_structs, realloc)
/**
* g_try_new:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Attempts to allocate @n_structs elements of type @struct_type, and returns
* %NULL on failure. Contrast with g_new(), which aborts the program on failure.
* The returned pointer is cast to a pointer to the given type.
* The function returns %NULL when @n_structs is 0 of if an overflow occurs.
*
* Since: 2.8
* Returns: a pointer to the allocated memory, cast to a pointer to @struct_type
*/
#define g_try_new(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc)
/**
* g_try_new0:
* @struct_type: the type of the elements to allocate
* @n_structs: the number of elements to allocate
*
* Attempts to allocate @n_structs elements of type @struct_type, initialized
* to 0's, and returns %NULL on failure. Contrast with g_new0(), which aborts
* the program on failure.
* The returned pointer is cast to a pointer to the given type.
* The function returns %NULL when @n_structs is 0 of if an overflow occurs.
*
* Since: 2.8
* Returns: a pointer to the allocated memory, cast to a pointer to @struct_type
*/
#define g_try_new0(struct_type, n_structs) _G_NEW (struct_type, n_structs, try_malloc0)
/**
* g_try_renew:
* @struct_type: the type of the elements to allocate
* @mem: the currently allocated memory
* @n_structs: the number of elements to allocate
*
* Attempts to reallocate the memory pointed to by @mem, so that it now has
* space for @n_structs elements of type @struct_type, and returns %NULL on
* failure. Contrast with g_renew(), which aborts the program on failure.
* It returns the new address of the memory, which may have been moved.
* The function returns %NULL if an overflow occurs.
*
* Since: 2.8
* Returns: a pointer to the new allocated memory, cast to a pointer to @struct_type
*/
#define g_try_renew(struct_type, mem, n_structs) _G_RENEW (struct_type, mem, n_structs, try_realloc)
/* Memory allocation virtualization for debugging purposes
* g_mem_set_vtable() has to be the very first GLib function called
* if being used
*/
struct _GMemVTable {
gpointer (*malloc) (gsize n_bytes);
gpointer (*realloc) (gpointer mem,
gsize n_bytes);
void (*free) (gpointer mem);
/* optional; set to NULL if not used ! */
gpointer (*calloc) (gsize n_blocks,
gsize n_block_bytes);
gpointer (*try_malloc) (gsize n_bytes);
gpointer (*try_realloc) (gpointer mem,
gsize n_bytes);
};
void g_mem_set_vtable (GMemVTable *vtable);
gboolean g_mem_is_system_malloc (void);
GLIB_VAR gboolean g_mem_gc_friendly;
/* Memory profiler and checker, has to be enabled via g_mem_set_vtable()
*/
GLIB_VAR GMemVTable *glib_mem_profiler_table;
void g_mem_profile (void);
/* deprecated memchunks and allocators */
#if !defined (G_DISABLE_DEPRECATED) || defined (GTK_COMPILATION) || defined (GDK_COMPILATION)
typedef struct _GAllocator GAllocator;
typedef struct _GMemChunk GMemChunk;
#define g_mem_chunk_create(type, pre_alloc, alloc_type) ( \
g_mem_chunk_new (#type " mem chunks (" #pre_alloc ")", \
sizeof (type), \
sizeof (type) * (pre_alloc), \
(alloc_type)) \
)
#define g_chunk_new(type, chunk) ( \
(type *) g_mem_chunk_alloc (chunk) \
)
#define g_chunk_new0(type, chunk) ( \
(type *) g_mem_chunk_alloc0 (chunk) \
)
#define g_chunk_free(mem, mem_chunk) G_STMT_START { \
g_mem_chunk_free ((mem_chunk), (mem)); \
} G_STMT_END
#define G_ALLOC_ONLY 1
#define G_ALLOC_AND_FREE 2
GMemChunk* g_mem_chunk_new (const gchar *name,
gint atom_size,
gsize area_size,
gint type);
void g_mem_chunk_destroy (GMemChunk *mem_chunk);
gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
gpointer g_mem_chunk_alloc0 (GMemChunk *mem_chunk);
void g_mem_chunk_free (GMemChunk *mem_chunk,
gpointer mem);
void g_mem_chunk_clean (GMemChunk *mem_chunk);
void g_mem_chunk_reset (GMemChunk *mem_chunk);
void g_mem_chunk_print (GMemChunk *mem_chunk);
void g_mem_chunk_info (void);
void g_blow_chunks (void);
GAllocator*g_allocator_new (const gchar *name,
guint n_preallocs);
void g_allocator_free (GAllocator *allocator);
#define G_ALLOCATOR_LIST (1)
#define G_ALLOCATOR_SLIST (2)
#define G_ALLOCATOR_NODE (3)
#endif /* G_DISABLE_DEPRECATED */
G_END_DECLS
#endif /* __G_MEM_H__ */

1084
deps/glib/gmessages.c vendored Normal file

File diff suppressed because it is too large Load Diff

405
deps/glib/gmessages.h vendored Normal file
View File

@ -0,0 +1,405 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_MESSAGES_H__
#define __G_MESSAGES_H__
#include <stdarg.h>
#include <glib/gtypes.h>
#include <glib/gmacros.h>
/* Suppress warnings when GCC is in -pedantic mode and not -std=c99
*/
#if (__GNUC__ >= 3 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 96))
#pragma GCC system_header
#endif
G_BEGIN_DECLS
/* calculate a string size, guaranteed to fit format + args.
*/
gsize g_printf_string_upper_bound (const gchar* format,
va_list args);
/* Log level shift offset for user defined
* log levels (0-7 are used by GLib).
*/
#define G_LOG_LEVEL_USER_SHIFT (8)
/* Glib log levels and flags.
*/
typedef enum
{
/* log flags */
G_LOG_FLAG_RECURSION = 1 << 0,
G_LOG_FLAG_FATAL = 1 << 1,
/* GLib log levels */
G_LOG_LEVEL_ERROR = 1 << 2, /* always fatal */
G_LOG_LEVEL_CRITICAL = 1 << 3,
G_LOG_LEVEL_WARNING = 1 << 4,
G_LOG_LEVEL_MESSAGE = 1 << 5,
G_LOG_LEVEL_INFO = 1 << 6,
G_LOG_LEVEL_DEBUG = 1 << 7,
G_LOG_LEVEL_MASK = ~(G_LOG_FLAG_RECURSION | G_LOG_FLAG_FATAL)
} GLogLevelFlags;
/* GLib log levels that are considered fatal by default */
#define G_LOG_FATAL_MASK (G_LOG_FLAG_RECURSION | G_LOG_LEVEL_ERROR)
typedef void (*GLogFunc) (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data);
/* Logging mechanism
*/
guint g_log_set_handler (const gchar *log_domain,
GLogLevelFlags log_levels,
GLogFunc log_func,
gpointer user_data);
void g_log_remove_handler (const gchar *log_domain,
guint handler_id);
void g_log_default_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer unused_data);
GLogFunc g_log_set_default_handler (GLogFunc log_func,
gpointer user_data);
void g_log (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *format,
...) G_GNUC_PRINTF (3, 4);
void g_logv (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *format,
va_list args);
GLogLevelFlags g_log_set_fatal_mask (const gchar *log_domain,
GLogLevelFlags fatal_mask);
GLogLevelFlags g_log_set_always_fatal (GLogLevelFlags fatal_mask);
/* internal */
G_GNUC_INTERNAL void _g_log_fallback_handler (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer unused_data);
/* Internal functions, used to implement the following macros */
void g_return_if_fail_warning (const char *log_domain,
const char *pretty_function,
const char *expression);
void g_warn_message (const char *domain,
const char *file,
int line,
const char *func,
const char *warnexpr);
#ifndef G_DISABLE_DEPRECATED
void g_assert_warning (const char *log_domain,
const char *file,
const int line,
const char *pretty_function,
const char *expression) G_GNUC_NORETURN;
#endif /* !G_DISABLE_DEPRECATED */
#ifndef G_LOG_DOMAIN
#define G_LOG_DOMAIN ((gchar*) 0)
#endif /* G_LOG_DOMAIN */
#ifdef G_HAVE_ISO_VARARGS
/* for(;;) ; so that GCC knows that control doesn't go past g_error().
* Put space before ending semicolon to avoid C++ build warnings.
*/
#define g_error(...) G_STMT_START { \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_ERROR, \
__VA_ARGS__); \
for (;;) ; \
} G_STMT_END
#define g_message(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_MESSAGE, \
__VA_ARGS__)
#define g_critical(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
__VA_ARGS__)
#define g_warning(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_WARNING, \
__VA_ARGS__)
#define g_debug(...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
__VA_ARGS__)
#elif defined(G_HAVE_GNUC_VARARGS)
#define g_error(format...) G_STMT_START { \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_ERROR, \
format); \
for (;;) ; \
} G_STMT_END
#define g_message(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_MESSAGE, \
format)
#define g_critical(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
format)
#define g_warning(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_WARNING, \
format)
#define g_debug(format...) g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_DEBUG, \
format)
#else /* no varargs macros */
static void
g_error (const gchar *format,
...)
{
va_list args;
va_start (args, format);
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, format, args);
va_end (args);
for(;;) ;
}
static void
g_message (const gchar *format,
...)
{
va_list args;
va_start (args, format);
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, format, args);
va_end (args);
}
static void
g_critical (const gchar *format,
...)
{
va_list args;
va_start (args, format);
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, format, args);
va_end (args);
}
static void
g_warning (const gchar *format,
...)
{
va_list args;
va_start (args, format);
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, format, args);
va_end (args);
}
static void
g_debug (const gchar *format,
...)
{
va_list args;
va_start (args, format);
g_logv (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, format, args);
va_end (args);
}
#endif /* !__GNUC__ */
/**
* GPrintFunc:
* @string: the message to output
*
* Specifies the type of the print handler functions.
* These are called with the complete formatted string to output.
*/
typedef void (*GPrintFunc) (const gchar *string);
void g_print (const gchar *format,
...) G_GNUC_PRINTF (1, 2);
GPrintFunc g_set_print_handler (GPrintFunc func);
void g_printerr (const gchar *format,
...) G_GNUC_PRINTF (1, 2);
GPrintFunc g_set_printerr_handler (GPrintFunc func);
/**
* g_warn_if_reached:
*
* Logs a critical warning.
*
* Since: 2.16
*/
#define g_warn_if_reached() \
do { \
g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); \
} while (0)
/**
* g_warn_if_fail:
* @expr: the expression to check
*
* Logs a warning if the expression is not true.
*
* Since: 2.16
*/
#define g_warn_if_fail(expr) \
do { \
if G_LIKELY (expr) ; \
else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, #expr); \
} while (0)
#ifdef G_DISABLE_CHECKS
/**
* g_return_if_fail:
* @expr: the expression to check
*
* Verifies that the expression evaluates to %TRUE. If the expression
* evaluates to %FALSE, a critical message is logged and the current
* function returns. This can only be used in functions which do not
* return a value.
*
* If G_DISABLE_CHECKS is defined then the check is not performed. You
* should therefore not depend on any side effects of @expr.
*/
#define g_return_if_fail(expr) G_STMT_START{ (void)0; }G_STMT_END
/**
* g_return_val_if_fail:
* @expr: the expression to check
* @val: the value to return from the current function
* if the expression is not true
*
* Verifies that the expression evaluates to %TRUE. If the expression
* evaluates to %FALSE, a critical message is logged and @val is
* returned from the current function.
*
* If G_DISABLE_CHECKS is defined then the check is not performed. You
* should therefore not depend on any side effects of @expr.
*/
#define g_return_val_if_fail(expr,val) G_STMT_START{ (void)0; }G_STMT_END
/**
* g_return_if_reached:
*
* Logs a critical message and returns from the current function.
* This can only be used in functions which do not return a value.
*/
#define g_return_if_reached() G_STMT_START{ return; }G_STMT_END
/**
* g_return_val_if_reached:
* @val: the value to return from the current function
*
* Logs a critical message and returns @val.
*/
#define g_return_val_if_reached(val) G_STMT_START{ return (val); }G_STMT_END
#else /* !G_DISABLE_CHECKS */
#ifdef __GNUC__
#define g_return_if_fail(expr) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
g_return_if_fail_warning (G_LOG_DOMAIN, \
__PRETTY_FUNCTION__, \
#expr); \
return; \
}; }G_STMT_END
#define g_return_val_if_fail(expr,val) G_STMT_START{ \
if G_LIKELY(expr) { } else \
{ \
g_return_if_fail_warning (G_LOG_DOMAIN, \
__PRETTY_FUNCTION__, \
#expr); \
return (val); \
}; }G_STMT_END
#define g_return_if_reached() G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__); \
return; }G_STMT_END
#define g_return_val_if_reached(val) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d (%s): should not be reached", \
__FILE__, \
__LINE__, \
__PRETTY_FUNCTION__); \
return (val); }G_STMT_END
#else /* !__GNUC__ */
#define g_return_if_fail(expr) G_STMT_START{ \
if (expr) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d: assertion `%s' failed", \
__FILE__, \
__LINE__, \
#expr); \
return; \
}; }G_STMT_END
#define g_return_val_if_fail(expr, val) G_STMT_START{ \
if (expr) { } else \
{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d: assertion `%s' failed", \
__FILE__, \
__LINE__, \
#expr); \
return (val); \
}; }G_STMT_END
#define g_return_if_reached() G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d: should not be reached", \
__FILE__, \
__LINE__); \
return; }G_STMT_END
#define g_return_val_if_reached(val) G_STMT_START{ \
g_log (G_LOG_DOMAIN, \
G_LOG_LEVEL_CRITICAL, \
"file %s: line %d: should not be reached", \
__FILE__, \
__LINE__); \
return (val); }G_STMT_END
#endif /* !__GNUC__ */
#endif /* !G_DISABLE_CHECKS */
G_END_DECLS
#endif /* __G_MESSAGES_H__ */

340
deps/glib/gprintf.c vendored Normal file
View File

@ -0,0 +1,340 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997, 2002 Peter Mattis, 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.
*/
#include "config.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include "gprintf.h"
#include "gprintfint.h"
/**
* g_printf:
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @...: the arguments to insert in the output.
*
* An implementation of the standard printf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_printf (gchar const *format,
...)
{
va_list args;
gint retval;
va_start (args, format);
retval = g_vprintf (format, args);
va_end (args);
return retval;
}
/**
* g_fprintf:
* @file: the stream to write to.
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @...: the arguments to insert in the output.
*
* An implementation of the standard fprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_fprintf (FILE *file,
gchar const *format,
...)
{
va_list args;
gint retval;
va_start (args, format);
retval = g_vfprintf (file, format, args);
va_end (args);
return retval;
}
/**
* g_sprintf:
* @string: A pointer to a memory buffer to contain the resulting string. It
* is up to the caller to ensure that the allocated buffer is large
* enough to hold the formatted result
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @...: the arguments to insert in the output.
*
* An implementation of the standard sprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Note that it is usually better to use g_snprintf(), to avoid the
* risk of buffer overflow.
*
* See also g_strdup_printf().
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_sprintf (gchar *string,
gchar const *format,
...)
{
va_list args;
gint retval;
va_start (args, format);
retval = g_vsprintf (string, format, args);
va_end (args);
return retval;
}
/**
* g_snprintf:
* @string: the buffer to hold the output.
* @n: the maximum number of bytes to produce (including the
* terminating nul character).
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @...: the arguments to insert in the output.
*
* A safer form of the standard sprintf() function. The output is guaranteed
* to not exceed @n characters (including the terminating nul character), so
* it is easy to ensure that a buffer overflow cannot occur.
*
* See also g_strdup_printf().
*
* In versions of GLib prior to 1.2.3, this function may return -1 if the
* output was truncated, and the truncated string may not be nul-terminated.
* In versions prior to 1.3.12, this function returns the length of the output
* string.
*
* The return value of g_snprintf() conforms to the snprintf()
* function as standardized in ISO C99. Note that this is different from
* traditional snprintf(), which returns the length of the output string.
*
* The format string may contain positional parameters, as specified in
* the Single Unix Specification.
*
* Returns: the number of bytes which would be produced if the buffer
* was large enough.
**/
gint
g_snprintf (gchar *string,
gulong n,
gchar const *format,
...)
{
va_list args;
gint retval;
va_start (args, format);
retval = g_vsnprintf (string, n, format, args);
va_end (args);
return retval;
}
/**
* g_vprintf:
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @args: the list of arguments to insert in the output.
*
* An implementation of the standard vprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_vprintf (gchar const *format,
va_list args)
{
g_return_val_if_fail (format != NULL, -1);
return _g_vprintf (format, args);
}
/**
* g_vfprintf:
* @file: the stream to write to.
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @args: the list of arguments to insert in the output.
*
* An implementation of the standard fprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_vfprintf (FILE *file,
gchar const *format,
va_list args)
{
g_return_val_if_fail (format != NULL, -1);
return _g_vfprintf (file, format, args);
}
/**
* g_vsprintf:
* @string: the buffer to hold the output.
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @args: the list of arguments to insert in the output.
*
* An implementation of the standard vsprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
*
* Returns: the number of bytes printed.
*
* Since: 2.2
**/
gint
g_vsprintf (gchar *string,
gchar const *format,
va_list args)
{
g_return_val_if_fail (string != NULL, -1);
g_return_val_if_fail (format != NULL, -1);
return _g_vsprintf (string, format, args);
}
/**
* g_vsnprintf:
* @string: the buffer to hold the output.
* @n: the maximum number of bytes to produce (including the
* terminating nul character).
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @args: the list of arguments to insert in the output.
*
* A safer form of the standard vsprintf() function. The output is guaranteed
* to not exceed @n characters (including the terminating nul character), so
* it is easy to ensure that a buffer overflow cannot occur.
*
* See also g_strdup_vprintf().
*
* In versions of GLib prior to 1.2.3, this function may return -1 if the
* output was truncated, and the truncated string may not be nul-terminated.
* In versions prior to 1.3.12, this function returns the length of the output
* string.
*
* The return value of g_vsnprintf() conforms to the vsnprintf() function
* as standardized in ISO C99. Note that this is different from traditional
* vsnprintf(), which returns the length of the output string.
*
* The format string may contain positional parameters, as specified in
* the Single Unix Specification.
*
* Returns: the number of bytes which would be produced if the buffer
* was large enough.
*/
gint
g_vsnprintf (gchar *string,
gulong n,
gchar const *format,
va_list args)
{
g_return_val_if_fail (n == 0 || string != NULL, -1);
g_return_val_if_fail (format != NULL, -1);
return _g_vsnprintf (string, n, format, args);
}
/**
* g_vasprintf:
* @string: the return location for the newly-allocated string.
* @format: a standard printf() format string, but notice
* <link linkend="string-precision">string precision pitfalls</link>.
* @args: the list of arguments to insert in the output.
*
* An implementation of the GNU vasprintf() function which supports
* positional parameters, as specified in the Single Unix Specification.
* This function is similar to g_vsprintf(), except that it allocates a
* string to hold the output, instead of putting the output in a buffer
* you allocate in advance.
*
* Returns: the number of bytes printed.
*
* Since: 2.4
**/
gint
g_vasprintf (gchar **string,
gchar const *format,
va_list args)
{
gint len;
g_return_val_if_fail (string != NULL, -1);
#if !defined(HAVE_GOOD_PRINTF)
len = _g_gnulib_vasprintf (string, format, args);
if (len < 0)
*string = NULL;
#elif defined (HAVE_VASPRINTF)
len = vasprintf (string, format, args);
if (len < 0)
*string = NULL;
else if (!g_mem_is_system_malloc ())
{
/* vasprintf returns malloc-allocated memory */
gchar *string1 = g_strndup (*string, len);
free (*string);
*string = string1;
}
#else
{
va_list args2;
G_VA_COPY (args2, args);
*string = g_new (gchar, g_printf_string_upper_bound (format, args));
len = _g_vsprintf (*string, format, args2);
va_end (args2);
}
#endif
return len;
}

52
deps/glib/gprintf.h vendored Normal file
View File

@ -0,0 +1,52 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997, 2002 Peter Mattis, 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 __G_PRINTF_H__
#define __G_PRINTF_H__
#include <glib.h>
#include <stdio.h>
#include <stdarg.h>
G_BEGIN_DECLS
gint g_printf (gchar const *format,
...) G_GNUC_PRINTF (1, 2);
gint g_fprintf (FILE *file,
gchar const *format,
...) G_GNUC_PRINTF (2, 3);
gint g_sprintf (gchar *string,
gchar const *format,
...) G_GNUC_PRINTF (2, 3);
gint g_vprintf (gchar const *format,
va_list args);
gint g_vfprintf (FILE *file,
gchar const *format,
va_list args);
gint g_vsprintf (gchar *string,
gchar const *format,
va_list args);
gint g_vasprintf (gchar **string,
gchar const *format,
va_list args);
G_END_DECLS
#endif /* __G_PRINTF_H__ */

59
deps/glib/gprintfint.h vendored Normal file
View File

@ -0,0 +1,59 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 2002. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __G_PRINTFINT_H__
#define __G_PRINTFINT_H__
#ifdef HAVE_GOOD_PRINTF
#define _g_printf printf
#define _g_fprintf fprintf
#define _g_sprintf sprintf
#define _g_snprintf snprintf
#define _g_vprintf vprintf
#define _g_vfprintf vfprintf
#define _g_vsprintf vsprintf
#define _g_vsnprintf vsnprintf
#else
#include "gnulib/printf.h"
#define _g_printf _g_gnulib_printf
#define _g_fprintf _g_gnulib_fprintf
#define _g_sprintf _g_gnulib_sprintf
#define _g_snprintf _g_gnulib_snprintf
#define _g_vprintf _g_gnulib_vprintf
#define _g_vfprintf _g_gnulib_vfprintf
#define _g_vsprintf _g_gnulib_vsprintf
#define _g_vsnprintf _g_gnulib_vsnprintf
#endif
#endif /* __G_PRINTF_H__ */

300
deps/glib/gqsort.c vendored Normal file
View File

@ -0,0 +1,300 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1991, 1992, 1996, 1997,1999,2004 Free Software Foundation, Inc.
* Copyright (C) 2000 Eazel, Inc.
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* This file was originally part of the GNU C Library, and was modified to allow
* user data to be passed in to the sorting function.
*
* Written by Douglas C. Schmidt (schmidt@ics.uci.edu).
* Modified by Maciej Stachowiak (mjs@eazel.com)
*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with GLib
* at ftp://ftp.gtk.org/pub/gtk/.
*/
#include "config.h"
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include "gqsort.h"
#include "gtestutils.h"
#ifdef HAVE_QSORT_R
/**
* g_qsort_with_data:
* @pbase: start of array to sort
* @total_elems: elements in the array
* @size: size of each element
* @compare_func: function to compare elements
* @user_data: data to pass to @compare_func
*
* This is just like the standard C qsort() function, but
* the comparison routine accepts a user data argument.
*/
void
g_qsort_with_data (gconstpointer pbase,
gint total_elems,
gsize size,
GCompareDataFunc compare_func,
gpointer user_data)
{
qsort_r ((gpointer)pbase, total_elems, size, compare_func, user_data);
}
#else
/* Byte-wise swap two items of size SIZE. */
#define SWAP(a, b, size) \
do \
{ \
register size_t __size = (size); \
register char *__a = (a), *__b = (b); \
do \
{ \
char __tmp = *__a; \
*__a++ = *__b; \
*__b++ = __tmp; \
} while (--__size > 0); \
} while (0)
/* Discontinue quicksort algorithm when partition gets below this size.
This particular magic number was chosen to work best on a Sun 4/260. */
#define MAX_THRESH 4
/* Stack node declarations used to store unfulfilled partition obligations. */
typedef struct
{
char *lo;
char *hi;
} stack_node;
/* The next 4 #defines implement a very fast in-line stack abstraction. */
/* The stack needs log (total_elements) entries (we could even subtract
log(MAX_THRESH)). Since total_elements has type size_t, we get as
upper bound for log (total_elements):
bits per byte (CHAR_BIT) * sizeof(size_t). */
#define STACK_SIZE (CHAR_BIT * sizeof(size_t))
#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top))
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
#define STACK_NOT_EMPTY (stack < top)
/* Order size using quicksort. This implementation incorporates
four optimizations discussed in Sedgewick:
1. Non-recursive, using an explicit stack of pointer that store the
next array partition to sort. To save time, this maximum amount
of space required to store an array of SIZE_MAX is allocated on the
stack. Assuming a 32-bit (64 bit) integer for size_t, this needs
only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes).
Pretty cheap, actually.
2. Chose the pivot element using a median-of-three decision tree.
This reduces the probability of selecting a bad pivot value and
eliminates certain extraneous comparisons.
3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving
insertion sort to order the MAX_THRESH items within each partition.
This is a big win, since insertion sort is faster for small, mostly
sorted array segments.
4. The larger of the two sub-partitions is always pushed onto the
stack first, with the algorithm then concentrating on the
smaller partition. This *guarantees* no more than log (total_elems)
stack size is needed (actually O(1) in this case)! */
void
g_qsort_with_data (gconstpointer pbase,
gint total_elems,
gsize size,
GCompareDataFunc compare_func,
gpointer user_data)
{
register char *base_ptr = (char *) pbase;
const size_t max_thresh = MAX_THRESH * size;
g_return_if_fail (total_elems >= 0);
g_return_if_fail (pbase != NULL || total_elems == 0);
g_return_if_fail (compare_func != NULL);
if (total_elems == 0)
/* Avoid lossage with unsigned arithmetic below. */
return;
if (total_elems > MAX_THRESH)
{
char *lo = base_ptr;
char *hi = &lo[size * (total_elems - 1)];
stack_node stack[STACK_SIZE];
stack_node *top = stack;
PUSH (NULL, NULL);
while (STACK_NOT_EMPTY)
{
char *left_ptr;
char *right_ptr;
/* Select median value from among LO, MID, and HI. Rearrange
LO and HI so the three values are sorted. This lowers the
probability of picking a pathological pivot value and
skips a comparison for both the LEFT_PTR and RIGHT_PTR in
the while loops. */
char *mid = lo + size * ((hi - lo) / size >> 1);
if ((*compare_func) ((void *) mid, (void *) lo, user_data) < 0)
SWAP (mid, lo, size);
if ((*compare_func) ((void *) hi, (void *) mid, user_data) < 0)
SWAP (mid, hi, size);
else
goto jump_over;
if ((*compare_func) ((void *) mid, (void *) lo, user_data) < 0)
SWAP (mid, lo, size);
jump_over:;
left_ptr = lo + size;
right_ptr = hi - size;
/* Here's the famous ``collapse the walls'' section of quicksort.
Gotta like those tight inner loops! They are the main reason
that this algorithm runs much faster than others. */
do
{
while ((*compare_func) ((void *) left_ptr, (void *) mid, user_data) < 0)
left_ptr += size;
while ((*compare_func) ((void *) mid, (void *) right_ptr, user_data) < 0)
right_ptr -= size;
if (left_ptr < right_ptr)
{
SWAP (left_ptr, right_ptr, size);
if (mid == left_ptr)
mid = right_ptr;
else if (mid == right_ptr)
mid = left_ptr;
left_ptr += size;
right_ptr -= size;
}
else if (left_ptr == right_ptr)
{
left_ptr += size;
right_ptr -= size;
break;
}
}
while (left_ptr <= right_ptr);
/* Set up pointers for next iteration. First determine whether
left and right partitions are below the threshold size. If so,
ignore one or both. Otherwise, push the larger partition's
bounds on the stack and continue sorting the smaller one. */
if ((size_t) (right_ptr - lo) <= max_thresh)
{
if ((size_t) (hi - left_ptr) <= max_thresh)
/* Ignore both small partitions. */
POP (lo, hi);
else
/* Ignore small left partition. */
lo = left_ptr;
}
else if ((size_t) (hi - left_ptr) <= max_thresh)
/* Ignore small right partition. */
hi = right_ptr;
else if ((right_ptr - lo) > (hi - left_ptr))
{
/* Push larger left partition indices. */
PUSH (lo, right_ptr);
lo = left_ptr;
}
else
{
/* Push larger right partition indices. */
PUSH (left_ptr, hi);
hi = right_ptr;
}
}
}
/* Once the BASE_PTR array is partially sorted by quicksort the rest
is completely sorted using insertion sort, since this is efficient
for partitions below MAX_THRESH size. BASE_PTR points to the beginning
of the array to sort, and END_PTR points at the very last element in
the array (*not* one beyond it!). */
#define min(x, y) ((x) < (y) ? (x) : (y))
{
char *const end_ptr = &base_ptr[size * (total_elems - 1)];
char *tmp_ptr = base_ptr;
char *thresh = min(end_ptr, base_ptr + max_thresh);
register char *run_ptr;
/* Find smallest element in first threshold and place it at the
array's beginning. This is the smallest array element,
and the operation speeds up insertion sort's inner loop. */
for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
if ((*compare_func) ((void *) run_ptr, (void *) tmp_ptr, user_data) < 0)
tmp_ptr = run_ptr;
if (tmp_ptr != base_ptr)
SWAP (tmp_ptr, base_ptr, size);
/* Insertion sort, running from left-hand-side up to right-hand-side. */
run_ptr = base_ptr + size;
while ((run_ptr += size) <= end_ptr)
{
tmp_ptr = run_ptr - size;
while ((*compare_func) ((void *) run_ptr, (void *) tmp_ptr, user_data) < 0)
tmp_ptr -= size;
tmp_ptr += size;
if (tmp_ptr != run_ptr)
{
char *trav;
trav = run_ptr + size;
while (--trav >= run_ptr)
{
char c = *trav;
char *hi, *lo;
for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo)
*hi = *lo;
*hi = c;
}
}
}
}
}
#endif /* HAVE_QSORT_R */

46
deps/glib/gqsort.h vendored Normal file
View File

@ -0,0 +1,46 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_QSORT_H__
#define __G_QSORT_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
void g_qsort_with_data (gconstpointer pbase,
gint total_elems,
gsize size,
GCompareDataFunc compare_func,
gpointer user_data);
G_END_DECLS
#endif /* __G_QSORT_H__ */

52
deps/glib/gquark.h vendored Normal file
View File

@ -0,0 +1,52 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_QUARK_H__
#define __G_QUARK_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
typedef guint32 GQuark;
/* Quarks (string<->id association)
*/
GQuark g_quark_try_string (const gchar *string);
GQuark g_quark_from_static_string (const gchar *string);
GQuark g_quark_from_string (const gchar *string);
const gchar * g_quark_to_string (GQuark quark) G_GNUC_CONST;
const gchar * g_intern_string (const gchar *string);
const gchar * g_intern_static_string (const gchar *string);
G_END_DECLS
#endif /* __G_QUARK_H__ */

1047
deps/glib/gqueue.c vendored Normal file

File diff suppressed because it is too large Load Diff

150
deps/glib/gqueue.h vendored Normal file
View File

@ -0,0 +1,150 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_QUEUE_H__
#define __G_QUEUE_H__
#include <glib/glist.h>
G_BEGIN_DECLS
typedef struct _GQueue GQueue;
/**
* GQueue:
* @head: a pointer to the first element of the queue
* @tail: a pointer to the last element of the queue
* @length: the number of elements in the queue
*
* Contains the public fields of a
* <link linkend="glib-Double-ended-Queues">Queue</link>.
*/
struct _GQueue
{
GList *head;
GList *tail;
guint length;
};
/**
* G_QUEUE_INIT:
*
* A statically-allocated #GQueue must be initialized with this
* macro before it can be used. This macro can be used to initialize
* a variable, but it cannot be assigned to a variable. In that case
* you have to use g_queue_init().
*
* |[
* GQueue my_queue = G_QUEUE_INIT;
* ]|
*
* Since: 2.14
*/
#define G_QUEUE_INIT { NULL, NULL, 0 }
/* Queues
*/
GQueue* g_queue_new (void);
void g_queue_free (GQueue *queue);
void g_queue_init (GQueue *queue);
void g_queue_clear (GQueue *queue);
gboolean g_queue_is_empty (GQueue *queue);
guint g_queue_get_length (GQueue *queue);
void g_queue_reverse (GQueue *queue);
GQueue * g_queue_copy (GQueue *queue);
void g_queue_foreach (GQueue *queue,
GFunc func,
gpointer user_data);
GList * g_queue_find (GQueue *queue,
gconstpointer data);
GList * g_queue_find_custom (GQueue *queue,
gconstpointer data,
GCompareFunc func);
void g_queue_sort (GQueue *queue,
GCompareDataFunc compare_func,
gpointer user_data);
void g_queue_push_head (GQueue *queue,
gpointer data);
void g_queue_push_tail (GQueue *queue,
gpointer data);
void g_queue_push_nth (GQueue *queue,
gpointer data,
gint n);
gpointer g_queue_pop_head (GQueue *queue);
gpointer g_queue_pop_tail (GQueue *queue);
gpointer g_queue_pop_nth (GQueue *queue,
guint n);
gpointer g_queue_peek_head (GQueue *queue);
gpointer g_queue_peek_tail (GQueue *queue);
gpointer g_queue_peek_nth (GQueue *queue,
guint n);
gint g_queue_index (GQueue *queue,
gconstpointer data);
gboolean g_queue_remove (GQueue *queue,
gconstpointer data);
guint g_queue_remove_all (GQueue *queue,
gconstpointer data);
void g_queue_insert_before (GQueue *queue,
GList *sibling,
gpointer data);
void g_queue_insert_after (GQueue *queue,
GList *sibling,
gpointer data);
void g_queue_insert_sorted (GQueue *queue,
gpointer data,
GCompareDataFunc func,
gpointer user_data);
void g_queue_push_head_link (GQueue *queue,
GList *link_);
void g_queue_push_tail_link (GQueue *queue,
GList *link_);
void g_queue_push_nth_link (GQueue *queue,
gint n,
GList *link_);
GList* g_queue_pop_head_link (GQueue *queue);
GList* g_queue_pop_tail_link (GQueue *queue);
GList* g_queue_pop_nth_link (GQueue *queue,
guint n);
GList* g_queue_peek_head_link (GQueue *queue);
GList* g_queue_peek_tail_link (GQueue *queue);
GList* g_queue_peek_nth_link (GQueue *queue,
guint n);
gint g_queue_link_index (GQueue *queue,
GList *link_);
void g_queue_unlink (GQueue *queue,
GList *link_);
void g_queue_delete_link (GQueue *queue,
GList *link_);
G_END_DECLS
#endif /* __G_QUEUE_H__ */

1495
deps/glib/gslice.c vendored Normal file

File diff suppressed because it is too large Load Diff

86
deps/glib/gslice.h vendored Normal file
View File

@ -0,0 +1,86 @@
/* GLIB sliced memory - fast threaded memory chunk allocator
* Copyright (C) 2005 Tim Janik
*
* 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.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_SLICE_H__
#define __G_SLICE_H__
#include <glib/gtypes.h>
G_BEGIN_DECLS
/* slices - fast allocation/release of small memory blocks
*/
gpointer g_slice_alloc (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_slice_alloc0 (gsize block_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
gpointer g_slice_copy (gsize block_size,
gconstpointer mem_block) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(1);
void g_slice_free1 (gsize block_size,
gpointer mem_block);
void g_slice_free_chain_with_offset (gsize block_size,
gpointer mem_chain,
gsize next_offset);
#define g_slice_new(type) ((type*) g_slice_alloc (sizeof (type)))
#define g_slice_new0(type) ((type*) g_slice_alloc0 (sizeof (type)))
/* MemoryBlockType *
* g_slice_dup (MemoryBlockType,
* MemoryBlockType *mem_block);
* g_slice_free (MemoryBlockType,
* MemoryBlockType *mem_block);
* g_slice_free_chain (MemoryBlockType,
* MemoryBlockType *first_chain_block,
* memory_block_next_field);
* pseudo prototypes for the macro
* definitions following below.
*/
/* we go through extra hoops to ensure type safety */
#define g_slice_dup(type, mem) \
(1 ? (type*) g_slice_copy (sizeof (type), (mem)) \
: ((void) ((type*) 0 == (mem)), (type*) 0))
#define g_slice_free(type, mem) do { \
if (1) g_slice_free1 (sizeof (type), (mem)); \
else (void) ((type*) 0 == (mem)); \
} while (0)
#define g_slice_free_chain(type, mem_chain, next) do { \
if (1) g_slice_free_chain_with_offset (sizeof (type), \
(mem_chain), G_STRUCT_OFFSET (type, next)); \
else (void) ((type*) 0 == (mem_chain)); \
} while (0)
/* --- internal debugging API --- */
typedef enum {
G_SLICE_CONFIG_ALWAYS_MALLOC = 1,
G_SLICE_CONFIG_BYPASS_MAGAZINES,
G_SLICE_CONFIG_WORKING_SET_MSECS,
G_SLICE_CONFIG_COLOR_INCREMENT,
G_SLICE_CONFIG_CHUNK_SIZES,
G_SLICE_CONFIG_CONTENTION_COUNTER
} GSliceConfig;
void g_slice_set_config (GSliceConfig ckey, gint64 value);
gint64 g_slice_get_config (GSliceConfig ckey);
gint64* g_slice_get_config_state (GSliceConfig ckey, gint64 address, guint *n_values);
G_END_DECLS
#endif /* __G_SLICE_H__ */

1082
deps/glib/gslist.c vendored Normal file

File diff suppressed because it is too large Load Diff

116
deps/glib/gslist.h vendored Normal file
View File

@ -0,0 +1,116 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_SLIST_H__
#define __G_SLIST_H__
#include <glib/gmem.h>
G_BEGIN_DECLS
typedef struct _GSList GSList;
struct _GSList
{
gpointer data;
GSList *next;
};
/* Singly linked lists
*/
GSList* g_slist_alloc (void) G_GNUC_WARN_UNUSED_RESULT;
void g_slist_free (GSList *list);
void g_slist_free_1 (GSList *list);
#define g_slist_free1 g_slist_free_1
void g_slist_free_full (GSList *list,
GDestroyNotify free_func);
GSList* g_slist_append (GSList *list,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_prepend (GSList *list,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_insert (GSList *list,
gpointer data,
gint position) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_insert_sorted (GSList *list,
gpointer data,
GCompareFunc func) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_insert_sorted_with_data (GSList *list,
gpointer data,
GCompareDataFunc func,
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_insert_before (GSList *slist,
GSList *sibling,
gpointer data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_concat (GSList *list1,
GSList *list2) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_remove (GSList *list,
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_remove_all (GSList *list,
gconstpointer data) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_remove_link (GSList *list,
GSList *link_) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_delete_link (GSList *list,
GSList *link_) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_reverse (GSList *list) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_copy (GSList *list) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_nth (GSList *list,
guint n);
GSList* g_slist_find (GSList *list,
gconstpointer data);
GSList* g_slist_find_custom (GSList *list,
gconstpointer data,
GCompareFunc func);
gint g_slist_position (GSList *list,
GSList *llink);
gint g_slist_index (GSList *list,
gconstpointer data);
GSList* g_slist_last (GSList *list);
guint g_slist_length (GSList *list);
void g_slist_foreach (GSList *list,
GFunc func,
gpointer user_data);
GSList* g_slist_sort (GSList *list,
GCompareFunc compare_func) G_GNUC_WARN_UNUSED_RESULT;
GSList* g_slist_sort_with_data (GSList *list,
GCompareDataFunc compare_func,
gpointer user_data) G_GNUC_WARN_UNUSED_RESULT;
gpointer g_slist_nth_data (GSList *list,
guint n);
#define g_slist_next(slist) ((slist) ? (((GSList *)(slist))->next) : NULL)
#ifndef G_DISABLE_DEPRECATED
void g_slist_push_allocator (gpointer dummy);
void g_slist_pop_allocator (void);
#endif
G_END_DECLS
#endif /* __G_SLIST_H__ */

832
deps/glib/gstdio.c vendored Normal file
View File

@ -0,0 +1,832 @@
/* gstdio.c - wrappers for C library functions
*
* Copyright 2004 Tor Lillqvist
*
* GLib 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.
*
* GLib 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 GLib; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "config.h"
#include "glibconfig.h"
#define G_STDIO_NO_WRAP_ON_UNIX
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_WIN32
#include <windows.h>
#include <errno.h>
#include <wchar.h>
#include <direct.h>
#include <io.h>
#include <sys/utime.h>
#else
#include <utime.h>
#endif
#include "gstdio.h"
#if !defined (G_OS_UNIX) && !defined (G_OS_WIN32) && !defined (G_OS_BEOS)
#error Please port this to your operating system
#endif
#if defined (_MSC_VER) && !defined(_WIN64)
#undef _wstat
#define _wstat _wstat32
#endif
/**
* g_access:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: as in access()
*
* A wrapper for the POSIX access() function. This function is used to
* test a pathname for one or several of read, write or execute
* permissions, or just existence.
*
* On Windows, the file protection mechanism is not at all POSIX-like,
* and the underlying function in the C library only checks the
* FAT-style READONLY attribute, and does not look at the ACL of a
* file at all. This function is this in practise almost useless on
* Windows. Software that needs to handle file permissions on Windows
* more exactly should use the Win32 API.
*
* See your C library manual for more details about access().
*
* Returns: zero if the pathname refers to an existing file system
* object that has all the tested permissions, or -1 otherwise or on
* error.
*
* Since: 2.8
*/
int
g_access (const gchar *filename,
int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
#ifndef X_OK
#define X_OK 1
#endif
retval = _waccess (wfilename, mode & ~X_OK);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return access (filename, mode);
#endif
}
/**
* g_chmod:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: as in chmod()
*
* A wrapper for the POSIX chmod() function. The chmod() function is
* used to set the permissions of a file system object.
*
* On Windows the file protection mechanism is not at all POSIX-like,
* and the underlying chmod() function in the C library just sets or
* clears the FAT-style READONLY attribute. It does not touch any
* ACL. Software that needs to manage file permissions on Windows
* exactly should use the Win32 API.
*
* See your C library manual for more details about chmod().
*
* Returns: zero if the operation succeeded, -1 on error.
*
* Since: 2.8
*/
int
g_chmod (const gchar *filename,
int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wchmod (wfilename, mode);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return chmod (filename, mode);
#endif
}
/**
* g_open:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @flags: as in open()
* @mode: as in open()
*
* A wrapper for the POSIX open() function. The open() function is
* used to convert a pathname into a file descriptor.
*
* On POSIX systems file descriptors are implemented by the operating
* system. On Windows, it's the C library that implements open() and
* file descriptors. The actual Win32 API for opening files is quite
* different, see MSDN documentation for CreateFile(). The Win32 API
* uses file handles, which are more randomish integers, not small
* integers like file descriptors.
*
* Because file descriptors are specific to the C library on Windows,
* the file descriptor returned by this function makes sense only to
* functions in the same C library. Thus if the GLib-using code uses a
* different C library than GLib does, the file descriptor returned by
* this function cannot be passed to C library functions like write()
* or read().
*
* See your C library manual for more details about open().
*
* Returns: a new file descriptor, or -1 if an error occurred. The
* return value can be used exactly like the return value from open().
*
* Since: 2.6
*/
int
g_open (const gchar *filename,
int flags,
int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wopen (wfilename, flags, mode);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return open (filename, flags, mode);
#endif
}
/**
* g_creat:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: as in creat()
*
* A wrapper for the POSIX creat() function. The creat() function is
* used to convert a pathname into a file descriptor, creating a file
* if necessary.
* On POSIX systems file descriptors are implemented by the operating
* system. On Windows, it's the C library that implements creat() and
* file descriptors. The actual Windows API for opening files is
* different, see MSDN documentation for CreateFile(). The Win32 API
* uses file handles, which are more randomish integers, not small
* integers like file descriptors.
*
* Because file descriptors are specific to the C library on Windows,
* the file descriptor returned by this function makes sense only to
* functions in the same C library. Thus if the GLib-using code uses a
* different C library than GLib does, the file descriptor returned by
* this function cannot be passed to C library functions like write()
* or read().
*
* See your C library manual for more details about creat().
*
* Returns: a new file descriptor, or -1 if an error occurred. The
* return value can be used exactly like the return value from creat().
*
* Since: 2.8
*/
int
g_creat (const gchar *filename,
int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wcreat (wfilename, mode);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return creat (filename, mode);
#endif
}
/**
* g_rename:
* @oldfilename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @newfilename: a pathname in the GLib file name encoding
*
* A wrapper for the POSIX rename() function. The rename() function
* renames a file, moving it between directories if required.
*
* See your C library manual for more details about how rename() works
* on your system. It is not possible in general on Windows to rename
* a file that is open to some process.
*
* Returns: 0 if the renaming succeeded, -1 if an error occurred
*
* Since: 2.6
*/
int
g_rename (const gchar *oldfilename,
const gchar *newfilename)
{
#ifdef G_OS_WIN32
wchar_t *woldfilename = g_utf8_to_utf16 (oldfilename, -1, NULL, NULL, NULL);
wchar_t *wnewfilename;
int retval;
int save_errno = 0;
if (woldfilename == NULL)
{
errno = EINVAL;
return -1;
}
wnewfilename = g_utf8_to_utf16 (newfilename, -1, NULL, NULL, NULL);
if (wnewfilename == NULL)
{
g_free (woldfilename);
errno = EINVAL;
return -1;
}
if (MoveFileExW (woldfilename, wnewfilename, MOVEFILE_REPLACE_EXISTING))
retval = 0;
else
{
retval = -1;
switch (GetLastError ())
{
#define CASE(a,b) case ERROR_##a: save_errno = b; break
CASE (FILE_NOT_FOUND, ENOENT);
CASE (PATH_NOT_FOUND, ENOENT);
CASE (ACCESS_DENIED, EACCES);
CASE (NOT_SAME_DEVICE, EXDEV);
CASE (LOCK_VIOLATION, EACCES);
CASE (SHARING_VIOLATION, EACCES);
CASE (FILE_EXISTS, EEXIST);
CASE (ALREADY_EXISTS, EEXIST);
#undef CASE
default: save_errno = EIO;
}
}
g_free (woldfilename);
g_free (wnewfilename);
errno = save_errno;
return retval;
#else
return rename (oldfilename, newfilename);
#endif
}
/**
* g_mkdir:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: permissions to use for the newly created directory
*
* A wrapper for the POSIX mkdir() function. The mkdir() function
* attempts to create a directory with the given name and permissions.
* The mode argument is ignored on Windows.
*
* See your C library manual for more details about mkdir().
*
* Returns: 0 if the directory was successfully created, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_mkdir (const gchar *filename,
int mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wmkdir (wfilename);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return mkdir (filename, mode);
#endif
}
/**
* g_chdir:
* @path: a pathname in the GLib file name encoding (UTF-8 on Windows)
*
* A wrapper for the POSIX chdir() function. The function changes the
* current directory of the process to @path.
*
* See your C library manual for more details about chdir().
*
* Returns: 0 on success, -1 if an error occurred.
*
* Since: 2.8
*/
int
g_chdir (const gchar *path)
{
#ifdef G_OS_WIN32
wchar_t *wpath = g_utf8_to_utf16 (path, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wpath == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wchdir (wpath);
save_errno = errno;
g_free (wpath);
errno = save_errno;
return retval;
#else
return chdir (path);
#endif
}
/**
* GStatBuf:
*
* A type corresponding to the appropriate struct type for the stat
* system call, depending on the platform and/or compiler being used.
*
* See g_stat() for more information.
**/
/**
* g_stat:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @buf: a pointer to a <structname>stat</structname> struct, which
* will be filled with the file information
*
* A wrapper for the POSIX stat() function. The stat() function
* returns information about a file. On Windows the stat() function in
* the C library checks only the FAT-style READONLY attribute and does
* not look at the ACL at all. Thus on Windows the protection bits in
* the st_mode field are a fabrication of little use.
*
* On Windows the Microsoft C libraries have several variants of the
* <structname>stat</structname> struct and stat() function with names
* like "_stat", "_stat32", "_stat32i64" and "_stat64i32". The one
* used here is for 32-bit code the one with 32-bit size and time
* fields, specifically called "_stat32".
*
* In Microsoft's compiler, by default "struct stat" means one with
* 64-bit time fields while in MinGW "struct stat" is the legacy one
* with 32-bit fields. To hopefully clear up this messs, the gstdio.h
* header defines a type GStatBuf which is the appropriate struct type
* depending on the platform and/or compiler being used. On POSIX it
* is just "struct stat", but note that even on POSIX platforms,
* "stat" might be a macro.
*
* See your C library manual for more details about stat().
*
* Returns: 0 if the information was successfully retrieved, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_stat (const gchar *filename,
GStatBuf *buf)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
int len;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
len = wcslen (wfilename);
while (len > 0 && G_IS_DIR_SEPARATOR (wfilename[len-1]))
len--;
if (len > 0 &&
(!g_path_is_absolute (filename) || len > g_path_skip_root (filename) - filename))
wfilename[len] = '\0';
retval = _wstat (wfilename, buf);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return stat (filename, buf);
#endif
}
/**
* g_lstat:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @buf: a pointer to a <structname>stat</structname> struct, which
* will be filled with the file information
*
* A wrapper for the POSIX lstat() function. The lstat() function is
* like stat() except that in the case of symbolic links, it returns
* information about the symbolic link itself and not the file that it
* refers to. If the system does not support symbolic links g_lstat()
* is identical to g_stat().
*
* See your C library manual for more details about lstat().
*
* Returns: 0 if the information was successfully retrieved, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_lstat (const gchar *filename,
GStatBuf *buf)
{
#ifdef HAVE_LSTAT
/* This can't be Win32, so don't do the widechar dance. */
return lstat (filename, buf);
#else
return g_stat (filename, buf);
#endif
}
/**
* g_unlink:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
*
* A wrapper for the POSIX unlink() function. The unlink() function
* deletes a name from the filesystem. If this was the last link to the
* file and no processes have it opened, the diskspace occupied by the
* file is freed.
*
* See your C library manual for more details about unlink(). Note
* that on Windows, it is in general not possible to delete files that
* are open to some process, or mapped into memory.
*
* Returns: 0 if the name was successfully deleted, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_unlink (const gchar *filename)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wunlink (wfilename);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return unlink (filename);
#endif
}
/**
* g_remove:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
*
* A wrapper for the POSIX remove() function. The remove() function
* deletes a name from the filesystem.
*
* See your C library manual for more details about how remove() works
* on your system. On Unix, remove() removes also directories, as it
* calls unlink() for files and rmdir() for directories. On Windows,
* although remove() in the C library only works for files, this
* function tries first remove() and then if that fails rmdir(), and
* thus works for both files and directories. Note however, that on
* Windows, it is in general not possible to remove a file that is
* open to some process, or mapped into memory.
*
* If this function fails on Windows you can't infer too much from the
* errno value. rmdir() is tried regardless of what caused remove() to
* fail. Any errno value set by remove() will be overwritten by that
* set by rmdir().
*
* Returns: 0 if the file was successfully removed, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_remove (const gchar *filename)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wremove (wfilename);
if (retval == -1)
retval = _wrmdir (wfilename);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return remove (filename);
#endif
}
/**
* g_rmdir:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
*
* A wrapper for the POSIX rmdir() function. The rmdir() function
* deletes a directory from the filesystem.
*
* See your C library manual for more details about how rmdir() works
* on your system.
*
* Returns: 0 if the directory was successfully removed, -1 if an error
* occurred
*
* Since: 2.6
*/
int
g_rmdir (const gchar *filename)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wrmdir (wfilename);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return rmdir (filename);
#endif
}
/**
* g_fopen:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: a string describing the mode in which the file should be
* opened
*
* A wrapper for the stdio fopen() function. The fopen() function
* opens a file and associates a new stream with it.
*
* Because file descriptors are specific to the C library on Windows,
* and a file descriptor is partof the <type>FILE</type> struct, the
* <type>FILE</type> pointer returned by this function makes sense
* only to functions in the same C library. Thus if the GLib-using
* code uses a different C library than GLib does, the
* <type>FILE</type> pointer returned by this function cannot be
* passed to C library functions like fprintf() or fread().
*
* See your C library manual for more details about fopen().
*
* Returns: A <type>FILE</type> pointer if the file was successfully
* opened, or %NULL if an error occurred
*
* Since: 2.6
*/
FILE *
g_fopen (const gchar *filename,
const gchar *mode)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
wchar_t *wmode;
FILE *retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return NULL;
}
wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
if (wmode == NULL)
{
g_free (wfilename);
errno = EINVAL;
return NULL;
}
retval = _wfopen (wfilename, wmode);
save_errno = errno;
g_free (wfilename);
g_free (wmode);
errno = save_errno;
return retval;
#else
return fopen (filename, mode);
#endif
}
/**
* g_freopen:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @mode: a string describing the mode in which the file should be
* opened
* @stream: an existing stream which will be reused, or %NULL
*
* A wrapper for the POSIX freopen() function. The freopen() function
* opens a file and associates it with an existing stream.
*
* See your C library manual for more details about freopen().
*
* Returns: A <type>FILE</type> pointer if the file was successfully
* opened, or %NULL if an error occurred.
*
* Since: 2.6
*/
FILE *
g_freopen (const gchar *filename,
const gchar *mode,
FILE *stream)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
wchar_t *wmode;
FILE *retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return NULL;
}
wmode = g_utf8_to_utf16 (mode, -1, NULL, NULL, NULL);
if (wmode == NULL)
{
g_free (wfilename);
errno = EINVAL;
return NULL;
}
retval = _wfreopen (wfilename, wmode, stream);
save_errno = errno;
g_free (wfilename);
g_free (wmode);
errno = save_errno;
return retval;
#else
return freopen (filename, mode, stream);
#endif
}
/**
* g_utime:
* @filename: a pathname in the GLib file name encoding (UTF-8 on Windows)
* @utb: a pointer to a struct utimbuf.
*
* A wrapper for the POSIX utime() function. The utime() function
* sets the access and modification timestamps of a file.
*
* See your C library manual for more details about how utime() works
* on your system.
*
* Returns: 0 if the operation was successful, -1 if an error
* occurred
*
* Since: 2.18
*/
int
g_utime (const gchar *filename,
struct utimbuf *utb)
{
#ifdef G_OS_WIN32
wchar_t *wfilename = g_utf8_to_utf16 (filename, -1, NULL, NULL, NULL);
int retval;
int save_errno;
if (wfilename == NULL)
{
errno = EINVAL;
return -1;
}
retval = _wutime (wfilename, (struct _utimbuf*) utb);
save_errno = errno;
g_free (wfilename);
errno = save_errno;
return retval;
#else
return utime (filename, utb);
#endif
}

149
deps/glib/gstdio.h vendored Normal file
View File

@ -0,0 +1,149 @@
/* gstdio.h - GFilename wrappers for C library functions
*
* Copyright 2004 Tor Lillqvist
*
* GLib 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.
*
* GLib 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 GLib; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __G_STDIO_H__
#define __G_STDIO_H__
#include <glib/gprintf.h>
#include <sys/stat.h>
G_BEGIN_DECLS
#if defined (_MSC_VER) && !defined(_WIN64)
/* Make it clear that we mean the struct with 32-bit st_size and
* 32-bit st_*time fields as that is how the 32-bit GLib DLL normally
* has been compiled. If you get a compiler warning when calling
* g_stat(), do take it seriously and make sure that the type of
* struct stat the code in GLib fills in matches the struct the type
* of struct stat you pass to g_stat(). To avoid hassle, to get file
* attributes just use the GIO API instead which doesn't use struct
* stat.
*
* Sure, it would be nicer to use a struct with 64-bit st_size and
* 64-bit st_*time fields, but changing that now would break ABI. And
* in MinGW, a plain "struct stat" is the one with 32-bit st_size and
* st_*time fields.
*/
typedef struct _stat32 GStatBuf;
#else
typedef struct stat GStatBuf;
#endif
#if defined(G_OS_UNIX) && !defined(G_STDIO_NO_WRAP_ON_UNIX)
/* Just pass on to the system functions, so there's no potential for data
* format mismatches, especially with large file interfaces.
* A few functions can't be handled in this way, since they are not defined
* in a portable system header that we could include here.
*/
#ifndef __GTK_DOC_IGNORE__
#define g_chmod chmod
#define g_open open
#define g_creat creat
#define g_rename rename
#define g_mkdir mkdir
#define g_stat stat
#define g_lstat lstat
#define g_remove remove
#define g_fopen fopen
#define g_freopen freopen
#define g_utime utime
#endif
int g_access (const gchar *filename,
int mode);
int g_chdir (const gchar *path);
int g_unlink (const gchar *filename);
int g_rmdir (const gchar *filename);
#else /* ! G_OS_UNIX */
/* Wrappers for C library functions that take pathname arguments. On
* Unix, the pathname is a file name as it literally is in the file
* system. On well-maintained systems with consistent users who know
* what they are doing and no exchange of files with others this would
* be a well-defined encoding, preferably UTF-8. On Windows, the
* pathname is always in UTF-8, even if that is not the on-disk
* encoding, and not the encoding accepted by the C library or Win32
* API.
*/
int g_access (const gchar *filename,
int mode);
int g_chmod (const gchar *filename,
int mode);
int g_open (const gchar *filename,
int flags,
int mode);
int g_creat (const gchar *filename,
int mode);
int g_rename (const gchar *oldfilename,
const gchar *newfilename);
int g_mkdir (const gchar *filename,
int mode);
int g_chdir (const gchar *path);
int g_stat (const gchar *filename,
GStatBuf *buf);
int g_lstat (const gchar *filename,
GStatBuf *buf);
int g_unlink (const gchar *filename);
int g_remove (const gchar *filename);
int g_rmdir (const gchar *filename);
FILE *g_fopen (const gchar *filename,
const gchar *mode);
FILE *g_freopen (const gchar *filename,
const gchar *mode,
FILE *stream);
struct utimbuf; /* Don't need the real definition of struct utimbuf when just
* including this header.
*/
int g_utime (const gchar *filename,
struct utimbuf *utb);
#endif /* G_OS_UNIX */
G_END_DECLS
#endif /* __G_STDIO_H__ */

3251
deps/glib/gstrfuncs.c vendored Normal file

File diff suppressed because it is too large Load Diff

269
deps/glib/gstrfuncs.h vendored Normal file
View File

@ -0,0 +1,269 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_STRFUNCS_H__
#define __G_STRFUNCS_H__
#include <stdarg.h>
#include <glib/gmacros.h>
#include <glib/gtypes.h>
G_BEGIN_DECLS
/* Functions like the ones in <ctype.h> that are not affected by locale. */
typedef enum {
G_ASCII_ALNUM = 1 << 0,
G_ASCII_ALPHA = 1 << 1,
G_ASCII_CNTRL = 1 << 2,
G_ASCII_DIGIT = 1 << 3,
G_ASCII_GRAPH = 1 << 4,
G_ASCII_LOWER = 1 << 5,
G_ASCII_PRINT = 1 << 6,
G_ASCII_PUNCT = 1 << 7,
G_ASCII_SPACE = 1 << 8,
G_ASCII_UPPER = 1 << 9,
G_ASCII_XDIGIT = 1 << 10
} GAsciiType;
GLIB_VAR const guint16 * const g_ascii_table;
#define g_ascii_isalnum(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_ALNUM) != 0)
#define g_ascii_isalpha(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_ALPHA) != 0)
#define g_ascii_iscntrl(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_CNTRL) != 0)
#define g_ascii_isdigit(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_DIGIT) != 0)
#define g_ascii_isgraph(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_GRAPH) != 0)
#define g_ascii_islower(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_LOWER) != 0)
#define g_ascii_isprint(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_PRINT) != 0)
#define g_ascii_ispunct(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_PUNCT) != 0)
#define g_ascii_isspace(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_SPACE) != 0)
#define g_ascii_isupper(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_UPPER) != 0)
#define g_ascii_isxdigit(c) \
((g_ascii_table[(guchar) (c)] & G_ASCII_XDIGIT) != 0)
gchar g_ascii_tolower (gchar c) G_GNUC_CONST;
gchar g_ascii_toupper (gchar c) G_GNUC_CONST;
gint g_ascii_digit_value (gchar c) G_GNUC_CONST;
gint g_ascii_xdigit_value (gchar c) G_GNUC_CONST;
/* String utility functions that modify a string argument or
* return a constant string that must not be freed.
*/
#define G_STR_DELIMITERS "_-|> <."
gchar* g_strdelimit (gchar *string,
const gchar *delimiters,
gchar new_delimiter);
gchar* g_strcanon (gchar *string,
const gchar *valid_chars,
gchar substitutor);
const gchar * g_strerror (gint errnum) G_GNUC_CONST;
const gchar * g_strsignal (gint signum) G_GNUC_CONST;
gchar * g_strreverse (gchar *string);
gsize g_strlcpy (gchar *dest,
const gchar *src,
gsize dest_size);
gsize g_strlcat (gchar *dest,
const gchar *src,
gsize dest_size);
gchar * g_strstr_len (const gchar *haystack,
gssize haystack_len,
const gchar *needle);
gchar * g_strrstr (const gchar *haystack,
const gchar *needle);
gchar * g_strrstr_len (const gchar *haystack,
gssize haystack_len,
const gchar *needle);
gboolean g_str_has_suffix (const gchar *str,
const gchar *suffix);
gboolean g_str_has_prefix (const gchar *str,
const gchar *prefix);
/* String to/from double conversion functions */
gdouble g_strtod (const gchar *nptr,
gchar **endptr);
gdouble g_ascii_strtod (const gchar *nptr,
gchar **endptr);
guint64 g_ascii_strtoull (const gchar *nptr,
gchar **endptr,
guint base);
gint64 g_ascii_strtoll (const gchar *nptr,
gchar **endptr,
guint base);
/* 29 bytes should enough for all possible values that
* g_ascii_dtostr can produce.
* Then add 10 for good measure */
#define G_ASCII_DTOSTR_BUF_SIZE (29 + 10)
gchar * g_ascii_dtostr (gchar *buffer,
gint buf_len,
gdouble d);
gchar * g_ascii_formatd (gchar *buffer,
gint buf_len,
const gchar *format,
gdouble d);
/* removes leading spaces */
gchar* g_strchug (gchar *string);
/* removes trailing spaces */
gchar* g_strchomp (gchar *string);
/* removes leading & trailing spaces */
#define g_strstrip( string ) g_strchomp (g_strchug (string))
gint g_ascii_strcasecmp (const gchar *s1,
const gchar *s2);
gint g_ascii_strncasecmp (const gchar *s1,
const gchar *s2,
gsize n);
gchar* g_ascii_strdown (const gchar *str,
gssize len) G_GNUC_MALLOC;
gchar* g_ascii_strup (const gchar *str,
gssize len) G_GNUC_MALLOC;
#ifndef G_DISABLE_DEPRECATED
/* The following four functions are deprecated and will be removed in
* the next major release. They use the locale-specific tolower and
* toupper, which is almost never the right thing.
*/
gint g_strcasecmp (const gchar *s1,
const gchar *s2);
gint g_strncasecmp (const gchar *s1,
const gchar *s2,
guint n);
gchar* g_strdown (gchar *string);
gchar* g_strup (gchar *string);
#endif /* G_DISABLE_DEPRECATED */
/* String utility functions that return a newly allocated string which
* ought to be freed with g_free from the caller at some point.
*/
gchar* g_strdup (const gchar *str) G_GNUC_MALLOC;
gchar* g_strdup_printf (const gchar *format,
...) G_GNUC_PRINTF (1, 2) G_GNUC_MALLOC;
gchar* g_strdup_vprintf (const gchar *format,
va_list args) G_GNUC_MALLOC;
gchar* g_strndup (const gchar *str,
gsize n) G_GNUC_MALLOC;
gchar* g_strnfill (gsize length,
gchar fill_char) G_GNUC_MALLOC;
gchar* g_strconcat (const gchar *string1,
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
gchar* g_strjoin (const gchar *separator,
...) G_GNUC_MALLOC G_GNUC_NULL_TERMINATED;
/* Make a copy of a string interpreting C string -style escape
* sequences. Inverse of g_strescape. The recognized sequences are \b
* \f \n \r \t \\ \" and the octal format.
*/
gchar* g_strcompress (const gchar *source) G_GNUC_MALLOC;
/* Copy a string escaping nonprintable characters like in C strings.
* Inverse of g_strcompress. The exceptions parameter, if non-NULL, points
* to a string containing characters that are not to be escaped.
*
* Deprecated API: gchar* g_strescape (const gchar *source);
* Luckily this function wasn't used much, using NULL as second parameter
* provides mostly identical semantics.
*/
gchar* g_strescape (const gchar *source,
const gchar *exceptions) G_GNUC_MALLOC;
gpointer g_memdup (gconstpointer mem,
guint byte_size) G_GNUC_MALLOC G_GNUC_ALLOC_SIZE(2);
/* NULL terminated string arrays.
* g_strsplit(), g_strsplit_set() split up string into max_tokens tokens
* at delim and return a newly allocated string array.
* g_strjoinv() concatenates all of str_array's strings, sliding in an
* optional separator, the returned string is newly allocated.
* g_strfreev() frees the array itself and all of its strings.
* g_strdupv() copies a NULL-terminated array of strings
* g_strv_length() returns the length of a NULL-terminated array of strings
*/
gchar** g_strsplit (const gchar *string,
const gchar *delimiter,
gint max_tokens) G_GNUC_MALLOC;
gchar ** g_strsplit_set (const gchar *string,
const gchar *delimiters,
gint max_tokens) G_GNUC_MALLOC;
gchar* g_strjoinv (const gchar *separator,
gchar **str_array) G_GNUC_MALLOC;
void g_strfreev (gchar **str_array);
gchar** g_strdupv (gchar **str_array) G_GNUC_MALLOC;
guint g_strv_length (gchar **str_array);
gchar* g_stpcpy (gchar *dest,
const char *src);
const gchar * g_strip_context (const gchar *msgid,
const gchar *msgval) G_GNUC_FORMAT(1);
const gchar * g_dgettext (const gchar *domain,
const gchar *msgid) G_GNUC_FORMAT(2);
const gchar * g_dcgettext (const gchar *domain,
const gchar *msgid,
int category) G_GNUC_FORMAT(2);
const gchar * g_dngettext (const gchar *domain,
const gchar *msgid,
const gchar *msgid_plural,
gulong n) G_GNUC_FORMAT(3);
const gchar * g_dpgettext (const gchar *domain,
const gchar *msgctxtid,
gsize msgidoffset) G_GNUC_FORMAT(2);
const gchar * g_dpgettext2 (const gchar *domain,
const gchar *context,
const gchar *msgid) G_GNUC_FORMAT(3);
G_END_DECLS
#endif /* __G_STRFUNCS_H__ */

1448
deps/glib/gstring.c vendored Normal file

File diff suppressed because it is too large Load Diff

186
deps/glib/gstring.h vendored Normal file
View File

@ -0,0 +1,186 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_STRING_H__
#define __G_STRING_H__
#include <glib/gtypes.h>
#include <glib/gunicode.h>
#include <glib/gutils.h> /* for G_CAN_INLINE */
G_BEGIN_DECLS
typedef struct _GString GString;
typedef struct _GStringChunk GStringChunk;
/**
* GString:
* @str: points to the character data. It may move as text is added.
* The @str field is null-terminated and so
* can be used as an ordinary C string.
* @len: contains the length of the string, not including the
* terminating nul byte.
* @allocated_len: the number of bytes that can be stored in the
* string before it needs to be reallocated. May be larger than @len.
*
* The #GString struct contains the public fields of a #GString.
*/
struct _GString
{
gchar *str;
gsize len;
gsize allocated_len;
};
/* String Chunks
*/
GStringChunk* g_string_chunk_new (gsize size);
void g_string_chunk_free (GStringChunk *chunk);
void g_string_chunk_clear (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
gchar* g_string_chunk_insert_len (GStringChunk *chunk,
const gchar *string,
gssize len);
gchar* g_string_chunk_insert_const (GStringChunk *chunk,
const gchar *string);
/* Strings
*/
GString* g_string_new (const gchar *init);
GString* g_string_new_len (const gchar *init,
gssize len);
GString* g_string_sized_new (gsize dfl_size);
gchar* g_string_free (GString *string,
gboolean free_segment);
gboolean g_string_equal (const GString *v,
const GString *v2);
guint g_string_hash (const GString *str);
GString* g_string_assign (GString *string,
const gchar *rval);
GString* g_string_truncate (GString *string,
gsize len);
GString* g_string_set_size (GString *string,
gsize len);
GString* g_string_insert_len (GString *string,
gssize pos,
const gchar *val,
gssize len);
GString* g_string_append (GString *string,
const gchar *val);
GString* g_string_append_len (GString *string,
const gchar *val,
gssize len);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_append_unichar (GString *string,
gunichar wc);
GString* g_string_prepend (GString *string,
const gchar *val);
GString* g_string_prepend_c (GString *string,
gchar c);
GString* g_string_prepend_unichar (GString *string,
gunichar wc);
GString* g_string_prepend_len (GString *string,
const gchar *val,
gssize len);
GString* g_string_insert (GString *string,
gssize pos,
const gchar *val);
GString* g_string_insert_c (GString *string,
gssize pos,
gchar c);
GString* g_string_insert_unichar (GString *string,
gssize pos,
gunichar wc);
GString* g_string_overwrite (GString *string,
gsize pos,
const gchar *val);
GString* g_string_overwrite_len (GString *string,
gsize pos,
const gchar *val,
gssize len);
GString* g_string_erase (GString *string,
gssize pos,
gssize len);
GString* g_string_ascii_down (GString *string);
GString* g_string_ascii_up (GString *string);
void g_string_vprintf (GString *string,
const gchar *format,
va_list args);
void g_string_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
void g_string_append_vprintf (GString *string,
const gchar *format,
va_list args);
void g_string_append_printf (GString *string,
const gchar *format,
...) G_GNUC_PRINTF (2, 3);
/* -- optimize g_strig_append_c --- */
#ifdef G_CAN_INLINE
static inline GString*
g_string_append_c_inline (GString *gstring,
gchar c)
{
if (gstring->len + 1 < gstring->allocated_len)
{
gstring->str[gstring->len++] = c;
gstring->str[gstring->len] = 0;
}
else
g_string_insert_c (gstring, -1, c);
return gstring;
}
#define g_string_append_c(gstr,c) g_string_append_c_inline (gstr, c)
#endif /* G_CAN_INLINE */
#ifndef G_DISABLE_DEPRECATED
/* The following two functions are deprecated and will be removed in
* the next major release. They use the locale-specific tolower and
* toupper, which is almost never the right thing.
*/
GString* g_string_down (GString *string);
GString* g_string_up (GString *string);
/* These aliases are included for compatibility. */
#define g_string_sprintf g_string_printf
#define g_string_sprintfa g_string_append_printf
#endif /* G_DISABLE_DEPRECATED */
G_END_DECLS
#endif /* __G_STRING_H__ */

516
deps/glib/gtestutils.c vendored Normal file
View File

@ -0,0 +1,516 @@
/* GLib testing utilities
* Copyright (C) 2007 Imendio AB
* Authors: Tim Janik, Sven Herzberg
*
* 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 "gtestutils.h"
#include <sys/types.h>
#ifdef G_OS_UNIX
#include <sys/wait.h>
#include <sys/time.h>
#include <fcntl.h>
#endif
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_WIN32
#include <io.h>
#endif
#include <errno.h>
#include <signal.h>
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
#endif /* HAVE_SYS_SELECT_H */
#include "gmain.h"
#include "gstrfuncs.h"
/* Global variable for storing assertion messages; this is the counterpart to
* glibc's (private) __abort_msg variable, and allows developers and crash
* analysis systems like Apport and ABRT to fish out assertion messages from
* core dumps, instead of having to catch them on screen output. */
char *__glib_assert_msg = NULL;
static guint8* g_test_log_dump (GTestLogMsg *msg,
guint *len);
/* --- variables --- */
static int test_log_fd = -1;
static int test_trap_last_pid = 0;
static gboolean test_debug_log = FALSE;
/* --- functions --- */
const char*
g_test_log_type_name (GTestLogType log_type)
{
switch (log_type)
{
case G_TEST_LOG_NONE: return "none";
case G_TEST_LOG_ERROR: return "error";
}
return "???";
}
static void
g_test_log_send (guint n_bytes,
const guint8 *buffer)
{
if (test_log_fd >= 0)
{
int r;
do
r = write (test_log_fd, buffer, n_bytes);
while (r < 0 && errno == EINTR);
}
if (test_debug_log)
{
GTestLogBuffer *lbuffer = g_test_log_buffer_new ();
GTestLogMsg *msg;
guint ui;
g_test_log_buffer_push (lbuffer, n_bytes, buffer);
msg = g_test_log_buffer_pop (lbuffer);
g_warn_if_fail (msg != NULL);
g_warn_if_fail (lbuffer->data->len == 0);
g_test_log_buffer_free (lbuffer);
/* print message */
g_printerr ("{*LOG(%s)", g_test_log_type_name (msg->log_type));
for (ui = 0; ui < msg->n_strings; ui++)
g_printerr (":{%s}", msg->strings[ui]);
if (msg->n_nums)
{
g_printerr (":(");
for (ui = 0; ui < msg->n_nums; ui++)
g_printerr ("%s%.16Lg", ui ? ";" : "", msg->nums[ui]);
g_printerr (")");
}
g_printerr (":LOG*}\n");
g_test_log_msg_free (msg);
}
}
static void
g_test_log (GTestLogType lbit,
const gchar *string1,
const gchar *string2,
guint n_args,
long double *largs)
{
GTestLogMsg msg;
gchar *astrings[3] = { NULL, NULL, NULL };
guint8 *dbuffer;
guint32 dbufferlen;
msg.log_type = lbit;
msg.n_strings = (string1 != NULL) + (string1 && string2);
msg.strings = astrings;
astrings[0] = (gchar*) string1;
astrings[1] = astrings[0] ? (gchar*) string2 : NULL;
msg.n_nums = n_args;
msg.nums = largs;
dbuffer = g_test_log_dump (&msg, &dbufferlen);
g_test_log_send (dbufferlen, dbuffer);
g_free (dbuffer);
}
void
g_assertion_message (const char *domain,
const char *file,
int line,
const char *func,
const char *message)
{
char lstr[32];
char *s;
if (!message)
message = "code should not be reached";
g_snprintf (lstr, 32, "%d", line);
s = g_strconcat (domain ? domain : "", domain && domain[0] ? ":" : "",
"ERROR:", file, ":", lstr, ":",
func, func[0] ? ":" : "",
" ", message, NULL);
g_printerr ("**\n%s\n", s);
/* store assertion message in global variable, so that it can be found in a
* core dump */
if (__glib_assert_msg != NULL)
/* free the old one */
free (__glib_assert_msg);
__glib_assert_msg = (char*) malloc (strlen (s) + 1);
strcpy (__glib_assert_msg, s);
g_test_log (G_TEST_LOG_ERROR, s, NULL, 0, NULL);
g_free (s);
abort();
}
void
g_assertion_message_expr (const char *domain,
const char *file,
int line,
const char *func,
const char *expr)
{
char *s = g_strconcat ("assertion failed: (", expr, ")", NULL);
g_assertion_message (domain, file, line, func, s);
g_free (s);
}
void
g_assertion_message_cmpnum (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
long double arg1,
const char *cmp,
long double arg2,
char numtype)
{
char *s = NULL;
switch (numtype)
{
case 'i': s = g_strdup_printf ("assertion failed (%s): (%.0Lf %s %.0Lf)", expr, arg1, cmp, arg2); break;
case 'x': s = g_strdup_printf ("assertion failed (%s): (0x%08" G_GINT64_MODIFIER "x %s 0x%08" G_GINT64_MODIFIER "x)", expr, (guint64) arg1, cmp, (guint64) arg2); break;
case 'f': s = g_strdup_printf ("assertion failed (%s): (%.9Lg %s %.9Lg)", expr, arg1, cmp, arg2); break;
/* ideally use: floats=%.7g double=%.17g */
}
g_assertion_message (domain, file, line, func, s);
g_free (s);
}
void
g_assertion_message_cmpstr (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const char *arg1,
const char *cmp,
const char *arg2)
{
char *a1, *a2, *s, *t1 = NULL, *t2 = NULL;
a1 = arg1 ? g_strconcat ("\"", t1 = g_strescape (arg1, NULL), "\"", NULL) : g_strdup ("NULL");
a2 = arg2 ? g_strconcat ("\"", t2 = g_strescape (arg2, NULL), "\"", NULL) : g_strdup ("NULL");
g_free (t1);
g_free (t2);
s = g_strdup_printf ("assertion failed (%s): (%s %s %s)", expr, a1, cmp, a2);
g_free (a1);
g_free (a2);
g_assertion_message (domain, file, line, func, s);
g_free (s);
}
void
g_assertion_message_error (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const GError *error,
GQuark error_domain,
int error_code)
{
GString *gstring;
/* This is used by both g_assert_error() and g_assert_no_error(), so there
* are three cases: expected an error but got the wrong error, expected
* an error but got no error, and expected no error but got an error.
*/
gstring = g_string_new ("assertion failed ");
if (error_domain)
g_string_append_printf (gstring, "(%s == (%s, %d)): ", expr,
g_quark_to_string (error_domain), error_code);
else
g_string_append_printf (gstring, "(%s == NULL): ", expr);
if (error)
g_string_append_printf (gstring, "%s (%s, %d)", error->message,
g_quark_to_string (error->domain), error->code);
else
g_string_append_printf (gstring, "%s is NULL", expr);
g_assertion_message (domain, file, line, func, gstring->str);
g_string_free (gstring, TRUE);
}
/**
* g_strcmp0:
* @str1: a C string or %NULL
* @str2: another C string or %NULL
*
* Compares @str1 and @str2 like strcmp(). Handles %NULL
* gracefully by sorting it before non-%NULL strings.
* Comparing two %NULL pointers returns 0.
*
* Returns: -1, 0 or 1, if @str1 is <, == or > than @str2.
*
* Since: 2.16
*/
int
g_strcmp0 (const char *str1,
const char *str2)
{
if (!str1)
return -(str1 != str2);
if (!str2)
return str1 != str2;
return strcmp (str1, str2);
}
static inline int
g_string_must_read (GString *gstring,
int fd)
{
#define STRING_BUFFER_SIZE 4096
char buf[STRING_BUFFER_SIZE];
gssize bytes;
again:
bytes = read (fd, buf, sizeof (buf));
if (bytes == 0)
return 0; /* EOF, calling this function assumes data is available */
else if (bytes > 0)
{
g_string_append_len (gstring, buf, bytes);
return 1;
}
else if (bytes < 0 && errno == EINTR)
goto again;
else /* bytes < 0 */
{
g_warning ("failed to read() from child process (%d): %s", test_trap_last_pid, g_strerror (errno));
return 1; /* ignore error after warning */
}
}
static inline void
g_string_write_out (GString *gstring,
int outfd,
int *stringpos)
{
if (*stringpos < gstring->len)
{
int r;
do
r = write (outfd, gstring->str + *stringpos, gstring->len - *stringpos);
while (r < 0 && errno == EINTR);
*stringpos += MAX (r, 0);
}
}
static void
gstring_overwrite_int (GString *gstring,
guint pos,
guint32 vuint)
{
vuint = g_htonl (vuint);
g_string_overwrite_len (gstring, pos, (const gchar*) &vuint, 4);
}
static void
gstring_append_int (GString *gstring,
guint32 vuint)
{
vuint = g_htonl (vuint);
g_string_append_len (gstring, (const gchar*) &vuint, 4);
}
static void
gstring_append_double (GString *gstring,
double vdouble)
{
union { double vdouble; guint64 vuint64; } u;
u.vdouble = vdouble;
u.vuint64 = GUINT64_TO_BE (u.vuint64);
g_string_append_len (gstring, (const gchar*) &u.vuint64, 8);
}
static guint8*
g_test_log_dump (GTestLogMsg *msg,
guint *len)
{
GString *gstring = g_string_sized_new (1024);
guint ui;
gstring_append_int (gstring, 0); /* message length */
gstring_append_int (gstring, msg->log_type);
gstring_append_int (gstring, msg->n_strings);
gstring_append_int (gstring, msg->n_nums);
gstring_append_int (gstring, 0); /* reserved */
for (ui = 0; ui < msg->n_strings; ui++)
{
guint l = strlen (msg->strings[ui]);
gstring_append_int (gstring, l);
g_string_append_len (gstring, msg->strings[ui], l);
}
for (ui = 0; ui < msg->n_nums; ui++)
gstring_append_double (gstring, msg->nums[ui]);
*len = gstring->len;
gstring_overwrite_int (gstring, 0, *len); /* message length */
return (guint8*) g_string_free (gstring, FALSE);
}
static inline long double
net_double (const gchar **ipointer)
{
union { guint64 vuint64; double vdouble; } u;
guint64 aligned_int64;
memcpy (&aligned_int64, *ipointer, 8);
*ipointer += 8;
u.vuint64 = GUINT64_FROM_BE (aligned_int64);
return u.vdouble;
}
static inline guint32
net_int (const gchar **ipointer)
{
guint32 aligned_int;
memcpy (&aligned_int, *ipointer, 4);
*ipointer += 4;
return g_ntohl (aligned_int);
}
static gboolean
g_test_log_extract (GTestLogBuffer *tbuffer)
{
const gchar *p = tbuffer->data->str;
GTestLogMsg msg;
guint mlength;
if (tbuffer->data->len < 4 * 5)
return FALSE;
mlength = net_int (&p);
if (tbuffer->data->len < mlength)
return FALSE;
msg.log_type = net_int (&p);
msg.n_strings = net_int (&p);
msg.n_nums = net_int (&p);
if (net_int (&p) == 0)
{
guint ui;
msg.strings = g_new0 (gchar*, msg.n_strings + 1);
msg.nums = g_new0 (long double, msg.n_nums);
for (ui = 0; ui < msg.n_strings; ui++)
{
guint sl = net_int (&p);
msg.strings[ui] = g_strndup (p, sl);
p += sl;
}
for (ui = 0; ui < msg.n_nums; ui++)
msg.nums[ui] = net_double (&p);
if (p <= tbuffer->data->str + mlength)
{
g_string_erase (tbuffer->data, 0, mlength);
tbuffer->msgs = g_slist_prepend (tbuffer->msgs, g_memdup (&msg, sizeof (msg)));
return TRUE;
}
}
g_free (msg.nums);
g_strfreev (msg.strings);
g_error ("corrupt log stream from test program");
return FALSE;
}
/**
* g_test_log_buffer_new:
*
* Internal function for gtester to decode test log messages, no ABI guarantees provided.
*/
GTestLogBuffer*
g_test_log_buffer_new (void)
{
GTestLogBuffer *tb = g_new0 (GTestLogBuffer, 1);
tb->data = g_string_sized_new (1024);
return tb;
}
/**
* g_test_log_buffer_free
*
* Internal function for gtester to free test log messages, no ABI guarantees provided.
*/
void
g_test_log_buffer_free (GTestLogBuffer *tbuffer)
{
g_return_if_fail (tbuffer != NULL);
while (tbuffer->msgs)
g_test_log_msg_free (g_test_log_buffer_pop (tbuffer));
g_string_free (tbuffer->data, TRUE);
g_free (tbuffer);
}
/**
* g_test_log_buffer_push
*
* Internal function for gtester to decode test log messages, no ABI guarantees provided.
*/
void
g_test_log_buffer_push (GTestLogBuffer *tbuffer,
guint n_bytes,
const guint8 *bytes)
{
g_return_if_fail (tbuffer != NULL);
if (n_bytes)
{
gboolean more_messages;
g_return_if_fail (bytes != NULL);
g_string_append_len (tbuffer->data, (const gchar*) bytes, n_bytes);
do
more_messages = g_test_log_extract (tbuffer);
while (more_messages);
}
}
/**
* g_test_log_buffer_pop:
*
* Internal function for gtester to retrieve test log messages, no ABI guarantees provided.
*/
GTestLogMsg*
g_test_log_buffer_pop (GTestLogBuffer *tbuffer)
{
GTestLogMsg *msg = NULL;
g_return_val_if_fail (tbuffer != NULL, NULL);
if (tbuffer->msgs)
{
GSList *slist = g_slist_last (tbuffer->msgs);
msg = slist->data;
tbuffer->msgs = g_slist_delete_link (tbuffer->msgs, slist);
}
return msg;
}
/**
* g_test_log_msg_free:
*
* Internal function for gtester to free test log messages, no ABI guarantees provided.
*/
void
g_test_log_msg_free (GTestLogMsg *tmsg)
{
g_return_if_fail (tmsg != NULL);
g_strfreev (tmsg->strings);
g_free (tmsg->nums);
g_free (tmsg);
}

161
deps/glib/gtestutils.h vendored Normal file
View File

@ -0,0 +1,161 @@
/* GLib testing utilities
* Copyright (C) 2007 Imendio AB
* Authors: Tim Janik
*
* 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.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_TEST_UTILS_H__
#define __G_TEST_UTILS_H__
#include <glib/gmessages.h>
#include <glib/gstring.h>
#include <glib/gerror.h>
#include <glib/gslist.h>
G_BEGIN_DECLS
/* assertion API */
#define g_assert_cmpstr(s1, cmp, s2) do { const char *__s1 = (s1), *__s2 = (s2); \
if (g_strcmp0 (__s1, __s2) cmp 0) ; else \
g_assertion_message_cmpstr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#s1 " " #cmp " " #s2, __s1, #cmp, __s2); } while (0)
#define g_assert_cmpint(n1, cmp, n2) do { gint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0)
#define g_assert_cmpuint(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'i'); } while (0)
#define g_assert_cmphex(n1, cmp, n2) do { guint64 __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'x'); } while (0)
#define g_assert_cmpfloat(n1,cmp,n2) do { long double __n1 = (n1), __n2 = (n2); \
if (__n1 cmp __n2) ; else \
g_assertion_message_cmpnum (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#n1 " " #cmp " " #n2, __n1, #cmp, __n2, 'f'); } while (0)
#define g_assert_no_error(err) do { if (err) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#err, err, 0, 0); } while (0)
#define g_assert_error(err, dom, c) do { if (!err || (err)->domain != dom || (err)->code != c) \
g_assertion_message_error (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#err, err, dom, c); } while (0)
#ifdef G_DISABLE_ASSERT
#define g_assert_not_reached() do { (void) 0; } while (0)
#define g_assert(expr) do { (void) 0; } while (0)
#else /* !G_DISABLE_ASSERT */
#define g_assert_not_reached() do { g_assertion_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, NULL); } while (0)
#define g_assert(expr) do { if G_LIKELY (expr) ; else \
g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, \
#expr); } while (0)
#endif /* !G_DISABLE_ASSERT */
int g_strcmp0 (const char *str1,
const char *str2);
void g_assertion_message (const char *domain,
const char *file,
int line,
const char *func,
const char *message) G_GNUC_NORETURN;
void g_assertion_message_expr (const char *domain,
const char *file,
int line,
const char *func,
const char *expr) G_GNUC_NORETURN;
void g_assertion_message_cmpstr (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const char *arg1,
const char *cmp,
const char *arg2) G_GNUC_NORETURN;
void g_assertion_message_cmpnum (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
long double arg1,
const char *cmp,
long double arg2,
char numtype) G_GNUC_NORETURN;
void g_assertion_message_error (const char *domain,
const char *file,
int line,
const char *func,
const char *expr,
const GError *error,
GQuark error_domain,
int error_code) G_GNUC_NORETURN;
/* internal logging API */
typedef enum {
G_TEST_LOG_NONE,
G_TEST_LOG_ERROR, /* s:msg */
} GTestLogType;
typedef struct {
GTestLogType log_type;
guint n_strings;
gchar **strings; /* NULL terminated */
guint n_nums;
long double *nums;
} GTestLogMsg;
typedef struct {
/*< private >*/
GString *data;
GSList *msgs;
} GTestLogBuffer;
const char* g_test_log_type_name (GTestLogType log_type);
GTestLogBuffer* g_test_log_buffer_new (void);
void g_test_log_buffer_free (GTestLogBuffer *tbuffer);
void g_test_log_buffer_push (GTestLogBuffer *tbuffer,
guint n_bytes,
const guint8 *bytes);
GTestLogMsg* g_test_log_buffer_pop (GTestLogBuffer *tbuffer);
void g_test_log_msg_free (GTestLogMsg *tmsg);
/**
* GTestLogFatalFunc:
* @log_domain: the log domain of the message
* @log_level: the log level of the message (including the fatal and recursion flags)
* @message: the message to process
* @user_data: user data, set in g_test_log_set_fatal_handler()
*
* Specifies the prototype of fatal log handler functions.
*
* Return value: %TRUE if the program should abort, %FALSE otherwise
*
* Since: 2.22
*/
typedef gboolean (*GTestLogFatalFunc) (const gchar *log_domain,
GLogLevelFlags log_level,
const gchar *message,
gpointer user_data);
void
g_test_log_set_fatal_handler (GTestLogFatalFunc log_func,
gpointer user_data);
G_END_DECLS
#endif /* __G_TEST_UTILS_H__ */

2601
deps/glib/gthread.c vendored Normal file

File diff suppressed because it is too large Load Diff

407
deps/glib/gthread.h vendored Normal file
View File

@ -0,0 +1,407 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_THREAD_H__
#define __G_THREAD_H__
#include <glib/gerror.h>
#include <glib/gutils.h> /* for G_INLINE_FUNC */
#include <glib/gatomic.h> /* for g_atomic_pointer_get */
G_BEGIN_DECLS
/* GLib Thread support
*/
extern GQuark g_thread_error_quark (void);
#define G_THREAD_ERROR g_thread_error_quark ()
typedef enum
{
G_THREAD_ERROR_AGAIN /* Resource temporarily unavailable */
} GThreadError;
typedef gpointer (*GThreadFunc) (gpointer data);
typedef enum
{
G_THREAD_PRIORITY_LOW,
G_THREAD_PRIORITY_NORMAL,
G_THREAD_PRIORITY_HIGH,
G_THREAD_PRIORITY_URGENT
} GThreadPriority;
typedef struct _GThread GThread;
struct _GThread
{
/*< private >*/
GThreadFunc func;
gpointer data;
gboolean joinable;
GThreadPriority priority;
};
typedef struct _GMutex GMutex;
typedef struct _GCond GCond;
typedef struct _GPrivate GPrivate;
typedef struct _GStaticPrivate GStaticPrivate;
typedef struct _GThreadFunctions GThreadFunctions;
struct _GThreadFunctions
{
GMutex* (*mutex_new) (void);
void (*mutex_lock) (GMutex *mutex);
gboolean (*mutex_trylock) (GMutex *mutex);
void (*mutex_unlock) (GMutex *mutex);
void (*mutex_free) (GMutex *mutex);
GCond* (*cond_new) (void);
void (*cond_signal) (GCond *cond);
void (*cond_broadcast) (GCond *cond);
void (*cond_wait) (GCond *cond,
GMutex *mutex);
gboolean (*cond_timed_wait) (GCond *cond,
GMutex *mutex,
GTimeVal *end_time);
void (*cond_free) (GCond *cond);
GPrivate* (*private_new) (GDestroyNotify destructor);
gpointer (*private_get) (GPrivate *private_key);
void (*private_set) (GPrivate *private_key,
gpointer data);
void (*thread_create) (GThreadFunc func,
gpointer data,
gulong stack_size,
gboolean joinable,
gboolean bound,
GThreadPriority priority,
gpointer thread,
GError **error);
void (*thread_yield) (void);
void (*thread_join) (gpointer thread);
void (*thread_exit) (void);
void (*thread_set_priority)(gpointer thread,
GThreadPriority priority);
void (*thread_self) (gpointer thread);
gboolean (*thread_equal) (gpointer thread1,
gpointer thread2);
};
GLIB_VAR GThreadFunctions g_thread_functions_for_glib_use;
GLIB_VAR gboolean g_thread_use_default_impl;
GLIB_VAR gboolean g_threads_got_initialized;
GLIB_VAR guint64 (*g_thread_gettime) (void);
/* initializes the mutex/cond/private implementation for glib, might
* only be called once, and must not be called directly or indirectly
* from another glib-function, e.g. as a callback.
*/
void g_thread_init (GThreadFunctions *vtable);
/* Errorcheck mutexes. If you define G_ERRORCHECK_MUTEXES, then all
* mutexes will check for re-locking and re-unlocking */
/* Initialize thread system with errorcheck mutexes. vtable must be
* NULL. Do not call directly. Use #define G_ERRORCHECK_MUTEXES
* instead.
*/
void g_thread_init_with_errorcheck_mutexes (GThreadFunctions* vtable);
/* Checks if thread support is initialized. Identical to the
* g_thread_supported macro but provided for language bindings.
*/
gboolean g_thread_get_initialized (void);
/* A random number to recognize debug calls to g_mutex_... */
#define G_MUTEX_DEBUG_MAGIC 0xf8e18ad7
#ifdef G_ERRORCHECK_MUTEXES
#define g_thread_init(vtable) g_thread_init_with_errorcheck_mutexes (vtable)
#endif
/* internal function for fallback static mutex implementation */
GMutex* g_static_mutex_get_mutex_impl (GMutex **mutex);
#define g_static_mutex_get_mutex_impl_shortcut(mutex) \
(g_atomic_pointer_get (mutex) ? *(mutex) : \
g_static_mutex_get_mutex_impl (mutex))
/* shorthands for conditional and unconditional function calls */
#define G_THREAD_UF(op, arglist) \
(*g_thread_functions_for_glib_use . op) arglist
#define G_THREAD_CF(op, fail, arg) \
(g_thread_supported () ? G_THREAD_UF (op, arg) : (fail))
#define G_THREAD_ECF(op, fail, mutex, type) \
(g_thread_supported () ? \
((type(*)(GMutex*, const gulong, gchar const*)) \
(*g_thread_functions_for_glib_use . op)) \
(mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (fail))
#ifndef G_ERRORCHECK_MUTEXES
# define g_mutex_lock(mutex) \
G_THREAD_CF (mutex_lock, (void)0, (mutex))
# define g_mutex_trylock(mutex) \
G_THREAD_CF (mutex_trylock, TRUE, (mutex))
# define g_mutex_unlock(mutex) \
G_THREAD_CF (mutex_unlock, (void)0, (mutex))
# define g_mutex_free(mutex) \
G_THREAD_CF (mutex_free, (void)0, (mutex))
# define g_cond_wait(cond, mutex) \
G_THREAD_CF (cond_wait, (void)0, (cond, mutex))
# define g_cond_timed_wait(cond, mutex, abs_time) \
G_THREAD_CF (cond_timed_wait, TRUE, (cond, mutex, abs_time))
#else /* G_ERRORCHECK_MUTEXES */
# define g_mutex_lock(mutex) \
G_THREAD_ECF (mutex_lock, (void)0, (mutex), void)
# define g_mutex_trylock(mutex) \
G_THREAD_ECF (mutex_trylock, TRUE, (mutex), gboolean)
# define g_mutex_unlock(mutex) \
G_THREAD_ECF (mutex_unlock, (void)0, (mutex), void)
# define g_mutex_free(mutex) \
G_THREAD_ECF (mutex_free, (void)0, (mutex), void)
# define g_cond_wait(cond, mutex) \
(g_thread_supported () ? ((void(*)(GCond*, GMutex*, gulong, gchar*))\
g_thread_functions_for_glib_use.cond_wait) \
(cond, mutex, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : (void) 0)
# define g_cond_timed_wait(cond, mutex, abs_time) \
(g_thread_supported () ? \
((gboolean(*)(GCond*, GMutex*, GTimeVal*, gulong, gchar*)) \
g_thread_functions_for_glib_use.cond_timed_wait) \
(cond, mutex, abs_time, G_MUTEX_DEBUG_MAGIC, G_STRLOC) : TRUE)
#endif /* G_ERRORCHECK_MUTEXES */
#if defined(G_THREADS_ENABLED) && defined(G_THREADS_MANDATORY)
#define g_thread_supported() 1
#else
#define g_thread_supported() (g_threads_got_initialized)
#endif
#define g_mutex_new() G_THREAD_UF (mutex_new, ())
#define g_cond_new() G_THREAD_UF (cond_new, ())
#define g_cond_signal(cond) G_THREAD_CF (cond_signal, (void)0, (cond))
#define g_cond_broadcast(cond) G_THREAD_CF (cond_broadcast, (void)0, (cond))
#define g_cond_free(cond) G_THREAD_CF (cond_free, (void)0, (cond))
#define g_private_new(destructor) G_THREAD_UF (private_new, (destructor))
#define g_private_get(private_key) G_THREAD_CF (private_get, \
((gpointer)private_key), \
(private_key))
#define g_private_set(private_key, value) G_THREAD_CF (private_set, \
(void) (private_key = \
(GPrivate*) (value)), \
(private_key, value))
#define g_thread_yield() G_THREAD_CF (thread_yield, (void)0, ())
#define g_thread_create(func, data, joinable, error) \
(g_thread_create_full (func, data, 0, joinable, FALSE, \
G_THREAD_PRIORITY_NORMAL, error))
GThread* g_thread_create_full (GThreadFunc func,
gpointer data,
gulong stack_size,
gboolean joinable,
gboolean bound,
GThreadPriority priority,
GError **error);
GThread* g_thread_self (void);
void g_thread_exit (gpointer retval);
gpointer g_thread_join (GThread *thread);
void g_thread_set_priority (GThread *thread,
GThreadPriority priority);
/* GStaticMutexes can be statically initialized with the value
* G_STATIC_MUTEX_INIT, and then they can directly be used, that is
* much easier, than having to explicitly allocate the mutex before
* use
*/
#define g_static_mutex_lock(mutex) \
g_mutex_lock (g_static_mutex_get_mutex (mutex))
#define g_static_mutex_trylock(mutex) \
g_mutex_trylock (g_static_mutex_get_mutex (mutex))
#define g_static_mutex_unlock(mutex) \
g_mutex_unlock (g_static_mutex_get_mutex (mutex))
void g_static_mutex_init (GStaticMutex *mutex);
void g_static_mutex_free (GStaticMutex *mutex);
struct _GStaticPrivate
{
/*< private >*/
guint index;
};
#define G_STATIC_PRIVATE_INIT { 0 }
void g_static_private_init (GStaticPrivate *private_key);
gpointer g_static_private_get (GStaticPrivate *private_key);
void g_static_private_set (GStaticPrivate *private_key,
gpointer data,
GDestroyNotify notify);
void g_static_private_free (GStaticPrivate *private_key);
typedef struct _GStaticRecMutex GStaticRecMutex;
struct _GStaticRecMutex
{
/*< private >*/
GStaticMutex mutex;
guint depth;
GSystemThread owner;
};
#define G_STATIC_REC_MUTEX_INIT { G_STATIC_MUTEX_INIT, 0, {{0, 0, 0, 0}} }
void g_static_rec_mutex_init (GStaticRecMutex *mutex);
void g_static_rec_mutex_lock (GStaticRecMutex *mutex);
gboolean g_static_rec_mutex_trylock (GStaticRecMutex *mutex);
void g_static_rec_mutex_unlock (GStaticRecMutex *mutex);
void g_static_rec_mutex_lock_full (GStaticRecMutex *mutex,
guint depth);
guint g_static_rec_mutex_unlock_full (GStaticRecMutex *mutex);
void g_static_rec_mutex_free (GStaticRecMutex *mutex);
typedef struct _GStaticRWLock GStaticRWLock;
struct _GStaticRWLock
{
/*< private >*/
GStaticMutex mutex;
GCond *read_cond;
GCond *write_cond;
guint read_counter;
gboolean have_writer;
guint want_to_read;
guint want_to_write;
};
#define G_STATIC_RW_LOCK_INIT { G_STATIC_MUTEX_INIT, NULL, NULL, 0, FALSE, 0, 0 }
void g_static_rw_lock_init (GStaticRWLock* lock);
void g_static_rw_lock_reader_lock (GStaticRWLock* lock);
gboolean g_static_rw_lock_reader_trylock (GStaticRWLock* lock);
void g_static_rw_lock_reader_unlock (GStaticRWLock* lock);
void g_static_rw_lock_writer_lock (GStaticRWLock* lock);
gboolean g_static_rw_lock_writer_trylock (GStaticRWLock* lock);
void g_static_rw_lock_writer_unlock (GStaticRWLock* lock);
void g_static_rw_lock_free (GStaticRWLock* lock);
void g_thread_foreach (GFunc thread_func,
gpointer user_data);
typedef enum
{
G_ONCE_STATUS_NOTCALLED,
G_ONCE_STATUS_PROGRESS,
G_ONCE_STATUS_READY
} GOnceStatus;
typedef struct _GOnce GOnce;
struct _GOnce
{
volatile GOnceStatus status;
volatile gpointer retval;
};
#define G_ONCE_INIT { G_ONCE_STATUS_NOTCALLED, NULL }
gpointer g_once_impl (GOnce *once, GThreadFunc func, gpointer arg);
#ifdef G_ATOMIC_OP_MEMORY_BARRIER_NEEDED
# define g_once(once, func, arg) g_once_impl ((once), (func), (arg))
#else /* !G_ATOMIC_OP_MEMORY_BARRIER_NEEDED*/
# define g_once(once, func, arg) \
(((once)->status == G_ONCE_STATUS_READY) ? \
(once)->retval : \
g_once_impl ((once), (func), (arg)))
#endif /* G_ATOMIC_OP_MEMORY_BARRIER_NEEDED */
/* initialize-once guards, keyed by value_location */
G_INLINE_FUNC gboolean g_once_init_enter (volatile gsize *value_location);
gboolean g_once_init_enter_impl (volatile gsize *value_location);
void g_once_init_leave (volatile gsize *value_location,
gsize initialization_value);
#if defined (G_CAN_INLINE) || defined (__G_THREAD_C__)
G_INLINE_FUNC gboolean
g_once_init_enter (volatile gsize *value_location)
{
if G_LIKELY ((gpointer) g_atomic_pointer_get (value_location) != NULL)
return FALSE;
else
return g_once_init_enter_impl (value_location);
}
#endif /* G_CAN_INLINE || __G_THREAD_C__ */
/* these are some convenience macros that expand to nothing if GLib
* was configured with --disable-threads. for using StaticMutexes,
* you define them with G_LOCK_DEFINE_STATIC (name) or G_LOCK_DEFINE (name)
* if you need to export the mutex. With G_LOCK_EXTERN (name) you can
* declare such an globally defined lock. name is a unique identifier
* for the protected varibale or code portion. locking, testing and
* unlocking of such mutexes can be done with G_LOCK(), G_UNLOCK() and
* G_TRYLOCK() respectively.
*/
extern void glib_dummy_decl (void);
#define G_LOCK_NAME(name) g__ ## name ## _lock
#ifdef G_THREADS_ENABLED
# define G_LOCK_DEFINE_STATIC(name) static G_LOCK_DEFINE (name)
# define G_LOCK_DEFINE(name) \
GStaticMutex G_LOCK_NAME (name) = G_STATIC_MUTEX_INIT
# define G_LOCK_EXTERN(name) extern GStaticMutex G_LOCK_NAME (name)
# ifdef G_DEBUG_LOCKS
# define G_LOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s): locking: %s ", \
__FILE__, __LINE__, G_STRFUNC, \
#name); \
g_static_mutex_lock (&G_LOCK_NAME (name)); \
}G_STMT_END
# define G_UNLOCK(name) G_STMT_START{ \
g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s): unlocking: %s ", \
__FILE__, __LINE__, G_STRFUNC, \
#name); \
g_static_mutex_unlock (&G_LOCK_NAME (name)); \
}G_STMT_END
# define G_TRYLOCK(name) \
(g_log (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, \
"file %s: line %d (%s): try locking: %s ", \
__FILE__, __LINE__, G_STRFUNC, \
#name), g_static_mutex_trylock (&G_LOCK_NAME (name)))
# else /* !G_DEBUG_LOCKS */
# define G_LOCK(name) g_static_mutex_lock (&G_LOCK_NAME (name))
# define G_UNLOCK(name) g_static_mutex_unlock (&G_LOCK_NAME (name))
# define G_TRYLOCK(name) g_static_mutex_trylock (&G_LOCK_NAME (name))
# endif /* !G_DEBUG_LOCKS */
#else /* !G_THREADS_ENABLED */
# define G_LOCK_DEFINE_STATIC(name) extern void glib_dummy_decl (void)
# define G_LOCK_DEFINE(name) extern void glib_dummy_decl (void)
# define G_LOCK_EXTERN(name) extern void glib_dummy_decl (void)
# define G_LOCK(name)
# define G_UNLOCK(name)
# define G_TRYLOCK(name) (TRUE)
#endif /* !G_THREADS_ENABLED */
G_END_DECLS
#endif /* __G_THREAD_H__ */

69
deps/glib/gthreadprivate.h vendored Normal file
View File

@ -0,0 +1,69 @@
/* GLIB - Library of useful routines for C programming
*
* gthreadprivate.h - GLib internal thread system related declarations.
*
* Copyright (C) 2003 Sebastian Wilhelmi
*
* The Gnome 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.
*
* The Gnome 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 the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifndef __G_THREADPRIVATE_H__
#define __G_THREADPRIVATE_H__
G_BEGIN_DECLS
/* System thread identifier comparison and assignment */
#if GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P
# define g_system_thread_equal_simple(thread1, thread2) \
((thread1).dummy_pointer == (thread2).dummy_pointer)
# define g_system_thread_assign(dest, src) \
((dest).dummy_pointer = (src).dummy_pointer)
#else /* GLIB_SIZEOF_SYSTEM_THREAD != SIZEOF_VOID_P */
# define g_system_thread_equal_simple(thread1, thread2) \
(memcmp (&(thread1), &(thread2), GLIB_SIZEOF_SYSTEM_THREAD) == 0)
# define g_system_thread_assign(dest, src) \
(memcpy (&(dest), &(src), GLIB_SIZEOF_SYSTEM_THREAD))
#endif /* GLIB_SIZEOF_SYSTEM_THREAD == SIZEOF_VOID_P */
#define g_system_thread_equal(thread1, thread2) \
(g_thread_functions_for_glib_use.thread_equal ? \
g_thread_functions_for_glib_use.thread_equal (&(thread1), &(thread2)) :\
g_system_thread_equal_simple((thread1), (thread2)))
/* Is called from gthread/gthread-impl.c */
void g_thread_init_glib (void);
/* base initializers, may only use g_mutex_new(), g_cond_new() */
G_GNUC_INTERNAL void _g_mem_thread_init_noprivate_nomessage (void);
/* initializers that may also use g_private_new() */
G_GNUC_INTERNAL void _g_slice_thread_init_nomessage (void);
G_GNUC_INTERNAL void _g_messages_thread_init_nomessage (void);
/* full fledged initializers */
G_GNUC_INTERNAL void _g_convert_thread_init (void);
G_GNUC_INTERNAL void _g_rand_thread_init (void);
G_GNUC_INTERNAL void _g_main_thread_init (void);
G_GNUC_INTERNAL void _g_atomic_thread_init (void);
G_GNUC_INTERNAL void _g_utils_thread_init (void);
G_GNUC_INTERNAL void _g_futex_thread_init (void);
#ifdef G_OS_WIN32
G_GNUC_INTERNAL void _g_win32_thread_init (void);
#endif /* G_OS_WIN32 */
G_END_DECLS
#endif /* __G_THREADPRIVATE_H__ */

461
deps/glib/gtypes.h vendored Normal file
View File

@ -0,0 +1,461 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_TYPES_H__
#define __G_TYPES_H__
#include <glibconfig.h>
#include <glib/gmacros.h>
#include <time.h>
G_BEGIN_DECLS
/* Provide type definitions for commonly used types.
* These are useful because a "gint8" can be adjusted
* to be 1 byte (8 bits) on all platforms. Similarly and
* more importantly, "gint32" can be adjusted to be
* 4 bytes (32 bits) on all platforms.
*/
typedef char gchar;
typedef short gshort;
typedef long glong;
typedef int gint;
typedef gint gboolean;
typedef unsigned char guchar;
typedef unsigned short gushort;
typedef unsigned long gulong;
typedef unsigned int guint;
typedef float gfloat;
typedef double gdouble;
/* Define min and max constants for the fixed size numerical types */
#define G_MININT8 ((gint8) 0x80)
#define G_MAXINT8 ((gint8) 0x7f)
#define G_MAXUINT8 ((guint8) 0xff)
#define G_MININT16 ((gint16) 0x8000)
#define G_MAXINT16 ((gint16) 0x7fff)
#define G_MAXUINT16 ((guint16) 0xffff)
#define G_MININT32 ((gint32) 0x80000000)
#define G_MAXINT32 ((gint32) 0x7fffffff)
#define G_MAXUINT32 ((guint32) 0xffffffff)
#define G_MININT64 ((gint64) G_GINT64_CONSTANT(0x8000000000000000))
#define G_MAXINT64 G_GINT64_CONSTANT(0x7fffffffffffffff)
#define G_MAXUINT64 G_GINT64_CONSTANT(0xffffffffffffffffU)
typedef void* gpointer;
typedef const void *gconstpointer;
typedef gint (*GCompareFunc) (gconstpointer a,
gconstpointer b);
typedef gint (*GCompareDataFunc) (gconstpointer a,
gconstpointer b,
gpointer user_data);
typedef gboolean (*GEqualFunc) (gconstpointer a,
gconstpointer b);
typedef void (*GDestroyNotify) (gpointer data);
typedef void (*GFunc) (gpointer data,
gpointer user_data);
typedef guint (*GHashFunc) (gconstpointer key);
typedef void (*GHFunc) (gpointer key,
gpointer value,
gpointer user_data);
/**
* GFreeFunc:
* @data: a data pointer
*
* Declares a type of function which takes an arbitrary
* data pointer argument and has no return value. It is
* not currently used in GLib or GTK+.
*/
typedef void (*GFreeFunc) (gpointer data);
/**
* GTranslateFunc:
* @str: the untranslated string
* @data: user data specified when installing the function, e.g.
* in g_option_group_set_translate_func()
*
* The type of functions which are used to translate user-visible
* strings, for <option>--help</option> output.
*
* Returns: a translation of the string for the current locale.
* The returned string is owned by GLib and must not be freed.
*/
typedef const gchar * (*GTranslateFunc) (const gchar *str,
gpointer data);
/* Define some mathematical constants that aren't available
* symbolically in some strict ISO C implementations.
*
* Note that the large number of digits used in these definitions
* doesn't imply that GLib or current computers in general would be
* able to handle floating point numbers with an accuracy like this.
* It's mostly an exercise in futility and future proofing. For
* extended precision floating point support, look somewhere else
* than GLib.
*/
#define G_E 2.7182818284590452353602874713526624977572470937000
#define G_LN2 0.69314718055994530941723212145817656807550013436026
#define G_LN10 2.3025850929940456840179914546843642076011014886288
#define G_PI 3.1415926535897932384626433832795028841971693993751
#define G_PI_2 1.5707963267948966192313216916397514420985846996876
#define G_PI_4 0.78539816339744830961566084581987572104929234984378
#define G_SQRT2 1.4142135623730950488016887242096980785696718753769
/* Portable endian checks and conversions
*
* glibconfig.h defines G_BYTE_ORDER which expands to one of
* the below macros.
*/
#define G_LITTLE_ENDIAN 1234
#define G_BIG_ENDIAN 4321
#define G_PDP_ENDIAN 3412 /* unused, need specific PDP check */
/* Basic bit swapping functions
*/
#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
(guint16) ((guint16) (val) >> 8) | \
(guint16) ((guint16) (val) << 8)))
#define GUINT32_SWAP_LE_BE_CONSTANT(val) ((guint32) ( \
(((guint32) (val) & (guint32) 0x000000ffU) << 24) | \
(((guint32) (val) & (guint32) 0x0000ff00U) << 8) | \
(((guint32) (val) & (guint32) 0x00ff0000U) >> 8) | \
(((guint32) (val) & (guint32) 0xff000000U) >> 24)))
#define GUINT64_SWAP_LE_BE_CONSTANT(val) ((guint64) ( \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x00000000000000ffU)) << 56) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x000000000000ff00U)) << 40) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x0000000000ff0000U)) << 24) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x00000000ff000000U)) << 8) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x000000ff00000000U)) >> 8) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x0000ff0000000000U)) >> 24) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0x00ff000000000000U)) >> 40) | \
(((guint64) (val) & \
(guint64) G_GINT64_CONSTANT (0xff00000000000000U)) >> 56)))
/* Arch specific stuff for speed
*/
#if defined (__GNUC__) && (__GNUC__ >= 2) && defined (__OPTIMIZE__)
# if defined (__i386__)
# define GUINT16_SWAP_LE_BE_IA32(val) \
(G_GNUC_EXTENSION \
({ register guint16 __v, __x = ((guint16) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ ("rorw $8, %w0" \
: "=r" (__v) \
: "0" (__x) \
: "cc"); \
__v; }))
# if !defined (__i486__) && !defined (__i586__) \
&& !defined (__pentium__) && !defined (__i686__) \
&& !defined (__pentiumpro__) && !defined (__pentium4__)
# define GUINT32_SWAP_LE_BE_IA32(val) \
(G_GNUC_EXTENSION \
({ register guint32 __v, __x = ((guint32) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ ("rorw $8, %w0\n\t" \
"rorl $16, %0\n\t" \
"rorw $8, %w0" \
: "=r" (__v) \
: "0" (__x) \
: "cc"); \
__v; }))
# else /* 486 and higher has bswap */
# define GUINT32_SWAP_LE_BE_IA32(val) \
(G_GNUC_EXTENSION \
({ register guint32 __v, __x = ((guint32) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ ("bswap %0" \
: "=r" (__v) \
: "0" (__x)); \
__v; }))
# endif /* processor specific 32-bit stuff */
# define GUINT64_SWAP_LE_BE_IA32(val) \
(G_GNUC_EXTENSION \
({ union { guint64 __ll; \
guint32 __l[2]; } __w, __r; \
__w.__ll = ((guint64) (val)); \
if (__builtin_constant_p (__w.__ll)) \
__r.__ll = GUINT64_SWAP_LE_BE_CONSTANT (__w.__ll); \
else \
{ \
__r.__l[0] = GUINT32_SWAP_LE_BE (__w.__l[1]); \
__r.__l[1] = GUINT32_SWAP_LE_BE (__w.__l[0]); \
} \
__r.__ll; }))
/* Possibly just use the constant version and let gcc figure it out? */
# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA32 (val))
# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA32 (val))
# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA32 (val))
# elif defined (__ia64__)
# define GUINT16_SWAP_LE_BE_IA64(val) \
(G_GNUC_EXTENSION \
({ register guint16 __v, __x = ((guint16) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT16_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ __volatile__ ("shl %0 = %1, 48 ;;" \
"mux1 %0 = %0, @rev ;;" \
: "=r" (__v) \
: "r" (__x)); \
__v; }))
# define GUINT32_SWAP_LE_BE_IA64(val) \
(G_GNUC_EXTENSION \
({ register guint32 __v, __x = ((guint32) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ __volatile__ ("shl %0 = %1, 32 ;;" \
"mux1 %0 = %0, @rev ;;" \
: "=r" (__v) \
: "r" (__x)); \
__v; }))
# define GUINT64_SWAP_LE_BE_IA64(val) \
(G_GNUC_EXTENSION \
({ register guint64 __v, __x = ((guint64) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ __volatile__ ("mux1 %0 = %1, @rev ;;" \
: "=r" (__v) \
: "r" (__x)); \
__v; }))
# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_IA64 (val))
# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_IA64 (val))
# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_IA64 (val))
# elif defined (__x86_64__)
# define GUINT32_SWAP_LE_BE_X86_64(val) \
(G_GNUC_EXTENSION \
({ register guint32 __v, __x = ((guint32) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT32_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ ("bswapl %0" \
: "=r" (__v) \
: "0" (__x)); \
__v; }))
# define GUINT64_SWAP_LE_BE_X86_64(val) \
(G_GNUC_EXTENSION \
({ register guint64 __v, __x = ((guint64) (val)); \
if (__builtin_constant_p (__x)) \
__v = GUINT64_SWAP_LE_BE_CONSTANT (__x); \
else \
__asm__ ("bswapq %0" \
: "=r" (__v) \
: "0" (__x)); \
__v; }))
/* gcc seems to figure out optimal code for this on its own */
# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_X86_64 (val))
# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_X86_64 (val))
# else /* generic gcc */
# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
# endif
#else /* generic */
# define GUINT16_SWAP_LE_BE(val) (GUINT16_SWAP_LE_BE_CONSTANT (val))
# define GUINT32_SWAP_LE_BE(val) (GUINT32_SWAP_LE_BE_CONSTANT (val))
# define GUINT64_SWAP_LE_BE(val) (GUINT64_SWAP_LE_BE_CONSTANT (val))
#endif /* generic */
#define GUINT16_SWAP_LE_PDP(val) ((guint16) (val))
#define GUINT16_SWAP_BE_PDP(val) (GUINT16_SWAP_LE_BE (val))
#define GUINT32_SWAP_LE_PDP(val) ((guint32) ( \
(((guint32) (val) & (guint32) 0x0000ffffU) << 16) | \
(((guint32) (val) & (guint32) 0xffff0000U) >> 16)))
#define GUINT32_SWAP_BE_PDP(val) ((guint32) ( \
(((guint32) (val) & (guint32) 0x00ff00ffU) << 8) | \
(((guint32) (val) & (guint32) 0xff00ff00U) >> 8)))
/* The G*_TO_?E() macros are defined in glibconfig.h.
* The transformation is symmetric, so the FROM just maps to the TO.
*/
#define GINT16_FROM_LE(val) (GINT16_TO_LE (val))
#define GUINT16_FROM_LE(val) (GUINT16_TO_LE (val))
#define GINT16_FROM_BE(val) (GINT16_TO_BE (val))
#define GUINT16_FROM_BE(val) (GUINT16_TO_BE (val))
#define GINT32_FROM_LE(val) (GINT32_TO_LE (val))
#define GUINT32_FROM_LE(val) (GUINT32_TO_LE (val))
#define GINT32_FROM_BE(val) (GINT32_TO_BE (val))
#define GUINT32_FROM_BE(val) (GUINT32_TO_BE (val))
#define GINT64_FROM_LE(val) (GINT64_TO_LE (val))
#define GUINT64_FROM_LE(val) (GUINT64_TO_LE (val))
#define GINT64_FROM_BE(val) (GINT64_TO_BE (val))
#define GUINT64_FROM_BE(val) (GUINT64_TO_BE (val))
#define GLONG_FROM_LE(val) (GLONG_TO_LE (val))
#define GULONG_FROM_LE(val) (GULONG_TO_LE (val))
#define GLONG_FROM_BE(val) (GLONG_TO_BE (val))
#define GULONG_FROM_BE(val) (GULONG_TO_BE (val))
#define GINT_FROM_LE(val) (GINT_TO_LE (val))
#define GUINT_FROM_LE(val) (GUINT_TO_LE (val))
#define GINT_FROM_BE(val) (GINT_TO_BE (val))
#define GUINT_FROM_BE(val) (GUINT_TO_BE (val))
#define GSIZE_FROM_LE(val) (GSIZE_TO_LE (val))
#define GSSIZE_FROM_LE(val) (GSSIZE_TO_LE (val))
#define GSIZE_FROM_BE(val) (GSIZE_TO_BE (val))
#define GSSIZE_FROM_BE(val) (GSSIZE_TO_BE (val))
/* Portable versions of host-network order stuff
*/
#define g_ntohl(val) (GUINT32_FROM_BE (val))
#define g_ntohs(val) (GUINT16_FROM_BE (val))
#define g_htonl(val) (GUINT32_TO_BE (val))
#define g_htons(val) (GUINT16_TO_BE (val))
/* IEEE Standard 754 Single Precision Storage Format (gfloat):
*
* 31 30 23 22 0
* +--------+---------------+---------------+
* | s 1bit | e[30:23] 8bit | f[22:0] 23bit |
* +--------+---------------+---------------+
* B0------------------->B1------->B2-->B3-->
*
* IEEE Standard 754 Double Precision Storage Format (gdouble):
*
* 63 62 52 51 32 31 0
* +--------+----------------+----------------+ +---------------+
* | s 1bit | e[62:52] 11bit | f[51:32] 20bit | | f[31:0] 32bit |
* +--------+----------------+----------------+ +---------------+
* B0--------------->B1---------->B2--->B3----> B4->B5->B6->B7->
*/
/* subtract from biased_exponent to form base2 exponent (normal numbers) */
typedef union _GDoubleIEEE754 GDoubleIEEE754;
typedef union _GFloatIEEE754 GFloatIEEE754;
#define G_IEEE754_FLOAT_BIAS (127)
#define G_IEEE754_DOUBLE_BIAS (1023)
/* multiply with base2 exponent to get base10 exponent (normal numbers) */
#define G_LOG_2_BASE_10 (0.30102999566398119521)
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
union _GFloatIEEE754
{
gfloat v_float;
struct {
guint mantissa : 23;
guint biased_exponent : 8;
guint sign : 1;
} mpn;
};
union _GDoubleIEEE754
{
gdouble v_double;
struct {
guint mantissa_low : 32;
guint mantissa_high : 20;
guint biased_exponent : 11;
guint sign : 1;
} mpn;
};
#elif G_BYTE_ORDER == G_BIG_ENDIAN
union _GFloatIEEE754
{
gfloat v_float;
struct {
guint sign : 1;
guint biased_exponent : 8;
guint mantissa : 23;
} mpn;
};
union _GDoubleIEEE754
{
gdouble v_double;
struct {
guint sign : 1;
guint biased_exponent : 11;
guint mantissa_high : 20;
guint mantissa_low : 32;
} mpn;
};
#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
#error unknown ENDIAN type
#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
typedef struct _GTimeVal GTimeVal;
struct _GTimeVal
{
glong tv_sec;
glong tv_usec;
};
G_END_DECLS
/* We prefix variable declarations so they can
* properly get exported in Windows DLLs.
*/
#ifndef GLIB_VAR
# ifdef G_PLATFORM_WIN32
# ifdef GLIB_STATIC_COMPILATION
# define GLIB_VAR extern
# else /* !GLIB_STATIC_COMPILATION */
# ifdef GLIB_COMPILATION
# ifdef DLL_EXPORT
# define GLIB_VAR __declspec(dllexport)
# else /* !DLL_EXPORT */
# define GLIB_VAR extern
# endif /* !DLL_EXPORT */
# else /* !GLIB_COMPILATION */
# define GLIB_VAR extern __declspec(dllimport)
# endif /* !GLIB_COMPILATION */
# endif /* !GLIB_STATIC_COMPILATION */
# else /* !G_PLATFORM_WIN32 */
# define GLIB_VAR extern
# endif /* !G_PLATFORM_WIN32 */
#endif /* GLIB_VAR */
#endif /* __G_TYPES_H__ */

729
deps/glib/gunicode.h vendored Normal file
View File

@ -0,0 +1,729 @@
/* gunicode.h - Unicode manipulation functions
*
* Copyright (C) 1999, 2000 Tom Tromey
* Copyright 2000, 2005 Red Hat, Inc.
*
* The Gnome 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.
*
* The Gnome 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 the Gnome Library; see the file COPYING.LIB. If not,
* write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_UNICODE_H__
#define __G_UNICODE_H__
#include <glib/gerror.h>
#include <glib/gtypes.h>
G_BEGIN_DECLS
/**
* gunichar:
*
* A type which can hold any UTF-32 or UCS-4 character code,
* also known as a Unicode code point.
*
* If you want to produce the UTF-8 representation of a #gunichar,
* use g_ucs4_to_utf8(). See also g_utf8_to_ucs4() for the reverse
* process.
*
* To print/scan values of this type as integer, use
* %G_GINT32_MODIFIER and/or %G_GUINT32_FORMAT.
*
* The notation to express a Unicode code point in running text is
* as a hexadecimal number with four to six digits and uppercase
* letters, prefixed by the string "U+". Leading zeros are omitted,
* unless the code point would have fewer than four hexadecimal digits.
* For example, "U+0041 LATIN CAPITAL LETTER A". To print a code point
* in the U+-notation, use the format string "U+\%04"G_GINT32_FORMAT"X".
* To scan, use the format string "U+\%06"G_GINT32_FORMAT"X".
*
* |[
* gunichar c;
* sscanf ("U+0041", "U+%06"G_GINT32_FORMAT"X", &amp;c)
* g_print ("Read U+%04"G_GINT32_FORMAT"X", c);
* ]|
*/
typedef guint32 gunichar;
/**
* gunichar2:
*
* A type which can hold any UTF-16 code
* point<footnote id="utf16_surrogate_pairs">UTF-16 also has so called
* <firstterm>surrogate pairs</firstterm> to encode characters beyond
* the BMP as pairs of 16bit numbers. Surrogate pairs cannot be stored
* in a single gunichar2 field, but all GLib functions accepting gunichar2
* arrays will correctly interpret surrogate pairs.</footnote>.
*
* To print/scan values of this type to/from text you need to convert
* to/from UTF-8, using g_utf16_to_utf8()/g_utf8_to_utf16().
*
* To print/scan values of this type as integer, use
* %G_GINT16_MODIFIER and/or %G_GUINT16_FORMAT.
*/
typedef guint16 gunichar2;
/**
* GUnicodeType:
* @G_UNICODE_CONTROL: General category "Other, Control" (Cc)
* @G_UNICODE_FORMAT: General category "Other, Format" (Cf)
* @G_UNICODE_UNASSIGNED: General category "Other, Not Assigned" (Cn)
* @G_UNICODE_PRIVATE_USE: General category "Other, Private Use" (Co)
* @G_UNICODE_SURROGATE: General category "Other, Surrogate" (Cs)
* @G_UNICODE_LOWERCASE_LETTER: General category "Letter, Lowercase" (Ll)
* @G_UNICODE_MODIFIER_LETTER: General category "Letter, Modifier" (Lm)
* @G_UNICODE_OTHER_LETTER: General category "Letter, Other" (Lo)
* @G_UNICODE_TITLECASE_LETTER: General category "Letter, Titlecase" (Lt)
* @G_UNICODE_UPPERCASE_LETTER: General category "Letter, Uppercase" (Lu)
* @G_UNICODE_SPACING_MARK: General category "Mark, Spacing" (Mc)
* @G_UNICODE_ENCLOSING_MARK: General category "Mark, Enclosing" (Me)
* @G_UNICODE_NON_SPACING_MARK: General category "Mark, Nonspacing" (Mn)
* @G_UNICODE_DECIMAL_NUMBER: General category "Number, Decimal Digit" (Nd)
* @G_UNICODE_LETTER_NUMBER: General category "Number, Letter" (Nl)
* @G_UNICODE_OTHER_NUMBER: General category "Number, Other" (No)
* @G_UNICODE_CONNECT_PUNCTUATION: General category "Punctuation, Connector" (Pc)
* @G_UNICODE_DASH_PUNCTUATION: General category "Punctuation, Dash" (Pd)
* @G_UNICODE_CLOSE_PUNCTUATION: General category "Punctuation, Close" (Pe)
* @G_UNICODE_FINAL_PUNCTUATION: General category "Punctuation, Final quote" (Pf)
* @G_UNICODE_INITIAL_PUNCTUATION: General category "Punctuation, Initial quote" (Pi)
* @G_UNICODE_OTHER_PUNCTUATION: General category "Punctuation, Other" (Po)
* @G_UNICODE_OPEN_PUNCTUATION: General category "Punctuation, Open" (Ps)
* @G_UNICODE_CURRENCY_SYMBOL: General category "Symbol, Currency" (Sc)
* @G_UNICODE_MODIFIER_SYMBOL: General category "Symbol, Modifier" (Sk)
* @G_UNICODE_MATH_SYMBOL: General category "Symbol, Math" (Sm)
* @G_UNICODE_OTHER_SYMBOL: General category "Symbol, Other" (So)
* @G_UNICODE_LINE_SEPARATOR: General category "Separator, Line" (Zl)
* @G_UNICODE_PARAGRAPH_SEPARATOR: General category "Separator, Paragraph" (Zp)
* @G_UNICODE_SPACE_SEPARATOR: General category "Separator, Space" (Zs)
*
* These are the possible character classifications from the
* Unicode specification.
* See <ulink url="http://www.unicode.org/Public/UNIDATA/UnicodeData.html">http://www.unicode.org/Public/UNIDATA/UnicodeData.html</ulink>.
*/
typedef enum
{
G_UNICODE_CONTROL,
G_UNICODE_FORMAT,
G_UNICODE_UNASSIGNED,
G_UNICODE_PRIVATE_USE,
G_UNICODE_SURROGATE,
G_UNICODE_LOWERCASE_LETTER,
G_UNICODE_MODIFIER_LETTER,
G_UNICODE_OTHER_LETTER,
G_UNICODE_TITLECASE_LETTER,
G_UNICODE_UPPERCASE_LETTER,
G_UNICODE_SPACING_MARK,
G_UNICODE_ENCLOSING_MARK,
G_UNICODE_NON_SPACING_MARK,
G_UNICODE_DECIMAL_NUMBER,
G_UNICODE_LETTER_NUMBER,
G_UNICODE_OTHER_NUMBER,
G_UNICODE_CONNECT_PUNCTUATION,
G_UNICODE_DASH_PUNCTUATION,
G_UNICODE_CLOSE_PUNCTUATION,
G_UNICODE_FINAL_PUNCTUATION,
G_UNICODE_INITIAL_PUNCTUATION,
G_UNICODE_OTHER_PUNCTUATION,
G_UNICODE_OPEN_PUNCTUATION,
G_UNICODE_CURRENCY_SYMBOL,
G_UNICODE_MODIFIER_SYMBOL,
G_UNICODE_MATH_SYMBOL,
G_UNICODE_OTHER_SYMBOL,
G_UNICODE_LINE_SEPARATOR,
G_UNICODE_PARAGRAPH_SEPARATOR,
G_UNICODE_SPACE_SEPARATOR
} GUnicodeType;
/**
* G_UNICODE_COMBINING_MARK:
*
* Older name for %G_UNICODE_SPACING_MARK.
*
* Deprecated: 2.30: Use %G_UNICODE_SPACING_MARK.
*/
#ifndef G_DISABLE_DEPRECATED
#define G_UNICODE_COMBINING_MARK G_UNICODE_SPACING_MARK
#endif
/**
* GUnicodeBreakType:
* @G_UNICODE_BREAK_MANDATORY: Mandatory Break (BK)
* @G_UNICODE_BREAK_CARRIAGE_RETURN: Carriage Return (CR)
* @G_UNICODE_BREAK_LINE_FEED: Line Feed (LF)
* @G_UNICODE_BREAK_COMBINING_MARK: Attached Characters and Combining Marks (CM)
* @G_UNICODE_BREAK_SURROGATE: Surrogates (SG)
* @G_UNICODE_BREAK_ZERO_WIDTH_SPACE: Zero Width Space (ZW)
* @G_UNICODE_BREAK_INSEPARABLE: Inseparable (IN)
* @G_UNICODE_BREAK_NON_BREAKING_GLUE: Non-breaking ("Glue") (GL)
* @G_UNICODE_BREAK_CONTINGENT: Contingent Break Opportunity (CB)
* @G_UNICODE_BREAK_SPACE: Space (SP)
* @G_UNICODE_BREAK_AFTER: Break Opportunity After (BA)
* @G_UNICODE_BREAK_BEFORE: Break Opportunity Before (BB)
* @G_UNICODE_BREAK_BEFORE_AND_AFTER: Break Opportunity Before and After (B2)
* @G_UNICODE_BREAK_HYPHEN: Hyphen (HY)
* @G_UNICODE_BREAK_NON_STARTER: Nonstarter (NS)
* @G_UNICODE_BREAK_OPEN_PUNCTUATION: Opening Punctuation (OP)
* @G_UNICODE_BREAK_CLOSE_PUNCTUATION: Closing Punctuation (CL)
* @G_UNICODE_BREAK_QUOTATION: Ambiguous Quotation (QU)
* @G_UNICODE_BREAK_EXCLAMATION: Exclamation/Interrogation (EX)
* @G_UNICODE_BREAK_IDEOGRAPHIC: Ideographic (ID)
* @G_UNICODE_BREAK_NUMERIC: Numeric (NU)
* @G_UNICODE_BREAK_INFIX_SEPARATOR: Infix Separator (Numeric) (IS)
* @G_UNICODE_BREAK_SYMBOL: Symbols Allowing Break After (SY)
* @G_UNICODE_BREAK_ALPHABETIC: Ordinary Alphabetic and Symbol Characters (AL)
* @G_UNICODE_BREAK_PREFIX: Prefix (Numeric) (PR)
* @G_UNICODE_BREAK_POSTFIX: Postfix (Numeric) (PO)
* @G_UNICODE_BREAK_COMPLEX_CONTEXT: Complex Content Dependent (South East Asian) (SA)
* @G_UNICODE_BREAK_AMBIGUOUS: Ambiguous (Alphabetic or Ideographic) (AI)
* @G_UNICODE_BREAK_UNKNOWN: Unknown (XX)
* @G_UNICODE_BREAK_NEXT_LINE: Next Line (NL)
* @G_UNICODE_BREAK_WORD_JOINER: Word Joiner (WJ)
* @G_UNICODE_BREAK_HANGUL_L_JAMO: Hangul L Jamo (JL)
* @G_UNICODE_BREAK_HANGUL_V_JAMO: Hangul V Jamo (JV)
* @G_UNICODE_BREAK_HANGUL_T_JAMO: Hangul T Jamo (JT)
* @G_UNICODE_BREAK_HANGUL_LV_SYLLABLE: Hangul LV Syllable (H2)
* @G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE: Hangul LVT Syllable (H3)
* @G_UNICODE_BREAK_CLOSE_PARANTHESIS: Closing Parenthesis (CP). Since 2.28
*
* These are the possible line break classifications.
*
* The five Hangul types were added in Unicode 4.1, so, has been
* introduced in GLib 2.10. Note that new types may be added in the future.
* Applications should be ready to handle unknown values.
* They may be regarded as %G_UNICODE_BREAK_UNKNOWN.
*
* See <ulink url="http://www.unicode.org/unicode/reports/tr14/">http://www.unicode.org/unicode/reports/tr14/</ulink>.
*/
typedef enum
{
G_UNICODE_BREAK_MANDATORY,
G_UNICODE_BREAK_CARRIAGE_RETURN,
G_UNICODE_BREAK_LINE_FEED,
G_UNICODE_BREAK_COMBINING_MARK,
G_UNICODE_BREAK_SURROGATE,
G_UNICODE_BREAK_ZERO_WIDTH_SPACE,
G_UNICODE_BREAK_INSEPARABLE,
G_UNICODE_BREAK_NON_BREAKING_GLUE,
G_UNICODE_BREAK_CONTINGENT,
G_UNICODE_BREAK_SPACE,
G_UNICODE_BREAK_AFTER,
G_UNICODE_BREAK_BEFORE,
G_UNICODE_BREAK_BEFORE_AND_AFTER,
G_UNICODE_BREAK_HYPHEN,
G_UNICODE_BREAK_NON_STARTER,
G_UNICODE_BREAK_OPEN_PUNCTUATION,
G_UNICODE_BREAK_CLOSE_PUNCTUATION,
G_UNICODE_BREAK_QUOTATION,
G_UNICODE_BREAK_EXCLAMATION,
G_UNICODE_BREAK_IDEOGRAPHIC,
G_UNICODE_BREAK_NUMERIC,
G_UNICODE_BREAK_INFIX_SEPARATOR,
G_UNICODE_BREAK_SYMBOL,
G_UNICODE_BREAK_ALPHABETIC,
G_UNICODE_BREAK_PREFIX,
G_UNICODE_BREAK_POSTFIX,
G_UNICODE_BREAK_COMPLEX_CONTEXT,
G_UNICODE_BREAK_AMBIGUOUS,
G_UNICODE_BREAK_UNKNOWN,
G_UNICODE_BREAK_NEXT_LINE,
G_UNICODE_BREAK_WORD_JOINER,
G_UNICODE_BREAK_HANGUL_L_JAMO,
G_UNICODE_BREAK_HANGUL_V_JAMO,
G_UNICODE_BREAK_HANGUL_T_JAMO,
G_UNICODE_BREAK_HANGUL_LV_SYLLABLE,
G_UNICODE_BREAK_HANGUL_LVT_SYLLABLE,
G_UNICODE_BREAK_CLOSE_PARANTHESIS
} GUnicodeBreakType;
/**
* GUnicodeScript:
* @G_UNICODE_SCRIPT_INVALID_CODE:
* a value never returned from g_unichar_get_script()
* @G_UNICODE_SCRIPT_COMMON: a character used by multiple different scripts
* @G_UNICODE_SCRIPT_INHERITED: a mark glyph that takes its script from the
* i base glyph to which it is attached
* @G_UNICODE_SCRIPT_ARABIC: Arabic
* @G_UNICODE_SCRIPT_ARMENIAN: Armenian
* @G_UNICODE_SCRIPT_BENGALI: Bengali
* @G_UNICODE_SCRIPT_BOPOMOFO: Bopomofo
* @G_UNICODE_SCRIPT_CHEROKEE: Cherokee
* @G_UNICODE_SCRIPT_COPTIC: Coptic
* @G_UNICODE_SCRIPT_CYRILLIC: Cyrillic
* @G_UNICODE_SCRIPT_DESERET: Deseret
* @G_UNICODE_SCRIPT_DEVANAGARI: Devanagari
* @G_UNICODE_SCRIPT_ETHIOPIC: Ethiopic
* @G_UNICODE_SCRIPT_GEORGIAN: Georgian
* @G_UNICODE_SCRIPT_GOTHIC: Gothic
* @G_UNICODE_SCRIPT_GREEK: Greek
* @G_UNICODE_SCRIPT_GUJARATI: Gujarati
* @G_UNICODE_SCRIPT_GURMUKHI: Gurmukhi
* @G_UNICODE_SCRIPT_HAN: Han
* @G_UNICODE_SCRIPT_HANGUL: Hangul
* @G_UNICODE_SCRIPT_HEBREW: Hebrew
* @G_UNICODE_SCRIPT_HIRAGANA: Hiragana
* @G_UNICODE_SCRIPT_KANNADA: Kannada
* @G_UNICODE_SCRIPT_KATAKANA: Katakana
* @G_UNICODE_SCRIPT_KHMER: Khmer
* @G_UNICODE_SCRIPT_LAO: Lao
* @G_UNICODE_SCRIPT_LATIN: Latin
* @G_UNICODE_SCRIPT_MALAYALAM: Malayalam
* @G_UNICODE_SCRIPT_MONGOLIAN: Mongolian
* @G_UNICODE_SCRIPT_MYANMAR: Myanmar
* @G_UNICODE_SCRIPT_OGHAM: Ogham
* @G_UNICODE_SCRIPT_OLD_ITALIC: Old Italic
* @G_UNICODE_SCRIPT_ORIYA: Oriya
* @G_UNICODE_SCRIPT_RUNIC: Runic
* @G_UNICODE_SCRIPT_SINHALA: Sinhala
* @G_UNICODE_SCRIPT_SYRIAC: Syriac
* @G_UNICODE_SCRIPT_TAMIL: Tamil
* @G_UNICODE_SCRIPT_TELUGU: Telugu
* @G_UNICODE_SCRIPT_THAANA: Thaana
* @G_UNICODE_SCRIPT_THAI: Thai
* @G_UNICODE_SCRIPT_TIBETAN: Tibetan
* @G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL:
* Canadian Aboriginal
* @G_UNICODE_SCRIPT_YI: Yi
* @G_UNICODE_SCRIPT_TAGALOG: Tagalog
* @G_UNICODE_SCRIPT_HANUNOO: Hanunoo
* @G_UNICODE_SCRIPT_BUHID: Buhid
* @G_UNICODE_SCRIPT_TAGBANWA: Tagbanwa
* @G_UNICODE_SCRIPT_BRAILLE: Braille
* @G_UNICODE_SCRIPT_CYPRIOT: Cypriot
* @G_UNICODE_SCRIPT_LIMBU: Limbu
* @G_UNICODE_SCRIPT_OSMANYA: Osmanya
* @G_UNICODE_SCRIPT_SHAVIAN: Shavian
* @G_UNICODE_SCRIPT_LINEAR_B: Linear B
* @G_UNICODE_SCRIPT_TAI_LE: Tai Le
* @G_UNICODE_SCRIPT_UGARITIC: Ugaritic
* @G_UNICODE_SCRIPT_NEW_TAI_LUE:
* New Tai Lue
* @G_UNICODE_SCRIPT_BUGINESE: Buginese
* @G_UNICODE_SCRIPT_GLAGOLITIC: Glagolitic
* @G_UNICODE_SCRIPT_TIFINAGH: Tifinagh
* @G_UNICODE_SCRIPT_SYLOTI_NAGRI:
* Syloti Nagri
* @G_UNICODE_SCRIPT_OLD_PERSIAN:
* Old Persian
* @G_UNICODE_SCRIPT_KHAROSHTHI: Kharoshthi
* @G_UNICODE_SCRIPT_UNKNOWN: an unassigned code point
* @G_UNICODE_SCRIPT_BALINESE: Balinese
* @G_UNICODE_SCRIPT_CUNEIFORM: Cuneiform
* @G_UNICODE_SCRIPT_PHOENICIAN: Phoenician
* @G_UNICODE_SCRIPT_PHAGS_PA: Phags-pa
* @G_UNICODE_SCRIPT_NKO: N'Ko
* @G_UNICODE_SCRIPT_KAYAH_LI: Kayah Li. Since 2.16.3
* @G_UNICODE_SCRIPT_LEPCHA: Lepcha. Since 2.16.3
* @G_UNICODE_SCRIPT_REJANG: Rejang. Since 2.16.3
* @G_UNICODE_SCRIPT_SUNDANESE: Sundanese. Since 2.16.3
* @G_UNICODE_SCRIPT_SAURASHTRA: Saurashtra. Since 2.16.3
* @G_UNICODE_SCRIPT_CHAM: Cham. Since 2.16.3
* @G_UNICODE_SCRIPT_OL_CHIKI: Ol Chiki. Since 2.16.3
* @G_UNICODE_SCRIPT_VAI: Vai. Since 2.16.3
* @G_UNICODE_SCRIPT_CARIAN: Carian. Since 2.16.3
* @G_UNICODE_SCRIPT_LYCIAN: Lycian. Since 2.16.3
* @G_UNICODE_SCRIPT_LYDIAN: Lydian. Since 2.16.3
* @G_UNICODE_SCRIPT_AVESTAN: Avestan. Since 2.26
* @G_UNICODE_SCRIPT_BAMUM: Bamum. Since 2.26
* @G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS:
* Egyptian Hieroglpyhs. Since 2.26
* @G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC:
* Imperial Aramaic. Since 2.26
* @G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI:
* Inscriptional Pahlavi. Since 2.26
* @G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN:
* Inscriptional Parthian. Since 2.26
* @G_UNICODE_SCRIPT_JAVANESE: Javanese. Since 2.26
* @G_UNICODE_SCRIPT_KAITHI: Kaithi. Since 2.26
* @G_UNICODE_SCRIPT_LISU: Lisu. Since 2.26
* @G_UNICODE_SCRIPT_MEETEI_MAYEK:
* Meetei Mayek. Since 2.26
* @G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN:
* Old South Arabian. Since 2.26
* @G_UNICODE_SCRIPT_OLD_TURKIC: Old Turkic. Since 2.28
* @G_UNICODE_SCRIPT_SAMARITAN: Samaritan. Since 2.26
* @G_UNICODE_SCRIPT_TAI_THAM: Tai Tham. Since 2.26
* @G_UNICODE_SCRIPT_TAI_VIET: Tai Viet. Since 2.26
* @G_UNICODE_SCRIPT_BATAK: Batak. Since 2.28
* @G_UNICODE_SCRIPT_BRAHMI: Brahmi. Since 2.28
* @G_UNICODE_SCRIPT_MANDAIC: Mandaic. Since 2.28
*
* The #GUnicodeScript enumeration identifies different writing
* systems. The values correspond to the names as defined in the
* Unicode standard. The enumeration has been added in GLib 2.14,
* and is interchangeable with #PangoScript.
*
* Note that new types may be added in the future. Applications
* should be ready to handle unknown values.
* See <ulink
* url="http://www.unicode.org/reports/tr24/">Unicode Standard Annex
* #24: Script names</ulink>.
*/
typedef enum
{ /* ISO 15924 code */
G_UNICODE_SCRIPT_INVALID_CODE = -1,
G_UNICODE_SCRIPT_COMMON = 0, /* Zyyy */
G_UNICODE_SCRIPT_INHERITED, /* Qaai */
G_UNICODE_SCRIPT_ARABIC, /* Arab */
G_UNICODE_SCRIPT_ARMENIAN, /* Armn */
G_UNICODE_SCRIPT_BENGALI, /* Beng */
G_UNICODE_SCRIPT_BOPOMOFO, /* Bopo */
G_UNICODE_SCRIPT_CHEROKEE, /* Cher */
G_UNICODE_SCRIPT_COPTIC, /* Qaac */
G_UNICODE_SCRIPT_CYRILLIC, /* Cyrl (Cyrs) */
G_UNICODE_SCRIPT_DESERET, /* Dsrt */
G_UNICODE_SCRIPT_DEVANAGARI, /* Deva */
G_UNICODE_SCRIPT_ETHIOPIC, /* Ethi */
G_UNICODE_SCRIPT_GEORGIAN, /* Geor (Geon, Geoa) */
G_UNICODE_SCRIPT_GOTHIC, /* Goth */
G_UNICODE_SCRIPT_GREEK, /* Grek */
G_UNICODE_SCRIPT_GUJARATI, /* Gujr */
G_UNICODE_SCRIPT_GURMUKHI, /* Guru */
G_UNICODE_SCRIPT_HAN, /* Hani */
G_UNICODE_SCRIPT_HANGUL, /* Hang */
G_UNICODE_SCRIPT_HEBREW, /* Hebr */
G_UNICODE_SCRIPT_HIRAGANA, /* Hira */
G_UNICODE_SCRIPT_KANNADA, /* Knda */
G_UNICODE_SCRIPT_KATAKANA, /* Kana */
G_UNICODE_SCRIPT_KHMER, /* Khmr */
G_UNICODE_SCRIPT_LAO, /* Laoo */
G_UNICODE_SCRIPT_LATIN, /* Latn (Latf, Latg) */
G_UNICODE_SCRIPT_MALAYALAM, /* Mlym */
G_UNICODE_SCRIPT_MONGOLIAN, /* Mong */
G_UNICODE_SCRIPT_MYANMAR, /* Mymr */
G_UNICODE_SCRIPT_OGHAM, /* Ogam */
G_UNICODE_SCRIPT_OLD_ITALIC, /* Ital */
G_UNICODE_SCRIPT_ORIYA, /* Orya */
G_UNICODE_SCRIPT_RUNIC, /* Runr */
G_UNICODE_SCRIPT_SINHALA, /* Sinh */
G_UNICODE_SCRIPT_SYRIAC, /* Syrc (Syrj, Syrn, Syre) */
G_UNICODE_SCRIPT_TAMIL, /* Taml */
G_UNICODE_SCRIPT_TELUGU, /* Telu */
G_UNICODE_SCRIPT_THAANA, /* Thaa */
G_UNICODE_SCRIPT_THAI, /* Thai */
G_UNICODE_SCRIPT_TIBETAN, /* Tibt */
G_UNICODE_SCRIPT_CANADIAN_ABORIGINAL, /* Cans */
G_UNICODE_SCRIPT_YI, /* Yiii */
G_UNICODE_SCRIPT_TAGALOG, /* Tglg */
G_UNICODE_SCRIPT_HANUNOO, /* Hano */
G_UNICODE_SCRIPT_BUHID, /* Buhd */
G_UNICODE_SCRIPT_TAGBANWA, /* Tagb */
/* Unicode-4.0 additions */
G_UNICODE_SCRIPT_BRAILLE, /* Brai */
G_UNICODE_SCRIPT_CYPRIOT, /* Cprt */
G_UNICODE_SCRIPT_LIMBU, /* Limb */
G_UNICODE_SCRIPT_OSMANYA, /* Osma */
G_UNICODE_SCRIPT_SHAVIAN, /* Shaw */
G_UNICODE_SCRIPT_LINEAR_B, /* Linb */
G_UNICODE_SCRIPT_TAI_LE, /* Tale */
G_UNICODE_SCRIPT_UGARITIC, /* Ugar */
/* Unicode-4.1 additions */
G_UNICODE_SCRIPT_NEW_TAI_LUE, /* Talu */
G_UNICODE_SCRIPT_BUGINESE, /* Bugi */
G_UNICODE_SCRIPT_GLAGOLITIC, /* Glag */
G_UNICODE_SCRIPT_TIFINAGH, /* Tfng */
G_UNICODE_SCRIPT_SYLOTI_NAGRI, /* Sylo */
G_UNICODE_SCRIPT_OLD_PERSIAN, /* Xpeo */
G_UNICODE_SCRIPT_KHAROSHTHI, /* Khar */
/* Unicode-5.0 additions */
G_UNICODE_SCRIPT_UNKNOWN, /* Zzzz */
G_UNICODE_SCRIPT_BALINESE, /* Bali */
G_UNICODE_SCRIPT_CUNEIFORM, /* Xsux */
G_UNICODE_SCRIPT_PHOENICIAN, /* Phnx */
G_UNICODE_SCRIPT_PHAGS_PA, /* Phag */
G_UNICODE_SCRIPT_NKO, /* Nkoo */
/* Unicode-5.1 additions */
G_UNICODE_SCRIPT_KAYAH_LI, /* Kali */
G_UNICODE_SCRIPT_LEPCHA, /* Lepc */
G_UNICODE_SCRIPT_REJANG, /* Rjng */
G_UNICODE_SCRIPT_SUNDANESE, /* Sund */
G_UNICODE_SCRIPT_SAURASHTRA, /* Saur */
G_UNICODE_SCRIPT_CHAM, /* Cham */
G_UNICODE_SCRIPT_OL_CHIKI, /* Olck */
G_UNICODE_SCRIPT_VAI, /* Vaii */
G_UNICODE_SCRIPT_CARIAN, /* Cari */
G_UNICODE_SCRIPT_LYCIAN, /* Lyci */
G_UNICODE_SCRIPT_LYDIAN, /* Lydi */
/* Unicode-5.2 additions */
G_UNICODE_SCRIPT_AVESTAN, /* Avst */
G_UNICODE_SCRIPT_BAMUM, /* Bamu */
G_UNICODE_SCRIPT_EGYPTIAN_HIEROGLYPHS, /* Egyp */
G_UNICODE_SCRIPT_IMPERIAL_ARAMAIC, /* Armi */
G_UNICODE_SCRIPT_INSCRIPTIONAL_PAHLAVI, /* Phli */
G_UNICODE_SCRIPT_INSCRIPTIONAL_PARTHIAN, /* Prti */
G_UNICODE_SCRIPT_JAVANESE, /* Java */
G_UNICODE_SCRIPT_KAITHI, /* Kthi */
G_UNICODE_SCRIPT_LISU, /* Lisu */
G_UNICODE_SCRIPT_MEETEI_MAYEK, /* Mtei */
G_UNICODE_SCRIPT_OLD_SOUTH_ARABIAN, /* Sarb */
G_UNICODE_SCRIPT_OLD_TURKIC, /* Orkh */
G_UNICODE_SCRIPT_SAMARITAN, /* Samr */
G_UNICODE_SCRIPT_TAI_THAM, /* Lana */
G_UNICODE_SCRIPT_TAI_VIET, /* Tavt */
/* Unicode-6.0 additions */
G_UNICODE_SCRIPT_BATAK, /* Batk */
G_UNICODE_SCRIPT_BRAHMI, /* Brah */
G_UNICODE_SCRIPT_MANDAIC /* Mand */
} GUnicodeScript;
guint32 g_unicode_script_to_iso15924 (GUnicodeScript script);
GUnicodeScript g_unicode_script_from_iso15924 (guint32 iso15924);
/* Returns TRUE if current locale uses UTF-8 charset. If CHARSET is
* not null, sets *CHARSET to the name of the current locale's
* charset. This value is statically allocated, and should be copied
* in case the locale's charset will be changed later using setlocale()
* or in some other way.
*/
gboolean g_get_charset (const char **charset);
/* These are all analogs of the <ctype.h> functions.
*/
gboolean g_unichar_isalnum (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isalpha (gunichar c) G_GNUC_CONST;
gboolean g_unichar_iscntrl (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isdigit (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isgraph (gunichar c) G_GNUC_CONST;
gboolean g_unichar_islower (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isprint (gunichar c) G_GNUC_CONST;
gboolean g_unichar_ispunct (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isspace (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isupper (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isxdigit (gunichar c) G_GNUC_CONST;
gboolean g_unichar_istitle (gunichar c) G_GNUC_CONST;
gboolean g_unichar_isdefined (gunichar c) G_GNUC_CONST;
gboolean g_unichar_iswide (gunichar c) G_GNUC_CONST;
gboolean g_unichar_iswide_cjk(gunichar c) G_GNUC_CONST;
gboolean g_unichar_iszerowidth(gunichar c) G_GNUC_CONST;
gboolean g_unichar_ismark (gunichar c) G_GNUC_CONST;
/* More <ctype.h> functions. These convert between the three cases.
* See the Unicode book to understand title case. */
gunichar g_unichar_toupper (gunichar c) G_GNUC_CONST;
gunichar g_unichar_tolower (gunichar c) G_GNUC_CONST;
gunichar g_unichar_totitle (gunichar c) G_GNUC_CONST;
/* If C is a digit (according to `g_unichar_isdigit'), then return its
numeric value. Otherwise return -1. */
gint g_unichar_digit_value (gunichar c) G_GNUC_CONST;
gint g_unichar_xdigit_value (gunichar c) G_GNUC_CONST;
/* Return the Unicode character type of a given character. */
GUnicodeType g_unichar_type (gunichar c) G_GNUC_CONST;
/* Return the line break property for a given character */
GUnicodeBreakType g_unichar_break_type (gunichar c) G_GNUC_CONST;
/* Returns the combining class for a given character */
gint g_unichar_combining_class (gunichar uc) G_GNUC_CONST;
gboolean g_unichar_get_mirror_char (gunichar ch,
gunichar *mirrored_ch);
GUnicodeScript g_unichar_get_script (gunichar ch) G_GNUC_CONST;
/* Validate a Unicode character */
gboolean g_unichar_validate (gunichar ch) G_GNUC_CONST;
/* Pairwise canonical compose/decompose */
gboolean g_unichar_compose (gunichar a,
gunichar b,
gunichar *ch);
gboolean g_unichar_decompose (gunichar ch,
gunichar *a,
gunichar *b);
gsize g_unichar_fully_decompose (gunichar ch,
gboolean compat,
gunichar *result,
gsize result_len);
/* Compute canonical ordering of a string in-place. This rearranges
decomposed characters in the string according to their combining
classes. See the Unicode manual for more information. */
void g_unicode_canonical_ordering (gunichar *string,
gsize len);
#ifndef G_DISABLE_DEPRECATED
/* Deprecated. Use g_unichar_fully_decompose() */
gunichar *g_unicode_canonical_decomposition (gunichar ch,
gsize *result_len) G_GNUC_MALLOC;
#endif
/* Array of skip-bytes-per-initial character.
*/
GLIB_VAR const gchar * const g_utf8_skip;
/**
* g_utf8_next_char:
* @p: Pointer to the start of a valid UTF-8 character
*
* Skips to the next character in a UTF-8 string. The string must be
* valid; this macro is as fast as possible, and has no error-checking.
* You would use this macro to iterate over a string character by
* character. The macro returns the start of the next UTF-8 character.
* Before using this macro, use g_utf8_validate() to validate strings
* that may contain invalid UTF-8.
*/
#define g_utf8_next_char(p) (char *)((p) + g_utf8_skip[*(const guchar *)(p)])
gunichar g_utf8_get_char (const gchar *p) G_GNUC_PURE;
gunichar g_utf8_get_char_validated (const gchar *p,
gssize max_len) G_GNUC_PURE;
gchar* g_utf8_offset_to_pointer (const gchar *str,
glong offset) G_GNUC_PURE;
glong g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos) G_GNUC_PURE;
gchar* g_utf8_prev_char (const gchar *p) G_GNUC_PURE;
gchar* g_utf8_find_next_char (const gchar *p,
const gchar *end) G_GNUC_PURE;
gchar* g_utf8_find_prev_char (const gchar *str,
const gchar *p) G_GNUC_PURE;
glong g_utf8_strlen (const gchar *p,
gssize max) G_GNUC_PURE;
gchar *g_utf8_substring (const gchar *str,
glong start_pos,
glong end_pos) G_GNUC_MALLOC;
gchar *g_utf8_strncpy (gchar *dest,
const gchar *src,
gsize n);
/* Find the UTF-8 character corresponding to ch, in string p. These
functions are equivalants to strchr and strrchr */
gchar* g_utf8_strchr (const gchar *p,
gssize len,
gunichar c);
gchar* g_utf8_strrchr (const gchar *p,
gssize len,
gunichar c);
gchar* g_utf8_strreverse (const gchar *str,
gssize len);
gunichar2 *g_utf8_to_utf16 (const gchar *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gunichar * g_utf8_to_ucs4 (const gchar *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gunichar * g_utf8_to_ucs4_fast (const gchar *str,
glong len,
glong *items_written) G_GNUC_MALLOC;
gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gchar* g_utf16_to_utf8 (const gunichar2 *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gchar* g_ucs4_to_utf8 (const gunichar *str,
glong len,
glong *items_read,
glong *items_written,
GError **error) G_GNUC_MALLOC;
gint g_unichar_to_utf8 (gunichar c,
gchar *outbuf);
gboolean g_utf8_validate (const gchar *str,
gssize max_len,
const gchar **end);
gchar *g_utf8_strup (const gchar *str,
gssize len) G_GNUC_MALLOC;
gchar *g_utf8_strdown (const gchar *str,
gssize len) G_GNUC_MALLOC;
gchar *g_utf8_casefold (const gchar *str,
gssize len) G_GNUC_MALLOC;
/**
* GNormalizeMode:
* @G_NORMALIZE_DEFAULT: standardize differences that do not affect the
* text content, such as the above-mentioned accent representation
* @G_NORMALIZE_NFD: another name for %G_NORMALIZE_DEFAULT
* @G_NORMALIZE_DEFAULT_COMPOSE: like %G_NORMALIZE_DEFAULT, but with
* composed forms rather than a maximally decomposed form
* @G_NORMALIZE_NFC: another name for %G_NORMALIZE_DEFAULT_COMPOSE
* @G_NORMALIZE_ALL: beyond %G_NORMALIZE_DEFAULT also standardize the
* "compatibility" characters in Unicode, such as SUPERSCRIPT THREE
* to the standard forms (in this case DIGIT THREE). Formatting
* information may be lost but for most text operations such
* characters should be considered the same
* @G_NORMALIZE_NFKD: another name for %G_NORMALIZE_ALL
* @G_NORMALIZE_ALL_COMPOSE: like %G_NORMALIZE_ALL, but with composed
* forms rather than a maximally decomposed form
* @G_NORMALIZE_NFKC: another name for %G_NORMALIZE_ALL_COMPOSE
*
* Defines how a Unicode string is transformed in a canonical
* form, standardizing such issues as whether a character with
* an accent is represented as a base character and combining
* accent or as a single precomposed character. Unicode strings
* should generally be normalized before comparing them.
*/
typedef enum {
G_NORMALIZE_DEFAULT,
G_NORMALIZE_NFD = G_NORMALIZE_DEFAULT,
G_NORMALIZE_DEFAULT_COMPOSE,
G_NORMALIZE_NFC = G_NORMALIZE_DEFAULT_COMPOSE,
G_NORMALIZE_ALL,
G_NORMALIZE_NFKD = G_NORMALIZE_ALL,
G_NORMALIZE_ALL_COMPOSE,
G_NORMALIZE_NFKC = G_NORMALIZE_ALL_COMPOSE
} GNormalizeMode;
gchar *g_utf8_normalize (const gchar *str,
gssize len,
GNormalizeMode mode) G_GNUC_MALLOC;
gint g_utf8_collate (const gchar *str1,
const gchar *str2) G_GNUC_PURE;
gchar *g_utf8_collate_key (const gchar *str,
gssize len) G_GNUC_MALLOC;
gchar *g_utf8_collate_key_for_filename (const gchar *str,
gssize len) G_GNUC_MALLOC;
/* private */
gchar *_g_utf8_make_valid (const gchar *name);
G_END_DECLS
#endif /* __G_UNICODE_H__ */

3872
deps/glib/gutils.c vendored Normal file

File diff suppressed because it is too large Load Diff

528
deps/glib/gutils.h vendored Normal file
View File

@ -0,0 +1,528 @@
/* GLIB - Library of useful routines for C programming
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#if defined(G_DISABLE_SINGLE_INCLUDES) && !defined (__GLIB_H_INSIDE__) && !defined (GLIB_COMPILATION)
#error "Only <glib.h> can be included directly."
#endif
#ifndef __G_UTILS_H__
#define __G_UTILS_H__
#include <glib/gtypes.h>
#include <stdarg.h>
G_BEGIN_DECLS
#ifdef G_OS_WIN32
/* On Win32, the canonical directory separator is the backslash, and
* the search path separator is the semicolon. Note that also the
* (forward) slash works as directory separator.
*/
#define G_DIR_SEPARATOR '\\'
#define G_DIR_SEPARATOR_S "\\"
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR || (c) == '/')
#define G_SEARCHPATH_SEPARATOR ';'
#define G_SEARCHPATH_SEPARATOR_S ";"
#else /* !G_OS_WIN32 */
/* Unix */
#define G_DIR_SEPARATOR '/'
#define G_DIR_SEPARATOR_S "/"
#define G_IS_DIR_SEPARATOR(c) ((c) == G_DIR_SEPARATOR)
#define G_SEARCHPATH_SEPARATOR ':'
#define G_SEARCHPATH_SEPARATOR_S ":"
#endif /* !G_OS_WIN32 */
/* Define G_VA_COPY() to do the right thing for copying va_list variables.
* glibconfig.h may have already defined G_VA_COPY as va_copy or __va_copy.
*/
#if !defined (G_VA_COPY)
# if defined (__GNUC__) && defined (__PPC__) && (defined (_CALL_SYSV) || defined (_WIN32))
# define G_VA_COPY(ap1, ap2) (*(ap1) = *(ap2))
# elif defined (G_VA_COPY_AS_ARRAY)
# define G_VA_COPY(ap1, ap2) g_memmove ((ap1), (ap2), sizeof (va_list))
# else /* va_list is a pointer */
# define G_VA_COPY(ap1, ap2) ((ap1) = (ap2))
# endif /* va_list is a pointer */
#endif /* !G_VA_COPY */
/* inlining hassle. for compilers that don't allow the `inline' keyword,
* mostly because of strict ANSI C compliance or dumbness, we try to fall
* back to either `__inline__' or `__inline'.
* G_CAN_INLINE is defined in glibconfig.h if the compiler seems to be
* actually *capable* to do function inlining, in which case inline
* function bodies do make sense. we also define G_INLINE_FUNC to properly
* export the function prototypes if no inlining can be performed.
* inline function bodies have to be special cased with G_CAN_INLINE and a
* .c file specific macro to allow one compiled instance with extern linkage
* of the functions by defining G_IMPLEMENT_INLINES and the .c file macro.
*/
#if defined (G_HAVE_INLINE) && defined (__GNUC__) && defined (__STRICT_ANSI__)
# undef inline
# define inline __inline__
#elif !defined (G_HAVE_INLINE)
# undef inline
# if defined (G_HAVE___INLINE__)
# define inline __inline__
# elif defined (G_HAVE___INLINE)
# define inline __inline
# else /* !inline && !__inline__ && !__inline */
# define inline /* don't inline, then */
# endif
#endif
#ifdef G_IMPLEMENT_INLINES
# define G_INLINE_FUNC
# undef G_CAN_INLINE
#elif defined (__GNUC__)
# define G_INLINE_FUNC static __inline __attribute__ ((unused))
#elif defined (G_CAN_INLINE)
# define G_INLINE_FUNC static inline
#else /* can't inline */
# define G_INLINE_FUNC
#endif /* !G_INLINE_FUNC */
#ifndef __GTK_DOC_IGNORE__
#ifdef G_OS_WIN32
#define g_get_user_name g_get_user_name_utf8
#define g_get_real_name g_get_real_name_utf8
#define g_get_home_dir g_get_home_dir_utf8
#define g_get_tmp_dir g_get_tmp_dir_utf8
#endif
#endif
const gchar * g_get_user_name (void);
const gchar * g_get_real_name (void);
const gchar * g_get_home_dir (void);
const gchar * g_get_tmp_dir (void);
const gchar * g_get_host_name (void);
gchar * g_get_prgname (void);
void g_set_prgname (const gchar *prgname);
const gchar * g_get_application_name (void);
void g_set_application_name (const gchar *application_name);
void g_reload_user_special_dirs_cache (void);
const gchar * g_get_user_data_dir (void);
const gchar * g_get_user_config_dir (void);
const gchar * g_get_user_cache_dir (void);
const gchar * const * g_get_system_data_dirs (void);
#ifdef G_OS_WIN32
/* This functions is not part of the public GLib API */
const gchar * const * g_win32_get_system_data_dirs_for_module (void (*address_of_function)(void));
#endif
#if defined (G_OS_WIN32) && defined (G_CAN_INLINE) && !defined (__cplusplus)
/* This function is not part of the public GLib API either. Just call
* g_get_system_data_dirs() in your code, never mind that that is
* actually a macro and you will in fact call this inline function.
*/
static inline const gchar * const *
_g_win32_get_system_data_dirs (void)
{
return g_win32_get_system_data_dirs_for_module ((void (*)(void)) &_g_win32_get_system_data_dirs);
}
#define g_get_system_data_dirs _g_win32_get_system_data_dirs
#endif
const gchar * const * g_get_system_config_dirs (void);
const gchar * g_get_user_runtime_dir (void);
const gchar * const * g_get_language_names (void);
gchar **g_get_locale_variants (const gchar *locale);
/**
* GUserDirectory:
* @G_USER_DIRECTORY_DESKTOP: the user's Desktop directory
* @G_USER_DIRECTORY_DOCUMENTS: the user's Documents directory
* @G_USER_DIRECTORY_DOWNLOAD: the user's Downloads directory
* @G_USER_DIRECTORY_MUSIC: the user's Music directory
* @G_USER_DIRECTORY_PICTURES: the user's Pictures directory
* @G_USER_DIRECTORY_PUBLIC_SHARE: the user's shared directory
* @G_USER_DIRECTORY_TEMPLATES: the user's Templates directory
* @G_USER_DIRECTORY_VIDEOS: the user's Movies directory
* @G_USER_N_DIRECTORIES: the number of enum values
*
* These are logical ids for special directories which are defined
* depending on the platform used. You should use g_get_user_special_dir()
* to retrieve the full path associated to the logical id.
*
* The #GUserDirectory enumeration can be extended at later date. Not
* every platform has a directory for every logical id in this
* enumeration.
*
* Since: 2.14
*/
typedef enum {
G_USER_DIRECTORY_DESKTOP,
G_USER_DIRECTORY_DOCUMENTS,
G_USER_DIRECTORY_DOWNLOAD,
G_USER_DIRECTORY_MUSIC,
G_USER_DIRECTORY_PICTURES,
G_USER_DIRECTORY_PUBLIC_SHARE,
G_USER_DIRECTORY_TEMPLATES,
G_USER_DIRECTORY_VIDEOS,
G_USER_N_DIRECTORIES
} GUserDirectory;
const gchar * g_get_user_special_dir (GUserDirectory directory);
/**
* GDebugKey:
* @key: the string
* @value: the flag
*
* Associates a string with a bit flag.
* Used in g_parse_debug_string().
*/
typedef struct _GDebugKey GDebugKey;
struct _GDebugKey
{
const gchar *key;
guint value;
};
/* Miscellaneous utility functions
*/
guint g_parse_debug_string (const gchar *string,
const GDebugKey *keys,
guint nkeys);
gint g_snprintf (gchar *string,
gulong n,
gchar const *format,
...) G_GNUC_PRINTF (3, 4);
gint g_vsnprintf (gchar *string,
gulong n,
gchar const *format,
va_list args);
/* Check if a file name is an absolute path */
gboolean g_path_is_absolute (const gchar *file_name);
/* In case of absolute paths, skip the root part */
const gchar * g_path_skip_root (const gchar *file_name);
#ifndef G_DISABLE_DEPRECATED
const gchar * g_basename (const gchar *file_name);
#define g_dirname g_path_get_dirname
#endif /* G_DISABLE_DEPRECATED */
#ifndef __GTK_DOC_IGNORE__
#ifdef G_OS_WIN32
#define g_get_current_dir g_get_current_dir_utf8
#endif
#endif
/* The returned strings are newly allocated with g_malloc() */
gchar* g_get_current_dir (void);
gchar* g_path_get_basename (const gchar *file_name) G_GNUC_MALLOC;
gchar* g_path_get_dirname (const gchar *file_name) G_GNUC_MALLOC;
/* Set the pointer at the specified location to NULL */
void g_nullify_pointer (gpointer *nullify_location);
/* return the environment string for the variable. The returned memory
* must not be freed. */
#ifndef __GTK_DOC_IGNORE__
#ifdef G_OS_WIN32
#define g_getenv g_getenv_utf8
#define g_setenv g_setenv_utf8
#define g_unsetenv g_unsetenv_utf8
#define g_find_program_in_path g_find_program_in_path_utf8
#endif
#endif
const gchar * g_getenv (const gchar *variable);
gboolean g_setenv (const gchar *variable,
const gchar *value,
gboolean overwrite);
void g_unsetenv (const gchar *variable);
gchar** g_listenv (void);
gchar** g_get_environ (void);
/* private */
const gchar* _g_getenv_nomalloc (const gchar *variable,
gchar buffer[1024]);
/**
* GVoidFunc:
*
* Declares a type of function which takes no arguments
* and has no return value. It is used to specify the type
* function passed to g_atexit().
*/
typedef void (*GVoidFunc) (void);
#ifndef ATEXIT
# define ATEXIT(proc) g_ATEXIT(proc)
#else
# define G_NATIVE_ATEXIT
#endif /* ATEXIT */
/* we use a GLib function as a replacement for ATEXIT, so
* the programmer is not required to check the return value
* (if there is any in the implementation) and doesn't encounter
* missing include files.
*/
void g_atexit (GVoidFunc func);
#ifdef G_OS_WIN32
/* It's a bad idea to wrap atexit() on Windows. If the GLib DLL calls
* atexit(), the function will be called when the GLib DLL is detached
* from the program, which is not what the caller wants. The caller
* wants the function to be called when it *itself* exits (or is
* detached, in case the caller, too, is a DLL).
*/
#if (defined(__MINGW_H) && !defined(_STDLIB_H_)) || (defined(_MSC_VER) && !defined(_INC_STDLIB))
int atexit (void (*)(void));
#endif
#define g_atexit(func) atexit(func)
#endif
/* Look for an executable in PATH, following execvp() rules */
gchar* g_find_program_in_path (const gchar *program);
/* Bit tests
*/
G_INLINE_FUNC gint g_bit_nth_lsf (gulong mask,
gint nth_bit) G_GNUC_CONST;
G_INLINE_FUNC gint g_bit_nth_msf (gulong mask,
gint nth_bit) G_GNUC_CONST;
G_INLINE_FUNC guint g_bit_storage (gulong number) G_GNUC_CONST;
/* Trash Stacks
* elements need to be >= sizeof (gpointer)
*/
typedef struct _GTrashStack GTrashStack;
struct _GTrashStack
{
GTrashStack *next;
};
G_INLINE_FUNC void g_trash_stack_push (GTrashStack **stack_p,
gpointer data_p);
G_INLINE_FUNC gpointer g_trash_stack_pop (GTrashStack **stack_p);
G_INLINE_FUNC gpointer g_trash_stack_peek (GTrashStack **stack_p);
G_INLINE_FUNC guint g_trash_stack_height (GTrashStack **stack_p);
/* inline function implementations
*/
#if defined (G_CAN_INLINE) || defined (__G_UTILS_C__)
G_INLINE_FUNC gint
g_bit_nth_lsf (gulong mask,
gint nth_bit)
{
if (G_UNLIKELY (nth_bit < -1))
nth_bit = -1;
while (nth_bit < ((GLIB_SIZEOF_LONG * 8) - 1))
{
nth_bit++;
if (mask & (1UL << nth_bit))
return nth_bit;
}
return -1;
}
G_INLINE_FUNC gint
g_bit_nth_msf (gulong mask,
gint nth_bit)
{
if (nth_bit < 0 || G_UNLIKELY (nth_bit > GLIB_SIZEOF_LONG * 8))
nth_bit = GLIB_SIZEOF_LONG * 8;
while (nth_bit > 0)
{
nth_bit--;
if (mask & (1UL << nth_bit))
return nth_bit;
}
return -1;
}
G_INLINE_FUNC guint
g_bit_storage (gulong number)
{
#if defined(__GNUC__) && (__GNUC__ >= 4) && defined(__OPTIMIZE__)
return G_LIKELY (number) ?
((GLIB_SIZEOF_LONG * 8U - 1) ^ __builtin_clzl(number)) + 1 : 1;
#else
register guint n_bits = 0;
do
{
n_bits++;
number >>= 1;
}
while (number);
return n_bits;
#endif
}
G_INLINE_FUNC void
g_trash_stack_push (GTrashStack **stack_p,
gpointer data_p)
{
GTrashStack *data = (GTrashStack *) data_p;
data->next = *stack_p;
*stack_p = data;
}
G_INLINE_FUNC gpointer
g_trash_stack_pop (GTrashStack **stack_p)
{
GTrashStack *data;
data = *stack_p;
if (data)
{
*stack_p = data->next;
/* NULLify private pointer here, most platforms store NULL as
* subsequent 0 bytes
*/
data->next = NULL;
}
return data;
}
G_INLINE_FUNC gpointer
g_trash_stack_peek (GTrashStack **stack_p)
{
GTrashStack *data;
data = *stack_p;
return data;
}
G_INLINE_FUNC guint
g_trash_stack_height (GTrashStack **stack_p)
{
GTrashStack *data;
guint i = 0;
for (data = *stack_p; data; data = data->next)
i++;
return i;
}
#endif /* G_CAN_INLINE || __G_UTILS_C__ */
/* Glib version.
* we prefix variable declarations so they can
* properly get exported in windows dlls.
*/
GLIB_VAR const guint glib_major_version;
GLIB_VAR const guint glib_minor_version;
GLIB_VAR const guint glib_micro_version;
GLIB_VAR const guint glib_interface_age;
GLIB_VAR const guint glib_binary_age;
const gchar * glib_check_version (guint required_major,
guint required_minor,
guint required_micro);
/**
* GLIB_CHECK_VERSION:
* @major: the major version to check for
* @minor: the minor version to check for
* @micro: the micro version to check for
*
* Checks the version of the GLib library that is being compiled
* against.
*
* <example>
* <title>Checking the version of the GLib library</title>
* <programlisting>
* if (!GLIB_CHECK_VERSION (1, 2, 0))
* g_error ("GLib version 1.2.0 or above is needed");
* </programlisting>
* </example>
*
* See glib_check_version() for a runtime check.
*
* Returns: %TRUE if the version of the GLib header files
* is the same as or newer than the passed-in version.
*/
#define GLIB_CHECK_VERSION(major,minor,micro) \
(GLIB_MAJOR_VERSION > (major) || \
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION > (minor)) || \
(GLIB_MAJOR_VERSION == (major) && GLIB_MINOR_VERSION == (minor) && \
GLIB_MICRO_VERSION >= (micro)))
G_END_DECLS
#ifndef G_DISABLE_DEPRECATED
/*
* This macro is deprecated. This DllMain() is too complex. It is
* recommended to write an explicit minimal DLlMain() that just saves
* the handle to the DLL and then use that handle instead, for
* instance passing it to
* g_win32_get_package_installation_directory_of_module().
*
* On Windows, this macro defines a DllMain function that stores the
* actual DLL name that the code being compiled will be included in.
* STATIC should be empty or 'static'. DLL_NAME is the name of the
* (pointer to the) char array where the DLL name will be stored. If
* this is used, you must also include <windows.h>. If you need a more complex
* DLL entry point function, you cannot use this.
*
* On non-Windows platforms, expands to nothing.
*/
#ifndef G_PLATFORM_WIN32
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name)
#else
# define G_WIN32_DLLMAIN_FOR_DLL_NAME(static, dll_name) \
static char *dll_name; \
\
BOOL WINAPI \
DllMain (HINSTANCE hinstDLL, \
DWORD fdwReason, \
LPVOID lpvReserved) \
{ \
wchar_t wcbfr[1000]; \
char *tem; \
switch (fdwReason) \
{ \
case DLL_PROCESS_ATTACH: \
GetModuleFileNameW ((HMODULE) hinstDLL, wcbfr, G_N_ELEMENTS (wcbfr)); \
tem = g_utf16_to_utf8 (wcbfr, -1, NULL, NULL, NULL); \
dll_name = g_path_get_basename (tem); \
g_free (tem); \
break; \
} \
\
return TRUE; \
}
#endif /* !G_DISABLE_DEPRECATED */
#endif /* G_PLATFORM_WIN32 */
#endif /* __G_UTILS_H__ */

32
deps/gmodule/Makefile.am vendored Normal file
View File

@ -0,0 +1,32 @@
noinst_LTLIBRARIES = libgmodule.la
libgmodule_la_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_srcdir)/deps \
-I$(top_srcdir)/deps/glib \
-I$(top_builddir)/deps/glib \
-Wall \
$(NULL)
EXTRA_DIST = \
gmoduleconf.h.in \
gmodule-dl.c \
gmodule-dld.c \
gmodule-dyld.c \
gmodule-win32.c \
gmoduleconf.h.win32 \
$(NULL)
BUILT_SOURCES = gmoduleconf.h
gmoduleconf.h: gmoduleconf.h.in
libgmodule_la_SOURCES = gmodule.c
libgmodule_la_LIBADD = \
$(G_MODULE_LIBS_EXTRA) \
$(G_MODULE_LIBS) \
$(top_builddir)/deps/glib/$(libglib) \
$(NULL)
libgmodule_la_LDFLAGS = \
$(G_MODULE_LDFLAGS) \
$(NULL)

4
deps/gmodule/README vendored Normal file
View File

@ -0,0 +1,4 @@
gmodule is taken from the same glib version as deps/glib.
The only modification is to drop the support for .la libtool archive, which
avoid pulling in GParser (and its dependencies).

168
deps/gmodule/gmodule-dl.c vendored Normal file
View File

@ -0,0 +1,168 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998, 2000 Tim Janik
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include <dlfcn.h>
/* Perl includes <nlist.h> and <link.h> instead of <dlfcn.h> on some systmes? */
/* dlerror() is not implemented on all systems
*/
#ifndef G_MODULE_HAVE_DLERROR
# ifdef __NetBSD__
# define dlerror() g_strerror (errno)
# else /* !__NetBSD__ */
/* could we rely on errno's state here? */
# define dlerror() "unknown dl-error"
# endif /* !__NetBSD__ */
#endif /* G_MODULE_HAVE_DLERROR */
/* some flags are missing on some systems, so we provide
* harmless defaults.
* The Perl sources say, RTLD_LAZY needs to be defined as (1),
* at least for Solaris 1.
*
* Mandatory:
* RTLD_LAZY - resolve undefined symbols as code from the dynamic library
* is executed.
* RTLD_NOW - resolve all undefined symbols before dlopen returns, and fail
* if this cannot be done.
* Optionally:
* RTLD_GLOBAL - the external symbols defined in the library will be made
* available to subsequently loaded libraries.
*/
#ifndef RTLD_LAZY
#define RTLD_LAZY 1
#endif /* RTLD_LAZY */
#ifndef RTLD_NOW
#define RTLD_NOW 0
#endif /* RTLD_NOW */
/* some systems (OSF1 V5.0) have broken RTLD_GLOBAL linkage */
#ifdef G_MODULE_BROKEN_RTLD_GLOBAL
#undef RTLD_GLOBAL
#endif /* G_MODULE_BROKEN_RTLD_GLOBAL */
#ifndef RTLD_GLOBAL
#define RTLD_GLOBAL 0
#endif /* RTLD_GLOBAL */
/* --- functions --- */
static gchar*
fetch_dlerror (gboolean replace_null)
{
gchar *msg = dlerror ();
/* make sure we always return an error message != NULL, if
* expected to do so. */
if (!msg && replace_null)
return "unknown dl-error";
return msg;
}
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
gpointer handle;
handle = dlopen (file_name,
(bind_local ? 0 : RTLD_GLOBAL) | (bind_lazy ? RTLD_LAZY : RTLD_NOW));
if (!handle)
g_module_set_error (fetch_dlerror (TRUE));
return handle;
}
static gpointer
_g_module_self (void)
{
gpointer handle;
/* to query symbols from the program itself, special link options
* are required on some systems.
*/
handle = dlopen (NULL, RTLD_GLOBAL | RTLD_LAZY);
if (!handle)
g_module_set_error (fetch_dlerror (TRUE));
return handle;
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
{
/* are there any systems out there that have dlopen()/dlclose()
* without a reference count implementation?
*/
is_unref |= 1;
if (is_unref)
{
if (dlclose (handle) != 0)
g_module_set_error (fetch_dlerror (TRUE));
}
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
gpointer p;
gchar *msg;
fetch_dlerror (FALSE);
p = dlsym (handle, symbol_name);
msg = fetch_dlerror (FALSE);
if (msg)
g_module_set_error (msg);
return p;
}
static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
if (directory && *directory) {
if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (directory, "/", module_name, NULL);
else
return g_strconcat (directory, "/lib", module_name, "." G_MODULE_SUFFIX, NULL);
} else if (strncmp (module_name, "lib", 3) == 0)
return g_strdup (module_name);
else
return g_strconcat ("lib", module_name, "." G_MODULE_SUFFIX, NULL);
}

163
deps/gmodule/gmodule-dld.c vendored Normal file
View File

@ -0,0 +1,163 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998, 2000 Tim Janik
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include <dl.h>
/* some flags are missing on some systems, so we provide
* harmless defaults.
*
* Mandatory:
* BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
* BIND_DEFERRED - Delay code symbol resolution until actual reference.
*
* Optionally:
* BIND_FIRST - Place the library at the head of the symbol search order.
* BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all unsatisfied
* symbols as fatal. This flag allows binding of unsatisfied code
* symbols to be deferred until use.
* [Perl: For certain libraries, like DCE, deferred binding often
* causes run time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE
* still allows unresolved references in situations like this.]
* BIND_NOSTART - Do not call the initializer for the shared library when the
* library is loaded, nor on a future call to shl_unload().
* BIND_VERBOSE - Print verbose messages concerning possible unsatisfied symbols.
*
* hp9000s700/hp9000s800:
* BIND_RESTRICTED - Restrict symbols visible by the library to those present at
* library load time.
* DYNAMIC_PATH - Allow the loader to dynamically search for the library specified
* by the path argument.
*/
#ifndef DYNAMIC_PATH
#define DYNAMIC_PATH 0
#endif /* DYNAMIC_PATH */
#ifndef BIND_RESTRICTED
#define BIND_RESTRICTED 0
#endif /* BIND_RESTRICTED */
#define OPT_BIND_FLAGS (BIND_NONFATAL | BIND_VERBOSE)
/* --- functions --- */
/*
* shl_load() does not appear to support making symbols invisible to
* the global namespace. However, the default is to put the library
* last in the search order, which is approximately what we want,
* since it will cause symbols that conflict with existing symbols to
* be invisible. It is unclear if BIND_FIRST should be used when
* bind_local==0, since it may cause the loaded symbols to be used
* preferentially to the application's symbols, which is Almost
* Always Wrong. --ds
*/
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
shl_t shl_handle;
shl_handle = shl_load (file_name,
(bind_lazy ? BIND_DEFERRED : BIND_IMMEDIATE) | OPT_BIND_FLAGS, 0);
if (!shl_handle)
{
/* the hp-docs say we should better abort() if errno==ENOSYM ;( */
g_module_set_error (g_strerror (errno));
}
return (gpointer) shl_handle;
}
static gpointer
_g_module_self (void)
{
shl_t shl_handle;
shl_handle = PROG_HANDLE;
if (!shl_handle)
g_module_set_error (g_strerror (errno));
return shl_handle;
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
{
if (!is_unref)
{
if (shl_unload ((shl_t) handle) != 0)
g_module_set_error (g_strerror (errno));
}
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
gpointer p = NULL;
/* should we restrict lookups to TYPE_PROCEDURE?
*/
if (handle == PROG_HANDLE)
{
/* PROG_HANDLE will only lookup symbols in the program itself, not honouring
* libraries. passing NULL as a handle will also try to lookup the symbol
* in currently loaded libraries. fix pointed out and supplied by:
* David Gero <dgero@nortelnetworks.com>
*/
handle = NULL;
}
if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
handle == NULL || p == NULL)
{
/* the hp-docs say we should better abort() if errno==ENOSYM ;( */
g_module_set_error (g_strerror (errno));
}
return p;
}
static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
if (directory && *directory)
if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (directory, "/", module_name, NULL);
else
return g_strconcat (directory, "/lib", module_name, ".sl", NULL);
else if (strncmp (module_name, "lib", 3) == 0)
return g_strdup (module_name);
else
return g_strconcat ("lib", module_name, ".sl", NULL);
}

154
deps/gmodule/gmodule-dyld.c vendored Normal file
View File

@ -0,0 +1,154 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998, 2000 Tim Janik
*
* dyld (Darwin) GMODULE implementation
* Copyright (C) 2001 Dan Winship
*
* 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 <mach-o/dyld.h>
static gpointer self_module = GINT_TO_POINTER (1);
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
NSObjectFileImage image;
NSObjectFileImageReturnCode ret;
NSModule module;
unsigned long options;
char *msg;
ret = NSCreateObjectFileImageFromFile (file_name, &image);
if (ret != NSObjectFileImageSuccess)
{
switch (ret)
{
case NSObjectFileImageInappropriateFile:
case NSObjectFileImageFormat:
msg = g_strdup_printf ("%s is not a loadable module", file_name);
break;
case NSObjectFileImageArch:
msg = g_strdup_printf ("%s is not built for this architecture",
file_name);
break;
case NSObjectFileImageAccess:
if (access (file_name, F_OK) == 0)
msg = g_strdup_printf ("%s: permission denied", file_name);
else
msg = g_strdup_printf ("%s: no such file or directory", file_name);
break;
default:
msg = g_strdup_printf ("unknown error for %s", file_name);
break;
}
g_module_set_error (msg);
g_free (msg);
return NULL;
}
options = NSLINKMODULE_OPTION_RETURN_ON_ERROR;
if (bind_local)
options |= NSLINKMODULE_OPTION_PRIVATE;
if (!bind_lazy)
options |= NSLINKMODULE_OPTION_BINDNOW;
module = NSLinkModule (image, file_name, options);
NSDestroyObjectFileImage (image);
if (!module)
{
NSLinkEditErrors c;
int error_number;
const char *file, *error;
NSLinkEditError (&c, &error_number, &file, &error);
msg = g_strdup_printf ("could not link %s: %s", file_name, error);
g_module_set_error (msg);
g_free (msg);
return NULL;
}
return module;
}
static gpointer
_g_module_self (void)
{
return &self_module;
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
{
if (handle == &self_module)
return;
if (!NSUnLinkModule (handle, 0))
g_module_set_error ("could not unlink module");
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
NSSymbol sym;
char *msg;
if (handle == &self_module)
{
if (NSIsSymbolNameDefined (symbol_name))
sym = NSLookupAndBindSymbol (symbol_name);
else
sym = NULL;
}
else
sym = NSLookupSymbolInModule (handle, symbol_name);
if (!sym)
{
msg = g_strdup_printf ("no such symbol %s", symbol_name);
g_module_set_error (msg);
g_free (msg);
return NULL;
}
return NSAddressOfSymbol (sym);
}
static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
if (directory && *directory)
{
if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (directory, "/", module_name, NULL);
else
return g_strconcat (directory, "/lib", module_name, "." G_MODULE_SUFFIX, NULL);
}
else if (strncmp (module_name, "lib", 3) == 0)
return g_strdup (module_name);
else
return g_strconcat ("lib", module_name, "." G_MODULE_SUFFIX, NULL);
}

202
deps/gmodule/gmodule-win32.c vendored Normal file
View File

@ -0,0 +1,202 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998, 2000 Tim Janik
*
* Win32 GMODULE implementation
* Copyright (C) 1998 Tor Lillqvist
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include <stdio.h>
#include <windows.h>
#include <tlhelp32.h>
#ifdef G_WITH_CYGWIN
#include <sys/cygwin.h>
#endif
static void
set_error (const gchar *format,
...)
{
gchar *error;
gchar *detail;
gchar *message;
va_list args;
error = g_win32_error_message (GetLastError ());
va_start (args, format);
detail = g_strdup_vprintf (format, args);
va_end (args);
message = g_strconcat (detail, error, NULL);
g_module_set_error (message);
g_free (message);
g_free (detail);
g_free (error);
}
/* --- functions --- */
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
HINSTANCE handle;
wchar_t *wfilename;
#ifdef G_WITH_CYGWIN
gchar tmp[MAX_PATH];
cygwin_conv_to_win32_path(file_name, tmp);
file_name = tmp;
#endif
wfilename = g_utf8_to_utf16 (file_name, -1, NULL, NULL, NULL);
handle = LoadLibraryW (wfilename);
g_free (wfilename);
if (!handle)
set_error ("`%s': ", file_name);
return handle;
}
static gint dummy;
static gpointer null_module_handle = &dummy;
static gpointer
_g_module_self (void)
{
return null_module_handle;
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
{
if (handle != null_module_handle)
if (!FreeLibrary (handle))
set_error ("");
}
static gpointer
find_in_any_module_using_toolhelp (const gchar *symbol_name)
{
HANDLE snapshot;
MODULEENTRY32 me32;
gpointer p;
if ((snapshot = CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, 0)) == (HANDLE) -1)
return NULL;
me32.dwSize = sizeof (me32);
p = NULL;
if (Module32First (snapshot, &me32))
{
do {
if ((p = GetProcAddress (me32.hModule, symbol_name)) != NULL)
break;
} while (Module32Next (snapshot, &me32));
}
CloseHandle (snapshot);
return p;
}
static gpointer
find_in_any_module (const gchar *symbol_name)
{
gpointer result;
if ((result = find_in_any_module_using_toolhelp (symbol_name)) == NULL)
return NULL;
else
return result;
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
gpointer p;
if (handle == null_module_handle)
{
if ((p = GetProcAddress (GetModuleHandle (NULL), symbol_name)) == NULL)
p = find_in_any_module (symbol_name);
}
else
p = GetProcAddress (handle, symbol_name);
if (!p)
set_error ("");
return p;
}
static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
gint k;
k = strlen (module_name);
if (directory && *directory)
if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, NULL);
#ifdef G_WITH_CYGWIN
else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
else
return g_strconcat (directory, G_DIR_SEPARATOR_S, "cyg", module_name, ".dll", NULL);
#else
else if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (directory, G_DIR_SEPARATOR_S, module_name, ".dll", NULL);
else
return g_strconcat (directory, G_DIR_SEPARATOR_S, "lib", module_name, ".dll", NULL);
#endif
else if (k > 4 && g_ascii_strcasecmp (module_name + k - 4, ".dll") == 0)
return g_strdup (module_name);
#ifdef G_WITH_CYGWIN
else if (strncmp (module_name, "lib", 3) == 0 || strncmp (module_name, "cyg", 3) == 0)
return g_strconcat (module_name, ".dll", NULL);
else
return g_strconcat ("cyg", module_name, ".dll", NULL);
#else
else if (strncmp (module_name, "lib", 3) == 0)
return g_strconcat (module_name, ".dll", NULL);
else
return g_strconcat ("lib", module_name, ".dll", NULL);
#endif
}

582
deps/gmodule/gmodule.c vendored Normal file
View File

@ -0,0 +1,582 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998 Tim Janik
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
/*
* MT safe
*/
#include "config.h"
#include "glib.h"
#include "gmodule.h"
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef G_OS_WIN32
#include <io.h> /* For open() and close() prototypes. */
#endif
#include "gmoduleconf.h"
#include "gstdio.h"
/* We maintain a list of modules, so we can reference count them.
* That's needed because some platforms don't support references counts on
* modules e.g. the shl_* implementation of HP-UX
* (http://www.stat.umn.edu/~luke/xls/projects/dlbasics/dlbasics.html).
* Also, the module for the program itself is kept seperatedly for
* faster access and because it has special semantics.
*/
/* --- structures --- */
struct _GModule
{
gchar *file_name;
#if defined (G_OS_WIN32) && !defined(_WIN64)
gchar *cp_file_name;
#endif
gpointer handle;
guint ref_count : 31;
guint is_resident : 1;
GModuleUnload unload;
GModule *next;
};
/* --- prototypes --- */
static gpointer _g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local);
static void _g_module_close (gpointer handle,
gboolean is_unref);
static gpointer _g_module_self (void);
static gpointer _g_module_symbol (gpointer handle,
const gchar *symbol_name);
static gchar* _g_module_build_path (const gchar *directory,
const gchar *module_name);
static inline void g_module_set_error (const gchar *error);
static inline GModule* g_module_find_by_handle (gpointer handle);
static inline GModule* g_module_find_by_name (const gchar *name);
/* --- variables --- */
static GModule *modules = NULL;
static GModule *main_module = NULL;
static GStaticPrivate module_error_private = G_STATIC_PRIVATE_INIT;
static gboolean module_debug_initialized = FALSE;
static guint module_debug_flags = 0;
/* --- inline functions --- */
static inline GModule*
g_module_find_by_handle (gpointer handle)
{
GModule *module;
GModule *retval = NULL;
if (main_module && main_module->handle == handle)
retval = main_module;
else
for (module = modules; module; module = module->next)
if (handle == module->handle)
{
retval = module;
break;
}
return retval;
}
static inline GModule*
g_module_find_by_name (const gchar *name)
{
GModule *module;
GModule *retval = NULL;
for (module = modules; module; module = module->next)
if (strcmp (name, module->file_name) == 0)
{
retval = module;
break;
}
return retval;
}
static inline void
g_module_set_error_unduped (gchar *error)
{
g_static_private_set (&module_error_private, error, g_free);
errno = 0;
}
static inline void
g_module_set_error (const gchar *error)
{
g_module_set_error_unduped (g_strdup (error));
}
/* --- include platform specifc code --- */
#define SUPPORT_OR_RETURN(rv) { g_module_set_error (NULL); }
#if (G_MODULE_IMPL == G_MODULE_IMPL_DL)
#include "gmodule-dl.c"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_DLD)
#include "gmodule-dld.c"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_WIN32)
#include "gmodule-win32.c"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_DYLD)
#include "gmodule-dyld.c"
#elif (G_MODULE_IMPL == G_MODULE_IMPL_AR)
#include "gmodule-ar.c"
#else
#undef SUPPORT_OR_RETURN
#define SUPPORT_OR_RETURN(rv) { g_module_set_error ("dynamic modules are " \
"not supported by this system"); return rv; }
static gpointer
_g_module_open (const gchar *file_name,
gboolean bind_lazy,
gboolean bind_local)
{
return NULL;
}
static void
_g_module_close (gpointer handle,
gboolean is_unref)
{
}
static gpointer
_g_module_self (void)
{
return NULL;
}
static gpointer
_g_module_symbol (gpointer handle,
const gchar *symbol_name)
{
return NULL;
}
static gchar*
_g_module_build_path (const gchar *directory,
const gchar *module_name)
{
return NULL;
}
#endif /* no implementation */
/* --- functions --- */
gboolean
g_module_supported (void)
{
SUPPORT_OR_RETURN (FALSE);
return TRUE;
}
static inline gboolean
str_check_suffix (const gchar* string,
const gchar* suffix)
{
gsize string_len = strlen (string);
gsize suffix_len = strlen (suffix);
return string_len >= suffix_len &&
strcmp (string + string_len - suffix_len, suffix) == 0;
}
enum
{
G_MODULE_DEBUG_RESIDENT_MODULES = 1 << 0,
G_MODULE_DEBUG_BIND_NOW_MODULES = 1 << 1
};
static void
_g_module_debug_init (void)
{
const GDebugKey keys[] = {
{ "resident-modules", G_MODULE_DEBUG_RESIDENT_MODULES },
{ "bind-now-modules", G_MODULE_DEBUG_BIND_NOW_MODULES }
};
const gchar *env;
env = g_getenv ("G_DEBUG");
module_debug_flags =
!env ? 0 : g_parse_debug_string (env, keys, G_N_ELEMENTS (keys));
module_debug_initialized = TRUE;
}
static GStaticRecMutex g_module_global_lock = G_STATIC_REC_MUTEX_INIT;
GModule*
g_module_open (const gchar *file_name,
GModuleFlags flags)
{
GModule *module;
gpointer handle = NULL;
gchar *name = NULL;
SUPPORT_OR_RETURN (NULL);
g_static_rec_mutex_lock (&g_module_global_lock);
if (G_UNLIKELY (!module_debug_initialized))
_g_module_debug_init ();
if (module_debug_flags & G_MODULE_DEBUG_BIND_NOW_MODULES)
flags &= ~G_MODULE_BIND_LAZY;
if (!file_name)
{
if (!main_module)
{
handle = _g_module_self ();
if (handle)
{
main_module = g_new (GModule, 1);
main_module->file_name = NULL;
#if defined (G_OS_WIN32) && !defined(_WIN64)
main_module->cp_file_name = NULL;
#endif
main_module->handle = handle;
main_module->ref_count = 1;
main_module->is_resident = TRUE;
main_module->unload = NULL;
main_module->next = NULL;
}
}
else
main_module->ref_count++;
g_static_rec_mutex_unlock (&g_module_global_lock);
return main_module;
}
/* we first search the module list by name */
module = g_module_find_by_name (file_name);
if (module)
{
module->ref_count++;
g_static_rec_mutex_unlock (&g_module_global_lock);
return module;
}
/* check whether we have a readable file right away */
if (g_file_test (file_name, G_FILE_TEST_IS_REGULAR))
name = g_strdup (file_name);
/* try completing file name with standard library suffix */
if (!name)
{
name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL);
if (!g_file_test (name, G_FILE_TEST_IS_REGULAR))
{
g_free (name);
name = NULL;
}
}
/* try completing by appending libtool suffix */
if (!name)
{
name = g_strconcat (file_name, ".la", NULL);
if (!g_file_test (name, G_FILE_TEST_IS_REGULAR))
{
g_free (name);
name = NULL;
}
}
/* we can't access() the file, lets hope the platform backends finds
* it via library paths
*/
if (!name)
{
gchar *dot = strrchr (file_name, '.');
gchar *slash = strrchr (file_name, G_DIR_SEPARATOR);
/* make sure the name has a suffix */
if (!dot || dot < slash)
name = g_strconcat (file_name, "." G_MODULE_SUFFIX, NULL);
else
name = g_strdup (file_name);
}
/* ok, try loading the module */
if (name)
{
handle = _g_module_open (name, (flags & G_MODULE_BIND_LAZY) != 0,
(flags & G_MODULE_BIND_LOCAL) != 0);
}
else
{
gchar *display_file_name = g_filename_display_name (file_name);
g_module_set_error_unduped (g_strdup_printf ("unable to access file \"%s\"", display_file_name));
g_free (display_file_name);
}
g_free (name);
if (handle)
{
gchar *saved_error;
GModuleCheckInit check_init;
const gchar *check_failed = NULL;
/* search the module list by handle, since file names are not unique */
module = g_module_find_by_handle (handle);
if (module)
{
_g_module_close (module->handle, TRUE);
module->ref_count++;
g_module_set_error (NULL);
g_static_rec_mutex_unlock (&g_module_global_lock);
return module;
}
saved_error = g_strdup (g_module_error ());
g_module_set_error (NULL);
module = g_new (GModule, 1);
module->file_name = g_strdup (file_name);
#if defined (G_OS_WIN32) && !defined(_WIN64)
module->cp_file_name = g_locale_from_utf8 (file_name, -1,
NULL, NULL, NULL);
#endif
module->handle = handle;
module->ref_count = 1;
module->is_resident = FALSE;
module->unload = NULL;
module->next = modules;
modules = module;
/* check initialization */
if (g_module_symbol (module, "g_module_check_init", (gpointer) &check_init) && check_init != NULL)
check_failed = check_init (module);
/* we don't call unload() if the initialization check failed. */
if (!check_failed)
g_module_symbol (module, "g_module_unload", (gpointer) &module->unload);
if (check_failed)
{
gchar *error;
error = g_strconcat ("GModule (", file_name, ") ",
"initialization check failed: ",
check_failed, NULL);
g_module_close (module);
module = NULL;
g_module_set_error (error);
g_free (error);
}
else
g_module_set_error (saved_error);
g_free (saved_error);
}
if (module != NULL &&
(module_debug_flags & G_MODULE_DEBUG_RESIDENT_MODULES))
g_module_make_resident (module);
g_static_rec_mutex_unlock (&g_module_global_lock);
return module;
}
#if defined (G_OS_WIN32) && !defined(_WIN64)
#undef g_module_open
GModule*
g_module_open (const gchar *file_name,
GModuleFlags flags)
{
gchar *utf8_file_name = g_locale_to_utf8 (file_name, -1, NULL, NULL, NULL);
GModule *retval = g_module_open_utf8 (utf8_file_name, flags);
g_free (utf8_file_name);
return retval;
}
#endif
gboolean
g_module_close (GModule *module)
{
SUPPORT_OR_RETURN (FALSE);
g_return_val_if_fail (module != NULL, FALSE);
g_return_val_if_fail (module->ref_count > 0, FALSE);
g_static_rec_mutex_lock (&g_module_global_lock);
module->ref_count--;
if (!module->ref_count && !module->is_resident && module->unload)
{
GModuleUnload unload;
unload = module->unload;
module->unload = NULL;
unload (module);
}
if (!module->ref_count && !module->is_resident)
{
GModule *last;
GModule *node;
last = NULL;
node = modules;
while (node)
{
if (node == module)
{
if (last)
last->next = node->next;
else
modules = node->next;
break;
}
last = node;
node = last->next;
}
module->next = NULL;
_g_module_close (module->handle, FALSE);
g_free (module->file_name);
#if defined (G_OS_WIN32) && !defined(_WIN64)
g_free (module->cp_file_name);
#endif
g_free (module);
}
g_static_rec_mutex_unlock (&g_module_global_lock);
return g_module_error() == NULL;
}
void
g_module_make_resident (GModule *module)
{
g_return_if_fail (module != NULL);
module->is_resident = TRUE;
}
const gchar *
g_module_error (void)
{
return g_static_private_get (&module_error_private);
}
gboolean
g_module_symbol (GModule *module,
const gchar *symbol_name,
gpointer *symbol)
{
const gchar *module_error;
if (symbol)
*symbol = NULL;
SUPPORT_OR_RETURN (FALSE);
g_return_val_if_fail (module != NULL, FALSE);
g_return_val_if_fail (symbol_name != NULL, FALSE);
g_return_val_if_fail (symbol != NULL, FALSE);
g_static_rec_mutex_lock (&g_module_global_lock);
#ifdef G_MODULE_NEED_USCORE
{
gchar *name;
name = g_strconcat ("_", symbol_name, NULL);
*symbol = _g_module_symbol (module->handle, name);
g_free (name);
}
#else /* !G_MODULE_NEED_USCORE */
*symbol = _g_module_symbol (module->handle, symbol_name);
#endif /* !G_MODULE_NEED_USCORE */
module_error = g_module_error ();
if (module_error)
{
gchar *error;
error = g_strconcat ("`", symbol_name, "': ", module_error, NULL);
g_module_set_error (error);
g_free (error);
*symbol = NULL;
}
g_static_rec_mutex_unlock (&g_module_global_lock);
return !module_error;
}
const gchar *
g_module_name (GModule *module)
{
g_return_val_if_fail (module != NULL, NULL);
if (module == main_module)
return "main";
return module->file_name;
}
#if defined (G_OS_WIN32) && !defined(_WIN64)
#undef g_module_name
const gchar *
g_module_name (GModule *module)
{
g_return_val_if_fail (module != NULL, NULL);
if (module == main_module)
return "main";
return module->cp_file_name;
}
#endif
gchar*
g_module_build_path (const gchar *directory,
const gchar *module_name)
{
g_return_val_if_fail (module_name != NULL, NULL);
return _g_module_build_path (directory, module_name);
}

101
deps/gmodule/gmodule.h vendored Normal file
View File

@ -0,0 +1,101 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998 Tim Janik
*
* 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.
*/
/*
* Modified by the GLib Team and others 1997-2000. See the AUTHORS
* file for a list of people on the GLib Team. See the ChangeLog
* files for a list of changes. These files are distributed with
* GLib at ftp://ftp.gtk.org/pub/gtk/.
*/
#ifndef __GMODULE_H__
#define __GMODULE_H__
#include <glib.h>
G_BEGIN_DECLS
/* exporting and importing functions, this is special cased
* to feature Windows dll stubs.
*/
#define G_MODULE_IMPORT extern
#ifdef G_PLATFORM_WIN32
# define G_MODULE_EXPORT __declspec(dllexport)
#else /* !G_PLATFORM_WIN32 */
# define G_MODULE_EXPORT
#endif /* !G_PLATFORM_WIN32 */
typedef enum
{
G_MODULE_BIND_LAZY = 1 << 0,
G_MODULE_BIND_LOCAL = 1 << 1,
G_MODULE_BIND_MASK = 0x03
} GModuleFlags;
typedef struct _GModule GModule;
typedef const gchar* (*GModuleCheckInit) (GModule *module);
typedef void (*GModuleUnload) (GModule *module);
#ifdef G_OS_WIN32
#define g_module_open g_module_open_utf8
#define g_module_name g_module_name_utf8
#endif
/* return TRUE if dynamic module loading is supported */
gboolean g_module_supported (void) G_GNUC_CONST;
/* open a module `file_name' and return handle, which is NULL on error */
GModule* g_module_open (const gchar *file_name,
GModuleFlags flags);
/* close a previously opened module, returns TRUE on success */
gboolean g_module_close (GModule *module);
/* make a module resident so g_module_close on it will be ignored */
void g_module_make_resident (GModule *module);
/* query the last module error as a string */
const gchar * g_module_error (void);
/* retrieve a symbol pointer from `module', returns TRUE on success */
gboolean g_module_symbol (GModule *module,
const gchar *symbol_name,
gpointer *symbol);
/* retrieve the file name from an existing module */
const gchar * g_module_name (GModule *module);
/* Build the actual file name containing a module. `directory' is the
* directory where the module file is supposed to be, or NULL or empty
* in which case it should either be in the current directory or, on
* some operating systems, in some standard place, for instance on the
* PATH. Hence, to be absoultely sure to get the correct module,
* always pass in a directory. The file name consists of the directory,
* if supplied, and `module_name' suitably decorated according to
* the operating system's conventions (for instance lib*.so or *.dll).
*
* No checks are made that the file exists, or is of correct type.
*/
gchar* g_module_build_path (const gchar *directory,
const gchar *module_name);
G_END_DECLS
#endif /* __GMODULE_H__ */

54
deps/gmodule/gmoduleconf.h.in vendored Normal file
View File

@ -0,0 +1,54 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998 Tim Janik
*
* 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 __G_MODULE_CONF_H__
#define __G_MODULE_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define G_MODULE_IMPL_NONE 0
#define G_MODULE_IMPL_DL 1
#define G_MODULE_IMPL_DLD 2
#define G_MODULE_IMPL_WIN32 3
#define G_MODULE_IMPL_OS2 4
#define G_MODULE_IMPL_BEOS 5
#define G_MODULE_IMPL_DYLD 6
#define G_MODULE_IMPL_AR 7
#define G_MODULE_IMPL @G_MODULE_IMPL@
#undef G_MODULE_HAVE_DLERROR
#if (@G_MODULE_HAVE_DLERROR@)
#define G_MODULE_HAVE_DLERROR
#endif
#if (@G_MODULE_NEED_USCORE@) || defined (hp9000s300) || defined (__hp9000s300) || defined (__hp9000s300__)
#define G_MODULE_NEED_USCORE
#endif
#if (@G_MODULE_BROKEN_RTLD_GLOBAL@)
#define G_MODULE_BROKEN_RTLD_GLOBAL
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __G_MODULE_CONF_H__ */

44
deps/gmodule/gmoduleconf.h.win32 vendored Normal file
View File

@ -0,0 +1,44 @@
/* GMODULE - GLIB wrapper code for dynamic module loading
* Copyright (C) 1998 Tim Janik
*
* 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 __G_MODULE_CONF_H__
#define __G_MODULE_CONF_H__
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define G_MODULE_IMPL_NONE 0
#define G_MODULE_IMPL_DL 1
#define G_MODULE_IMPL_DLD 2
#define G_MODULE_IMPL_WIN32 3
#define G_MODULE_IMPL_OS2 4
#define G_MODULE_IMPL_BEOS 5
#define G_MODULE_IMPL_DYLD 6
#define G_MODULE_IMPL G_MODULE_IMPL_WIN32
#undef G_MODULE_HAVE_DLERROR
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __G_MODULE_CONF_H__ */

View File

@ -1,7 +1,8 @@
include $(top_srcdir)/build/autotools/Makefile.am.silent
INCLUDES = \
-I$(top_srcdir)
-I$(top_srcdir) \
-I$(top_builddir)/deps/glib
AM_CFLAGS = \
$(COGL_DEP_CFLAGS) \
@ -16,6 +17,7 @@ endif
common_ldadd = \
$(COGL_DEP_LIBS) \
$(top_builddir)/deps/glib/libglib.la \
$(top_builddir)/cogl/libcogl.la
programs = cogl-info

View File

@ -110,7 +110,8 @@ BUILT_SOURCES = wrappers
# testing (such as test-bitmask) will still compile
INCLUDES = \
-I$(top_srcdir) \
-I$(top_builddir)/cogl
-I$(top_builddir)/cogl \
-I$(top_builddir)/deps/glib
test_conformance_CPPFLAGS = \
-DCOGL_ENABLE_EXPERIMENTAL_API \
@ -120,6 +121,9 @@ test_conformance_CPPFLAGS = \
test_conformance_CFLAGS = -g3 -O0 $(COGL_DEP_CFLAGS) $(COGL_EXTRA_CFLAGS)
test_conformance_LDADD = $(COGL_DEP_LIBS) $(top_builddir)/cogl/libcogl.la
if !USE_GLIB
test_conformance_LDADD += $(top_builddir)/deps/glib/libglib.la
endif
test_conformance_LDFLAGS = -export-dynamic
test: wrappers