From ade8ccaa16a6acb91816e48ca467a125b5c16141 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Fri, 5 Oct 2012 14:49:17 +0900 Subject: [PATCH] another try to clean up glib dependencies --- liblangtag/langtag.h | 3 ++ liblangtag/lt-error.h | 4 ++ liblangtag/lt-ext-module.c | 93 +++++++++++++++++++++++--------------- liblangtag/lt-list.h | 4 ++ liblangtag/lt-macros.h | 12 +++-- tests/Makefile.am | 1 - tests/main.c | 61 +++++++------------------ tests/main.h | 15 +++--- 8 files changed, 100 insertions(+), 93 deletions(-) diff --git a/liblangtag/langtag.h b/liblangtag/langtag.h index 9fe3633..e73ac78 100644 --- a/liblangtag/langtag.h +++ b/liblangtag/langtag.h @@ -14,9 +14,12 @@ #define __LANGTAG_H__ #define __LANGTAG_H__INSIDE +#include #include #include #include +#include +#include #include #undef __LANGTAG_H__INSIDE diff --git a/liblangtag/lt-error.h b/liblangtag/lt-error.h index 0b6ff50..07d9127 100644 --- a/liblangtag/lt-error.h +++ b/liblangtag/lt-error.h @@ -10,6 +10,10 @@ * Lesser General Public License or the Mozilla Public * License, as specified in the README file. */ +#if !defined (__LANGTAG_H__INSIDE) && !defined (__LANGTAG_COMPILATION) +#error "Only can be included directly." +#endif + #ifndef __LT_ERROR_H__ #define __LT_ERROR_H__ diff --git a/liblangtag/lt-ext-module.c b/liblangtag/lt-ext-module.c index 4298d3b..a043e3f 100644 --- a/liblangtag/lt-ext-module.c +++ b/liblangtag/lt-ext-module.c @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -201,36 +202,43 @@ lt_ext_module_load(lt_ext_module_t *module) lt_string_t *fullname = lt_string_new(NULL); char *filename = lt_strdup_printf("liblangtag-ext-%s." G_MODULE_SUFFIX, module->name); - char **path_list, *s, *path = NULL; + char *path_list, *p, *s, *path; const char *env = getenv("LANGTAG_EXT_MODULE_PATH"); - int i; lt_bool_t retval = FALSE; size_t len; if (!env) { - path_list = g_strsplit( + path_list = strdup( #ifdef GNOME_ENABLE_DEBUG - BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_SEARCHPATH_SEPARATOR_S - BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_DIR_SEPARATOR_S ".libs" G_SEARCHPATH_SEPARATOR_S + BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_SEARCHPATH_SEPARATOR_S + BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_DIR_SEPARATOR_S ".libs" LT_SEARCHPATH_SEPARATOR_S #endif - LANGTAG_EXT_MODULE_PATH, - G_SEARCHPATH_SEPARATOR_S, - -1); + LANGTAG_EXT_MODULE_PATH); } else { - path_list = g_strsplit(env, G_SEARCHPATH_SEPARATOR_S, -1); + path_list = strdup(env); } - for (i = 0; path_list[i] != NULL && !retval; i++) { - s = path_list[i]; - - while (*s && isspace(*s)) + s = path_list; + do { + if (!s) + break; + p = strchr(s, LT_SEARCHPATH_SEPARATOR); + if (p == s) { s++; - len = strlen(s); - while (len > 0 && isspace(s[len - 1])) + continue; + } + path = s; + if (p) { + *p = 0; + p++; + } + s = p; + while (*path && isspace(*path)) + path++; + len = strlen(path); + while (len > 0 && isspace(path[len - 1])) len--; - if (path) - free(path); - path = strndup(s, len); + path[len] = 0; if (path[0] != 0) { lt_string_clear(fullname); if (!lt_string_append_filename(fullname, path, filename, NULL)) { @@ -274,14 +282,13 @@ lt_ext_module_load(lt_ext_module_t *module) retval = TRUE; } } - } + } while (1); if (!retval) lt_warning("No such modules: %s", module->name); lt_string_unref(fullname); - free(path); free(filename); - g_strfreev(path_list); + free(path_list); return retval; } @@ -374,7 +381,8 @@ lt_ext_module_new(const char *name) retval = lt_mem_alloc_object(sizeof (lt_ext_module_t)); if (retval) { - char *filename = g_path_get_basename(name), *module = NULL; + char *n = strdup(name); + char *filename = basename(n), *module = NULL; static const char *prefix = "liblangtag-ext-"; static size_t prefix_len = 0; char singleton_c; @@ -399,7 +407,7 @@ lt_ext_module_new(const char *name) lt_mem_add_ref(&retval->parent, retval->name, (lt_destroy_func_t)free); - g_free(filename); + free(n); if (!lt_ext_module_load(retval)) { lt_ext_module_unref(retval); @@ -555,28 +563,40 @@ lt_ext_modules_load(void) { #ifdef ENABLE_GMODULE const char *env = getenv("LANGTAG_EXT_MODULE_PATH"); - char **path_list; - int i; + char *path_list, *s, *p, *path; size_t suffix_len = strlen(G_MODULE_SUFFIX) + 1; if (__lt_ext_module_initialized) return; if (!env) { - path_list = g_strsplit( + path_list = strdup( #ifdef GNOME_ENABLE_DEBUG - BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_SEARCHPATH_SEPARATOR_S - BUILDDIR G_DIR_SEPARATOR_S "liblangtag" G_DIR_SEPARATOR_S "extensions" G_DIR_SEPARATOR_S ".libs" G_SEARCHPATH_SEPARATOR_S + BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_SEARCHPATH_SEPARATOR_S + BUILDDIR LT_DIR_SEPARATOR_S "liblangtag" LT_DIR_SEPARATOR_S "extensions" LT_DIR_SEPARATOR_S ".libs" LT_SEARCHPATH_SEPARATOR_S #endif - LANGTAG_EXT_MODULE_PATH, - G_SEARCHPATH_SEPARATOR_S, - -1); + LANGTAG_EXT_MODULE_PATH); } else { - path_list = g_strsplit(env, G_SEARCHPATH_SEPARATOR_S, -1); + path_list = strdup(env); } - for (i = 0; path_list[i] != NULL; i++) { + s = path_list; + do { DIR *dir; - dir = opendir(path_list[i]); + if (!s) + break; + p = strchr(s, LT_SEARCHPATH_SEPARATOR); + if (s == p) { + s++; + continue; + } + path = s; + if (p) { + *p = 0; + p++; + } + s = p; + + dir = opendir(path); if (dir) { struct dirent dent, *dresult; size_t len; @@ -594,8 +614,9 @@ lt_ext_modules_load(void) } closedir(dir); } - } - g_strfreev(path_list); + } while (1); + + free(path_list); #endif /* ENABLE_GMODULE */ __lt_ext_default_handler = lt_ext_module_new_with_data("default", &__default_funcs); diff --git a/liblangtag/lt-list.h b/liblangtag/lt-list.h index 17563b9..13494b4 100644 --- a/liblangtag/lt-list.h +++ b/liblangtag/lt-list.h @@ -10,6 +10,10 @@ * Lesser General Public License or the Mozilla Public * License, as specified in the README file. */ +#if !defined (__LANGTAG_H__INSIDE) && !defined (__LANGTAG_COMPILATION) +#error "Only can be included directly." +#endif + #ifndef __LT_LIST_H__ #define __LT_LIST_H__ diff --git a/liblangtag/lt-macros.h b/liblangtag/lt-macros.h index fe09f25..b4ab5a3 100644 --- a/liblangtag/lt-macros.h +++ b/liblangtag/lt-macros.h @@ -99,11 +99,15 @@ /* Macros for path separator */ #ifdef _WIN32 -# define LT_DIR_SEPARATOR_S "\\" -# define LT_DIR_SEPARATOR '\\' +# define LT_DIR_SEPARATOR_S "\\" +# define LT_DIR_SEPARATOR '\\' +# define LT_SEARCHPATH_SEPARATOR_S ";" +# define LT_SEARCHPATH_SEPARATOR ';' #else -# define LT_DIR_SEPARATOR_S "/" -# define LT_DIR_SEPARATOR '/' +# define LT_DIR_SEPARATOR_S "/" +# define LT_DIR_SEPARATOR '/' +# define LT_SEARCHPATH_SEPARATOR_S ":" +# define LT_SEARCHPATH_SEPARATOR ':' #endif /* Macros for min/max */ diff --git a/tests/Makefile.am b/tests/Makefile.am index 4330ea8..53c4044 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -8,7 +8,6 @@ INCLUDES = \ -DTEST_DATADIR="\"$(abs_top_builddir)/data\"" \ -DTEST_MODDIR="\"$(abs_top_builddir)/liblangtag/extensions/.libs\"" \ -D__LANGTAG_COMPILATION \ - $(GLIB_CFLAGS) \ $(CHECK_CFLAGS) \ $(NULL) DEPS = \ diff --git a/tests/main.c b/tests/main.c index 3528e32..ce05af3 100644 --- a/tests/main.c +++ b/tests/main.c @@ -18,80 +18,53 @@ #include #include #include -#include +#include "langtag.h" +#include "lt-messages.h" #include "main.h" extern Suite *tester_suite(void); -static GLogFunc old_logger = NULL; -static GError *error = NULL; -G_LOCK_DEFINE_STATIC(err); +static lt_message_func_t old_logger = NULL; +static lt_error_t *error = NULL; /* * Private functions */ static void -logger(const gchar *log_domain, - GLogLevelFlags log_level, - const gchar *message, - gpointer user_data) +logger(lt_message_type_t type, + lt_message_flags_t flags, + lt_message_category_t category, + const char *message, + lt_pointer_t user_data) { - gchar *prev = NULL; - - G_LOCK (err); - - if (error) { - prev = g_strdup_printf("\n %s", error->message); - g_error_free(error); - error = NULL; - } - g_set_error(&error, TESTER_ERROR, log_level, - "%s%s", message, - (prev ? prev : "")); - g_free(prev); - - G_UNLOCK (err); + lt_error_set(&error, type, message); } static void init(int argc, char **argv) { - old_logger = g_log_set_default_handler(logger, NULL); + old_logger = lt_message_set_default_handler(logger, NULL); } static void fini(void) { + tester_pop_error(); if (old_logger) - g_log_set_default_handler(old_logger, NULL); + lt_message_set_default_handler(old_logger, NULL); } /* * Public functions */ -GQuark -tester_get_error_quark(void) -{ - GQuark quark = 0; - - if (!quark) - quark = g_quark_from_static_string("tester-error"); - - return quark; -} - -gchar * +void tester_pop_error(void) { - gchar *retval = NULL; - - if (error) { - retval = g_strdup(error->message); - g_clear_error(&error); + if (lt_error_is_set(error, LT_ERR_ANY)) { + lt_error_print(error, LT_ERR_ANY); + lt_error_clear(error); } - - return retval; } int diff --git a/tests/main.h b/tests/main.h index 1b9753a..7ac0e86 100644 --- a/tests/main.h +++ b/tests/main.h @@ -15,9 +15,9 @@ #define __TEST_MAIN_H__ #include -#include +#include -G_BEGIN_DECLS +LT_BEGIN_DECLS #define TESTER_ERROR tester_get_error_quark() #define TDEF(fn) START_TEST (test_ ## fn) @@ -26,12 +26,11 @@ G_BEGIN_DECLS #define TNUL(obj) fail_unless((obj) != NULL, "Failed to create an object") -void setup (void); -void teardown (void); -Suite *tester_suite (void); -GQuark tester_get_error_quark(void); -gchar *tester_pop_error (void) G_GNUC_MALLOC; +void setup (void); +void teardown (void); +Suite *tester_suite (void); +void tester_pop_error(void); -G_END_DECLS +LT_END_DECLS #endif /* __TEST_MAIN_H__ */