Mercurial > pidgin
changeset 29082:39716f7d2c93
Kill off unneeded GLIB_CHECK_VERSION checks in libpurple. Refs #10024.
author | John Bailey <rekkanoryo@rekkanoryo.org> |
---|---|
date | Sat, 22 Aug 2009 21:47:20 +0000 |
parents | 299ef6fd1a23 |
children | 99ab74fb312c |
files | libpurple/core.c libpurple/internal.h libpurple/plugin.c libpurple/plugins/autoaccept.c libpurple/protocols/jabber/jingle/session.c libpurple/protocols/msn/nexus.c libpurple/protocols/msn/state.c libpurple/protocols/yahoo/libymsg.c libpurple/util.c libpurple/win32/libc_interface.c libpurple/win32/libc_interface.h libpurple/win32/libc_internal.h |
diffstat | 12 files changed, 5 insertions(+), 531 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/core.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/core.c Sat Aug 22 21:47:20 2009 +0000 @@ -496,7 +496,6 @@ if (purple_strequal(entry, "logs")) { char *link; -#if GLIB_CHECK_VERSION(2,4,0) GError *err = NULL; if ((link = g_file_read_link(name, &err)) == NULL) @@ -512,27 +511,6 @@ g_free(old_user_dir); return FALSE; } -#else - char buf[MAXPATHLEN]; - size_t linklen; - - if ((linklen = readlink(name, buf, sizeof(buf) - 1) == -1)) - { - char *name_utf8 = g_filename_to_utf8(name, -1, NULL, NULL, NULL); - purple_debug_error("core", "Error reading symlink %s: %s. Please report this at " PURPLE_DEVEL_WEBSITE "\n", - name_utf8, g_strerror(errno)); - g_free(name_utf8); - g_free(name); - g_dir_close(dir); - g_free(status_file); - g_free(old_user_dir); - return FALSE; - } - buf[linklen] = '\0'; - - /* This way we don't have to GLIB_VERSION_CHECK every g_free(link) below. */ - link = g_strdup(buf); -#endif logs_dir = g_build_filename(user_dir, "logs", NULL);
--- a/libpurple/internal.h Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/internal.h Sat Aug 22 21:47:20 2009 +0000 @@ -118,36 +118,13 @@ # include <unistd.h> #endif -/* MAXPATHLEN should only be used with readlink() on glib < 2.4.0. For - * anything else, use g_file_read_link() or other dynamic functions. This is - * important because Hurd has no hard limits on path length. */ -#if !GLIB_CHECK_VERSION(2,4,0) -# ifndef MAXPATHLEN -# ifdef PATH_MAX -# define MAXPATHLEN PATH_MAX -# else -# define MAXPATHLEN 1024 -# endif -# endif -#endif - #ifndef HOST_NAME_MAX # define HOST_NAME_MAX 255 #endif #include <glib.h> -#if !GLIB_CHECK_VERSION(2,4,0) -# define G_MAXUINT32 ((guint32) 0xffffffff) -#endif -#ifndef G_MAXSIZE -# if GLIB_SIZEOF_LONG == 8 -# define G_MAXSIZE ((gsize) 0xffffffffffffffff) -# else -# define G_MAXSIZE ((gsize) 0xffffffff) -# endif -#endif - +/* This wasn't introduced until Glib 2.14 :( */ #ifndef G_MAXSSIZE # if GLIB_SIZEOF_LONG == 8 # define G_MAXSSIZE ((gssize) 0x7fffffffffffffff) @@ -156,80 +133,12 @@ # endif #endif -#if GLIB_CHECK_VERSION(2,6,0) -# include <glib/gstdio.h> -#endif - -#if !GLIB_CHECK_VERSION(2,6,0) -# define g_freopen freopen -# define g_fopen fopen -# define g_rmdir rmdir -# define g_remove remove -# define g_unlink unlink -# define g_lstat lstat -# define g_stat stat -# define g_mkdir mkdir -# define g_rename rename -# define g_open open -#endif - -#if !GLIB_CHECK_VERSION(2,8,0) && !defined _WIN32 -# define g_access access -#endif - -#if !GLIB_CHECK_VERSION(2,10,0) -# define g_slice_new(type) g_new(type, 1) -# define g_slice_new0(type) g_new0(type, 1) -# define g_slice_free(type, mem) g_free(mem) -#endif +#include <glib/gstdio.h> #ifdef _WIN32 #include "win32dep.h" #endif -/* ugly ugly ugly */ -/* This is a workaround for the fact that G_GINT64_MODIFIER and G_GSIZE_FORMAT - * are only defined in Glib >= 2.4 */ -#ifndef G_GINT64_MODIFIER -# if GLIB_SIZEOF_LONG == 8 -# define G_GINT64_MODIFIER "l" -# else -# define G_GINT64_MODIFIER "ll" -# endif -#endif - -#ifndef G_GSIZE_MODIFIER -# if GLIB_SIZEOF_LONG == 8 -# define G_GSIZE_MODIFIER "l" -# else -# define G_GSIZE_MODIFIER "" -# endif -#endif - -#ifndef G_GSIZE_FORMAT -# if GLIB_SIZEOF_LONG == 8 -# define G_GSIZE_FORMAT "lu" -# else -# define G_GSIZE_FORMAT "u" -# endif -#endif - -#ifndef G_GSSIZE_FORMAT -# if GLIB_SIZEOF_LONG == 8 -# define G_GSSIZE_FORMAT "li" -# else -# define G_GSSIZE_FORMAT "i" -# endif -#endif - -#ifndef G_GNUC_NULL_TERMINATED -# if __GNUC__ >= 4 -# define G_GNUC_NULL_TERMINATED __attribute__((__sentinel__)) -# else -# define G_GNUC_NULL_TERMINATED -# endif -#endif - #ifdef HAVE_CONFIG_H #if SIZEOF_TIME_T == 4 # define PURPLE_TIME_T_MODIFIER "lu" @@ -242,38 +151,6 @@ #include <glib-object.h> -#ifndef G_DEFINE_TYPE -#define G_DEFINE_TYPE(TypeName, type_name, TYPE_PARENT) \ -\ -static void type_name##_init (TypeName *self); \ -static void type_name##_class_init (TypeName##Class *klass); \ -static gpointer type_name##_parent_class = NULL; \ -static void type_name##_class_intern_init (gpointer klass) \ -{ \ - type_name##_parent_class = g_type_class_peek_parent (klass); \ - type_name##_class_init ((TypeName##Class*) klass); \ -} \ -\ -GType \ -type_name##_get_type (void) \ -{ \ - static GType g_define_type_id = 0; \ - if (G_UNLIKELY (g_define_type_id == 0)) \ - { \ - g_define_type_id = \ - g_type_register_static_simple (TYPE_PARENT, \ - g_intern_static_string (#TypeName), \ - sizeof (TypeName##Class), \ - (GClassInitFunc)type_name##_class_intern_init, \ - sizeof (TypeName), \ - (GInstanceInitFunc)type_name##_init, \ - (GTypeFlags) 0); \ - } \ - return g_define_type_id; \ -} /* closes type_name##_get_type() */ - -#endif - /* Safer ways to work with static buffers. When using non-static * buffers, either use g_strdup_* functions (preferred) or use * g_strlcpy/g_strlcpy directly. */
--- a/libpurple/plugin.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/plugin.c Sat Aug 22 21:47:20 2009 +0000 @@ -254,11 +254,7 @@ * * G_MODULE_BIND_LOCAL was added in glib 2.3.3. */ -#if GLIB_CHECK_VERSION(2,3,3) plugin->handle = g_module_open(filename, G_MODULE_BIND_LOCAL); -#else - plugin->handle = g_module_open(filename, 0); -#endif if (plugin->handle == NULL) { @@ -287,11 +283,7 @@ purple_debug_error("plugins", "%s is not loadable: %s\n", plugin->path, plugin->error); } -#if GLIB_CHECK_VERSION(2,3,3) plugin->handle = g_module_open(filename, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); -#else - plugin->handle = g_module_open(filename, G_MODULE_BIND_LAZY); -#endif if (plugin->handle == NULL) {
--- a/libpurple/plugins/autoaccept.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/plugins/autoaccept.c Sat Aug 22 21:47:20 2009 +0000 @@ -28,13 +28,7 @@ /* System headers */ #include <glib.h> -#if GLIB_CHECK_VERSION(2,6,0) -# include <glib/gstdio.h> -#else -# include <sys/types.h> -# include <sys/stat.h> -# define g_mkdir mkdir -#endif +#include <glib/gstdio.h> /* Purple headers */ #include <plugin.h>
--- a/libpurple/protocols/jabber/jingle/session.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/protocols/jabber/jingle/session.c Sat Aug 22 21:47:20 2009 +0000 @@ -367,7 +367,6 @@ g_hash_table_lookup(js->sessions, sid) : NULL; } -#if GLIB_CHECK_VERSION(2,4,0) static gboolean find_by_jid_ghr(gpointer key, gpointer value, gpointer user_data) { @@ -387,58 +386,12 @@ return FALSE; } -#else /* GLIB_CHECK_VERSION 2.4.0 */ - -/* Ugly code; g_hash_table_find version above is much nicer */ -struct session_find_jid -{ - const gchar *jid; - JingleSession *ret; - gboolean use_bare; -}; - -static void find_by_jid_ghr(gpointer key, gpointer value, gpointer user_data) -{ - JingleSession *session = (JingleSession *)value; - struct session_find_jid *data = user_data; - gchar *remote_jid; - gchar *cmp_jid; - - if (data->ret != NULL) - return; - - remote_jid = jingle_session_get_remote_jid(session); - cmp_jid = data->use_bare ? jabber_get_bare_jid(remote_jid) - : g_strdup(remote_jid); - g_free(remote_jid); - - if (g_str_equal(data->jid, cmp_jid)) - data->ret = session; - - g_free(cmp_jid); -} -#endif /* GLIB_CHECK_VERSION 2.4.0 */ - JingleSession * jingle_session_find_by_jid(JabberStream *js, const gchar *jid) { -#if GLIB_CHECK_VERSION(2,4,0) return js->sessions != NULL ? g_hash_table_find(js->sessions, find_by_jid_ghr, (gpointer)jid) : NULL; -#else - struct session_find_jid data; - - if (js->sessions == NULL) - return NULL; - - data.jid = jid; - data.ret = NULL; - data.use_bare = g_utf8_strchr(jid, -1, '/') == NULL; - - g_hash_table_foreach(js->sessions, find_by_jid_ghr, &data); - return data.ret; -#endif } static xmlnode *
--- a/libpurple/protocols/msn/nexus.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/protocols/msn/nexus.c Sat Aug 22 21:47:20 2009 +0000 @@ -244,15 +244,6 @@ gpointer data; }; -#if !GLIB_CHECK_VERSION(2, 12, 0) -static gboolean -nexus_remove_all_cb(gpointer key, gpointer val, gpointer data) -{ - return TRUE; -} -#endif - - static gboolean nexus_parse_token(MsnNexus *nexus, int id, xmlnode *node) { @@ -281,12 +272,7 @@ if (token_str == NULL) return FALSE; -#if GLIB_CHECK_VERSION(2, 12, 0) g_hash_table_remove_all(nexus->tokens[id].token); -#else - g_hash_table_foreach_remove(nexus->tokens[id].token, - nexus_remove_all_cb, NULL); -#endif elems = g_strsplit(token_str, "&", 0);
--- a/libpurple/protocols/msn/state.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/protocols/msn/state.c Sat Aug 22 21:47:20 2009 +0000 @@ -114,11 +114,7 @@ * 6: Album * 7: ? */ -#if GLIB_CHECK_VERSION(2,6,0) strings = g_strv_length(cmedia_array); -#else - while (cmedia_array[++strings] != NULL); -#endif if (strings >= 4 && !strcmp(cmedia_array[2], "1")) { parsed = TRUE;
--- a/libpurple/protocols/yahoo/libymsg.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/protocols/yahoo/libymsg.c Sat Aug 22 21:47:20 2009 +0000 @@ -1679,11 +1679,8 @@ char *crumb = NULL; char *crypt = NULL; -#if GLIB_CHECK_VERSION(2,6,0) totalelements = g_strv_length(split_data); -#else - while (split_data[++totalelements] != NULL); -#endif + if (totalelements >= 4) { response_no = strtol(split_data[0], NULL, 10); crumb = g_strdup(split_data[1] + strlen("crumb=")); @@ -1765,11 +1762,8 @@ int response_no = -1; char *token = NULL; -#if GLIB_CHECK_VERSION(2,6,0) totalelements = g_strv_length(split_data); -#else - while (split_data[++totalelements] != NULL); -#endif + if(totalelements == 1) response_no = strtol(split_data[0], NULL, 10); else if(totalelements >= 2) {
--- a/libpurple/util.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/util.c Sat Aug 22 21:47:20 2009 +0000 @@ -220,50 +220,12 @@ gchar * purple_base64_encode(const guchar *data, gsize len) { -#if GLIB_CHECK_VERSION(2,12,0) return g_base64_encode(data, len); -#else - char *out, *rv; - - g_return_val_if_fail(data != NULL, NULL); - g_return_val_if_fail(len > 0, NULL); - - rv = out = g_malloc(((len/3)+1)*4 + 1); - - for (; len >= 3; len -= 3) - { - *out++ = alphabet[data[0] >> 2]; - *out++ = alphabet[((data[0] << 4) & 0x30) | (data[1] >> 4)]; - *out++ = alphabet[((data[1] << 2) & 0x3c) | (data[2] >> 6)]; - *out++ = alphabet[data[2] & 0x3f]; - data += 3; - } - - if (len > 0) - { - unsigned char fragment; - - *out++ = alphabet[data[0] >> 2]; - fragment = (data[0] << 4) & 0x30; - - if (len > 1) - fragment |= data[1] >> 4; - - *out++ = alphabet[fragment]; - *out++ = (len < 2) ? '=' : alphabet[(data[1] << 2) & 0x3c]; - *out++ = '='; - } - - *out = '\0'; - - return rv; -#endif /* GLIB < 2.12.0 */ } guchar * purple_base64_decode(const char *str, gsize *ret_len) { -#if GLIB_CHECK_VERSION(2,12,0) /* * We want to allow ret_len to be NULL for backward compatibility, * but g_base64_decode() requires a valid length variable. So if @@ -271,69 +233,6 @@ */ gsize unused; return g_base64_decode(str, ret_len != NULL ? ret_len : &unused); -#else - guchar *out = NULL; - char tmp = 0; - const char *c; - gint32 tmp2 = 0; - int len = 0, n = 0; - - g_return_val_if_fail(str != NULL, NULL); - - c = str; - - while (*c) { - if (*c >= 'A' && *c <= 'Z') { - tmp = *c - 'A'; - } else if (*c >= 'a' && *c <= 'z') { - tmp = 26 + (*c - 'a'); - } else if (*c >= '0' && *c <= 57) { - tmp = 52 + (*c - '0'); - } else if (*c == '+') { - tmp = 62; - } else if (*c == '/') { - tmp = 63; - } else if (*c == '\r' || *c == '\n') { - c++; - continue; - } else if (*c == '=') { - if (n == 3) { - out = g_realloc(out, len + 2); - out[len] = (guchar)(tmp2 >> 10) & 0xff; - len++; - out[len] = (guchar)(tmp2 >> 2) & 0xff; - len++; - } else if (n == 2) { - out = g_realloc(out, len + 1); - out[len] = (guchar)(tmp2 >> 4) & 0xff; - len++; - } - break; - } - tmp2 = ((tmp2 << 6) | (tmp & 0xff)); - n++; - if (n == 4) { - out = g_realloc(out, len + 3); - out[len] = (guchar)((tmp2 >> 16) & 0xff); - len++; - out[len] = (guchar)((tmp2 >> 8) & 0xff); - len++; - out[len] = (guchar)(tmp2 & 0xff); - len++; - tmp2 = 0; - n = 0; - } - c++; - } - - out = g_realloc(out, len + 1); - out[len] = 0; - - if (ret_len != NULL) - *ret_len = len; - - return out; -#endif /* GLIB < 2.12.0 */ } /************************************************************************** @@ -2656,56 +2555,7 @@ int purple_build_dir (const char *path, int mode) { -#if GLIB_CHECK_VERSION(2,8,0) return g_mkdir_with_parents(path, mode); -#else - char *dir, **components, delim[] = { G_DIR_SEPARATOR, '\0' }; - int cur, len; - - g_return_val_if_fail(path != NULL, -1); - - dir = g_new0(char, strlen(path) + 1); - components = g_strsplit(path, delim, -1); - len = 0; - for (cur = 0; components[cur] != NULL; cur++) { - /* If you don't know what you're doing on both - * win32 and *NIX, stay the hell away from this code */ - if(cur > 1) - dir[len++] = G_DIR_SEPARATOR; - strcpy(dir + len, components[cur]); - len += strlen(components[cur]); - if(cur == 0) - dir[len++] = G_DIR_SEPARATOR; - - if(g_file_test(dir, G_FILE_TEST_IS_DIR)) { - continue; -#ifdef _WIN32 - /* allow us to create subdirs on UNC paths - * (\\machinename\path\to\blah) - * g_file_test() doesn't work on "\\machinename" */ - } else if (cur == 2 && dir[0] == '\\' && dir[1] == '\\' - && components[cur + 1] != NULL) { - continue; -#endif - } else if(g_file_test(dir, G_FILE_TEST_EXISTS)) { - purple_debug_warning("build_dir", "bad path: %s\n", path); - g_strfreev(components); - g_free(dir); - return -1; - } - - if (g_mkdir(dir, mode) < 0) { - purple_debug_warning("build_dir", "mkdir: %s\n", g_strerror(errno)); - g_strfreev(components); - g_free(dir); - return -1; - } - } - - g_strfreev(components); - g_free(dir); - return 0; -#endif } /* @@ -3215,30 +3065,13 @@ gboolean purple_str_has_prefix(const char *s, const char *p) { -#if GLIB_CHECK_VERSION(2,2,0) return g_str_has_prefix(s, p); -#else - g_return_val_if_fail(s != NULL, FALSE); - g_return_val_if_fail(p != NULL, FALSE); - - return (!strncmp(s, p, strlen(p))); -#endif } gboolean purple_str_has_suffix(const char *s, const char *x) { -#if GLIB_CHECK_VERSION(2,2,0) return g_str_has_suffix(s, x); -#else - int off; - - g_return_val_if_fail(s != NULL, FALSE); - g_return_val_if_fail(x != NULL, FALSE); - - off = strlen(s) - strlen(x); - return (off >= 0 && purple_strequal(s + off, x)); -#endif } char * @@ -5134,18 +4967,5 @@ const gchar * purple_get_host_name(void) { -#if GLIB_CHECK_VERSION(2,8,0) return g_get_host_name(); -#else - static char hostname[256]; - int ret = gethostname(hostname, sizeof(hostname)); - hostname[sizeof(hostname) - 1] = '\0'; - - if (ret == -1 || hostname[0] == '\0') { - purple_debug_info("purple_get_host_name: ", "could not find host name"); - return "localhost"; - } else { - return hostname; - } -#endif }
--- a/libpurple/win32/libc_interface.c Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/win32/libc_interface.c Sat Aug 22 21:47:20 2009 +0000 @@ -469,65 +469,7 @@ /* stdio.h */ int wpurple_rename (const char *oldname, const char *newname) { - -#if GLIB_CHECK_VERSION(2,8,5) - return g_rename(oldname, newname); - -#else - - /* This is a ugly, but we still compile with 2.6.10 but use newer runtimes */ - struct stat oldstat, newstat; - - /* As of Glib 2.8.5, g_rename() uses MoveFileEx() with MOVEFILE_REPLACE_EXISTING to behave more sanely */ - if (glib_check_version(2, 8, 5) == NULL) { - return g_rename(oldname, newname); - } - - if(g_stat(oldname, &oldstat) == 0) { - /* newname exists */ - if(g_stat(newname, &newstat) == 0) { - /* oldname is a dir */ - if(S_ISDIR(oldstat.st_mode)) { - if(!S_ISDIR(newstat.st_mode)) { - return g_rename(oldname, newname); - } - /* newname is a dir */ - else { - /* This is not quite right.. If newname is empty and - is not a sub dir of oldname, newname should be - deleted and oldname should be renamed. - */ - purple_debug(PURPLE_DEBUG_WARNING, "wpurple", "wpurple_rename does not behave here as it should\n"); - return g_rename(oldname, newname); - } - } - /* oldname is not a dir */ - else { - /* newname is a dir */ - if(S_ISDIR(newstat.st_mode)) { - errno = EISDIR; - return -1; - } - /* newname is not a dir */ - else { - g_remove(newname); - return g_rename(oldname, newname); - } - } - } - /* newname doesn't exist */ - else - return g_rename(oldname, newname); - } - else { - /* oldname doesn't exist */ - errno = ENOENT; - return -1; - } - -#endif - } /* time.h */ @@ -1129,54 +1071,7 @@ wpurple_g_access (const gchar *filename, int mode) { -#if GLIB_CHECK_VERSION(2,8,0) - return g_access(filename, mode); - -#else - - if (G_WIN32_HAVE_WIDECHAR_API ()) - { - 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 = _waccess (wfilename, mode); - save_errno = errno; - - g_free (wfilename); - - errno = save_errno; - return retval; - } - else - { - gchar *cp_filename = g_locale_from_utf8 (filename, -1, NULL, NULL, NULL); - int retval; - int save_errno; - - if (cp_filename == NULL) - { - errno = EINVAL; - return -1; - } - - retval = access (cp_filename, mode); - save_errno = errno; - - g_free (cp_filename); - - errno = save_errno; - return retval; - } - -#endif }
--- a/libpurple/win32/libc_interface.h Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/win32/libc_interface.h Sat Aug 22 21:47:20 2009 +0000 @@ -115,11 +115,6 @@ #define close( fd ) \ wpurple_close( fd ) -#if !GLIB_CHECK_VERSION(2,8,0) -#define g_access( filename, mode) \ -wpurple_g_access( filename, mode ) -#endif - #ifndef sleep #define sleep(x) Sleep((x)*1000) #endif @@ -140,14 +135,12 @@ #define rename( oldname, newname ) \ wpurple_rename( oldname, newname ) -#if GLIB_CHECK_VERSION(2,6,0) #ifdef g_rename # undef g_rename #endif /* This is necessary because we want rename on win32 to be able to overwrite an existing file, it is done in internal.h if GLib < 2.6*/ #define g_rename(oldname, newname) \ wpurple_rename(oldname, newname) -#endif /* sys/stat.h */ #define fchmod(a,b)
--- a/libpurple/win32/libc_internal.h Sat Aug 22 18:54:15 2009 +0000 +++ b/libpurple/win32/libc_internal.h Sat Aug 22 21:47:20 2009 +0000 @@ -141,10 +141,6 @@ int wpurple_gethostname(char *name, size_t size); -#if !GLIB_CHECK_VERSION(2,8,0) -int wpurple_g_access(const gchar *filename, int mode); -#endif - /* stdio.h */ int wpurple_rename(const char *oldname, const char *newname);