Permalink
Browse files

Get rid of all of glib dependencies

  • Loading branch information...
1 parent 0c2bcc5 commit 8efe65de87718d23dd7959e6ae65782ecad02068 @tagoh committed Oct 11, 2012
Showing with 155 additions and 30 deletions.
  1. +41 −23 configure.ac
  2. +1 −1 liblangtag/Makefile.am
  3. +108 −0 liblangtag/lt-atomic.h
  4. +2 −2 liblangtag/lt-ext-module-data.c
  5. +3 −3 liblangtag/lt-mem.c
  6. +0 −1 requires
View
@@ -93,41 +93,41 @@ CFLAGS=$_save_cflags
AC_MSG_RESULT($have_gnuc_varargs)
dnl inline
-AC_CACHE_CHECK([for __inline],lt_cv_has__inline,[
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+AC_CACHE_CHECK([for __inline], [lt_cv_has__inline],
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__inline int foo(void);
__inline int foo() {return 0;}
int main() {return foo();}
]])],
- lt_cv_has__inline=yes,
- lt_cv_has__inline=no,)
+ [lt_cv_has__inline=yes],
+ [lt_cv_has__inline=no], [])
])
case x$lt_cv_has__inline in
xyes)
AC_DEFINE(LT_HAVE___INLINE,1,[Have __inline keyword])
esac
-AC_CACHE_CHECK([for __inline__],lt_cv_has__inline__,[
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+AC_CACHE_CHECK([for __inline__], [lt_cv_has__inline__],
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
__inline__ int foo(void);
__inline__ int foo() {return 0;}
int main() {return foo();}
]])],
- lt_cv_has__inline__=yes,
- lt_cv_has__inline__=no,)
+ [lt_cv_has__inline__=yes],
+ [lt_cv_has__inline__=no], [])
])
case x$lt_cv_has__inline__ in
xyes)
AC_DEFINE(LT_HAVE___INLINE__,1,[Have __inline__ keyword])
esac
-AC_CACHE_CHECK([for inline],lt_cv_hasinline,[
- AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
+AC_CACHE_CHECK([for inline], [lt_cv_hasinline],
+ [AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#undef inline
inline int foo(void);
inline int foo() {return 0;}
int main() {return foo();}
]])],
- lt_cv_hasinline=yes,
- lt_cv_hasinline=no,)
+ [lt_cv_hasinline=yes],
+ [lt_cv_hasinline=no], [])
])
case x$lt_cv_hasinline in
xyes)
@@ -156,6 +156,30 @@ lt_test_func1(void) {
int main(void) {int i = 1; return --i;}]])],[lt_can_inline=yes;AC_DEFINE(LT_CAN_INLINE, 1, [Wheter inline statement can be used])],[lt_can_inline=no])
AC_MSG_RESULT($lt_can_inline)
+dnl ---build-in atomic functions---
+AC_CACHE_CHECK([for gcc atomic builtins], [lt_cv_has_atomic],
+ [AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
+int i, j = 0;
+i = __sync_fetch_and_add(&j, 1);
+__sync_synchronize();
+j = __sync_fetch_and_sub(&i, 1);
+return j;
+ ]])], [lt_cv_has_atomic=yes],
+ [_save_cflags="$CFLAGS"
+ CFLAGS="$CFLAGS -march=i486"
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([], [[
+int i, j = 0;
+i = __sync_fetch_and_add(&j, 1);
+__sync_synchronize();
+j = __sync_fetch_and_sub(&i, 1);
+return j;
+ ]])], [AC_MSG_ERROR([liblangtag has to be built with -march=i486 or later.])]
+ [lt_cv_has_atomic=no])])
+])
+if test "x$lt_cv_has_atomic" = "xyes"; then
+ AC_DEFINE(LT_HAVE_ATOMIC_BUILTINS, 1, [Have buit-in atomic functions])
+fi
+
dnl ---alignment---
AC_CHECK_ALIGNOF(void *)
@@ -166,11 +190,11 @@ dnl ======================================================================
dnl ======================================================================
dnl gettext stuff
dnl ======================================================================
-GETTEXT_PACKAGE=$PACKAGE
-AC_SUBST(GETTEXT_PACKAGE)
-AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Gettext package])
-
-AM_GLIB_GNU_GETTEXT
+dnl GETTEXT_PACKAGE=$PACKAGE
+dnl AC_SUBST(GETTEXT_PACKAGE)
+dnl AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, "$GETTEXT_PACKAGE", [Gettext package])
+dnl
+dnl AM_GLIB_GNU_GETTEXT
dnl ======================================================================
dnl options
@@ -271,12 +295,6 @@ dnl ======================================================================
AX_PTHREAD([],
[AC_MSG_ERROR([*** pthread library are required])])
-AM_PATH_GLIB_2_0($GLIB_REQUIRED, :,
- AC_MSG_ERROR([
-*** GLIB $GLIB_REQUIRED_VERSION or better is required. The latest version of
-*** GLIB is always available from ftp://ftp.gtk.org/.]),
- glib)
-
GOBJECT_INTROSPECTION_CHECK([1.30.0])
GTK_DOC_CHECK(1.0)
@@ -12,7 +12,6 @@ INCLUDES = \
-DSRCDIR="\"$(abs_top_srcdir)\"" \
-DREGDATADIR="\"$(datadir)/liblangtag\"" \
-DLANGTAG_EXT_MODULE_PATH="\"$(LANGTAG_MODULEDIR)\"" \
- $(GLIB_CFLAGS) \
$(LIBXML2_CFLAGS) \
$(PTHREAD_CFLAGS) \
$(NULL)
@@ -68,6 +67,7 @@ liblangtag_public_headers = \
lt-variant-db.h \
$(NULL)
liblangtag_private_headers = \
+ lt-atomic.h \
lt-ext-module-private.h \
lt-extension-private.h \
lt-extlang-private.h \
View
@@ -0,0 +1,108 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * lt-atomic.h
+ * Copyright (C) 2011-2012 Akira TAGOH
+ *
+ * Authors:
+ * Akira TAGOH <akira@tagoh.org>
+ *
+ * You may distribute under the terms of either the GNU
+ * Lesser General Public License or the Mozilla Public
+ * License, as specified in the README file.
+ */
+#ifndef __LT_ATOMIC_H__
+#define __LT_ATOMIC_H__
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <pthread.h>
+#include "lt-messages.h"
+
+LT_BEGIN_DECLS
+
+LT_INLINE_FUNC int lt_atomic_int_get (volatile int *v);
+LT_INLINE_FUNC int lt_atomic_int_inc (volatile int *v);
+LT_INLINE_FUNC lt_bool_t lt_atomic_int_dec_and_test(volatile int *v);
+
+#ifndef LT_HAVE_ATOMIC_BUILTINS
+static pthread_mutex_t __lt_atomic_lock = PTHREAD_MUTEX_INITIALIZER;
+#endif
+
+/*< private >*/
+
+/*< public >*/
+#ifdef LT_HAVE_ATOMIC_BUILTINS
+LT_INLINE_FUNC int
+lt_atomic_int_get(volatile int *v)
+{
+ lt_return_val_if_fail (v != NULL, 0);
+
+ __sync_synchronize();
+ return *v;
+}
+
+LT_INLINE_FUNC int
+lt_atomic_int_inc(volatile int *v)
+{
+ lt_return_val_if_fail (v != NULL, 0);
+
+ return __sync_fetch_and_add(v, 1);
+}
+
+lt_bool_t
+lt_atomic_int_dec_and_test(volatile int *v)
+{
+ lt_return_val_if_fail (v != NULL, FALSE);
+
+ return __sync_fetch_and_sub(v, 1) == 1;
+}
+
+#else /* !LT_HAVE_ATOMIC_BUILTINS */
+LT_INLINE_FUNC int
+lt_atomic_int_get(volatile int *v)
+{
+ volatile int retval;
+
+ lt_return_val_if_fail (v != NULL, 0);
+
+ pthread_mutex_lock(&__lt_atomic_lock);
+ retval = *v;
+ pthread_mutex_unlock(&__lt_atomic_lock);
+
+ return retval;
+}
+
+LT_INLINE_FUNC int
+lt_atomic_int_inc(volatile int *v)
+{
+ int retval;
+
+ lt_return_val_if_fail (v != NULL, 0);
+
+ pthread_mutex_lock(&__lt_atomic_lock);
+ retval = (*v)++;
+ pthread_mutex_unlock(&__lt_atomic_lock);
+
+ return retval;
+}
+
+LT_INLINE_FUNC lt_bool_t
+lt_atomic_int_dec_and_test(volatile int *v)
+{
+ lt_bool_t retval;
+
+ lt_return_if_fail (v != NULL, FALSE);
+
+ pthread_mutex_lock(&__lt_atomic_lock);
+ retval = --(*v) == 0;
+ pthread_mutex_unlock(&__lt_atomic_lock);
+
+ return retval;
+}
+#endif /* LT_HAVE_ATOMIC_BUILTINS */
+
+LT_END_DECLS
+
+#endif /* __LT_ATOMIC_H__ */
@@ -14,8 +14,8 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: atomic function is still used */
#include <stdlib.h>
+#include "lt-atomic.h"
#include "lt-mem.h"
#include "lt-messages.h"
#include "lt-ext-module-data.h"
@@ -104,7 +104,7 @@ lt_ext_module_data_unref(lt_ext_module_data_t *data)
lt_ext_module_data_private_t *priv = (lt_ext_module_data_private_t *)data;
if (data) {
- volatile int ref_count = g_atomic_int_get(&priv->parent.ref_count);
+ volatile int ref_count = lt_atomic_int_get((volatile int *)&priv->parent.ref_count);
if (ref_count == 1) {
if (priv->finalizer) {
View
@@ -14,8 +14,8 @@
#include "config.h"
#endif
-#include <glib.h> /* XXX: atomic functions is still used */
#include <stdlib.h>
+#include "lt-atomic.h"
#include "lt-mem.h"
#include "lt-messages.h"
@@ -168,7 +168,7 @@ lt_mem_ref(lt_mem_t *object)
{
lt_return_val_if_fail (object != NULL, NULL);
- g_atomic_int_inc(&object->ref_count);
+ lt_atomic_int_inc((volatile int *)&object->ref_count);
return object;
}
@@ -178,7 +178,7 @@ lt_mem_unref(lt_mem_t *object)
{
lt_return_if_fail (object != NULL);
- if (g_atomic_int_dec_and_test(&object->ref_count)) {
+ if (lt_atomic_int_dec_and_test((volatile int *)&object->ref_count)) {
lt_mem_slist_t *ll, *l;
if (object->refs) {
View
@@ -1,4 +1,3 @@
CHECK_REQUIRED=0.9.4
-GLIB_REQUIRED=2.14.0
GOBJECT_REQUIRED=2.0
LIBXML2_REQUIRED=2.1.0

0 comments on commit 8efe65d

Please sign in to comment.