Thu, 12 Mar 2020 23:08:19 -0500
Remove stringref.[ch] as the old logger reader was the only thing using it.
| libpurple/meson.build | file | annotate | diff | comparison | revisions | |
| libpurple/stringref.c | file | annotate | diff | comparison | revisions | |
| libpurple/stringref.h | file | annotate | diff | comparison | revisions |
--- a/libpurple/meson.build Thu Mar 12 23:04:27 2020 -0500 +++ b/libpurple/meson.build Thu Mar 12 23:08:19 2020 -0500 @@ -61,7 +61,6 @@ 'smiley-theme.c', 'smiley.c', 'status.c', - 'stringref.c', 'stun.c', 'sound.c', 'sound-theme.c', @@ -138,7 +137,6 @@ 'smiley-theme.h', 'smiley.h', 'status.h', - 'stringref.h', 'stun.h', 'sound.h', 'sound-theme.h',
--- a/libpurple/stringref.c Thu Mar 12 23:04:27 2020 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,167 +0,0 @@ -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ - -#include "internal.h" - -#include <string.h> -#include <stdarg.h> - -#include "debug.h" -#include "eventloop.h" -#include "stringref.h" - -/* - * The internal representation of a stringref. - * - * @note For this structure to be useful, the string contained within - * it must be immutable -- for this reason, do _not_ access it - * directly! - */ -struct _PurpleStringref { - guint32 ref; /* The reference count of this string. - * Note that reference counts are only - * 31 bits, and the high-order bit - * indicates whether this string is up - * for GC at the next idle handler... - * But you aren't going to touch this - * anyway, right? */ - char value[1]; /* The string contained in this ref. - * Notice that it is simply "hanging - * off the end" of the ref ... this - * is to save an allocation. */ -}; - -#define REFCOUNT(x) ((x) & 0x7fffffff) - -static GList *gclist = NULL; - -static void stringref_free(PurpleStringref *stringref); -static gboolean gs_idle_cb(gpointer data); - -PurpleStringref *purple_stringref_new(const char *value) -{ - PurpleStringref *newref; - size_t len; - - if (value == NULL) - return NULL; - - len = strlen(value); - - newref = g_malloc(sizeof(PurpleStringref) + len); - /* g_strlcpy() takes the size of the buffer, including the NUL. - strlen() returns the length of the string, without the NUL. */ - g_strlcpy(newref->value, value, len + 1); - newref->ref = 1; - - return newref; -} - -PurpleStringref *purple_stringref_new_noref(const char *value) -{ - PurpleStringref *newref; - - if (value == NULL) - return NULL; - - newref = g_malloc(sizeof(PurpleStringref) + strlen(value)); - strcpy(newref->value, value); - newref->ref = 0x80000000; - - if (gclist == NULL) - g_timeout_add(0, gs_idle_cb, NULL); - gclist = g_list_prepend(gclist, newref); - - return newref; -} - -PurpleStringref *purple_stringref_printf(const char *format, ...) -{ - PurpleStringref *newref; - va_list ap; - - if (format == NULL) - return NULL; - - va_start(ap, format); - newref = g_malloc(sizeof(PurpleStringref) + g_printf_string_upper_bound(format, ap)); - vsprintf(newref->value, format, ap); - va_end(ap); - newref->ref = 1; - - return newref; -} - -PurpleStringref *purple_stringref_ref(PurpleStringref *stringref) -{ - if (stringref == NULL) - return NULL; - stringref->ref++; - return stringref; -} - -void purple_stringref_unref(PurpleStringref *stringref) -{ - if (stringref == NULL) - return; - if (REFCOUNT(--(stringref->ref)) == 0) { - if (stringref->ref & 0x80000000) - gclist = g_list_remove(gclist, stringref); - stringref_free(stringref); - } -} - -const char *purple_stringref_value(const PurpleStringref *stringref) -{ - return (stringref == NULL ? NULL : stringref->value); -} - -int purple_stringref_cmp(const PurpleStringref *s1, const PurpleStringref *s2) -{ - return (s1 == s2 ? 0 : strcmp(purple_stringref_value(s1), purple_stringref_value(s2))); -} - -size_t purple_stringref_len(const PurpleStringref *stringref) -{ - return strlen(purple_stringref_value(stringref)); -} - -static void stringref_free(PurpleStringref *stringref) -{ - g_return_if_fail(stringref != NULL); - - if (REFCOUNT(stringref->ref) == 0) { - g_free(stringref); - return; - } -#ifdef DEBUG - purple_debug(PURPLE_DEBUG_ERROR, "stringref", "Free of nonzero (%d) ref stringref!\n", REFCOUNT(stringref->ref)); -#endif /* DEBUG */ -} - -static gboolean gs_idle_cb(gpointer data) -{ - g_list_free_full(gclist, (GDestroyNotify)stringref_free); - gclist = NULL; - - return FALSE; -}
--- a/libpurple/stringref.h Thu Mar 12 23:04:27 2020 -0500 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,144 +0,0 @@ -/* TODO: Can we just replace this whole thing with a GCache */ - -/* purple - * - * Purple is the legal property of its developers, whose names are too numerous - * to list here. Please refer to the COPYRIGHT file distributed with this - * source distribution. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA - * - */ - -#ifndef PURPLE_STRINGREF_H -#define PURPLE_STRINGREF_H -/** - * SECTION:stringref - * @section_id: libpurple-stringref - * @short_description: <filename>stringref.h</filename> - * @title: Reference-counted Immutable Strings - */ - -typedef struct _PurpleStringref PurpleStringref; - -G_BEGIN_DECLS - -/** - * purple_stringref_new: - * @value: This will be the value of the string; it will be - * duplicated. - * - * Creates an immutable reference-counted string object. The newly - * created object will have a reference count of 1. - * - * Returns: (transfer full): A newly allocated string reference object with a refcount - * of 1. - */ -PurpleStringref *purple_stringref_new(const char *value); - -/** - * purple_stringref_new_noref: - * @value: This will be the value of the string; it will be - * duplicated. - * - * Creates an immutable reference-counted string object. The newly - * created object will have a reference count of zero, and if it is - * not referenced before the next iteration of the mainloop it will - * be freed at that time. - * - * Returns: (transfer full): A newly allocated string reference object with a refcount - * of zero. - */ -PurpleStringref *purple_stringref_new_noref(const char *value); - -/** - * purple_stringref_printf: - * @format: A printf-style format specification. - * @...: The arguments for the format specification. - * - * Creates an immutable reference-counted string object from a printf - * format specification and arguments. The created object will have a - * reference count of 1. - * - * Returns: A newly allocated string reference object with a refcount - * of 1. - */ -PurpleStringref *purple_stringref_printf(const char *format, ...); - -/** - * purple_stringref_ref: - * @stringref: String to be referenced. - * - * Increase the reference count of the given stringref. - * - * Returns: (transfer full): A pointer to the referenced string. - */ -PurpleStringref *purple_stringref_ref(PurpleStringref *stringref); - -/** - * purple_stringref_unref: - * @stringref: String to be dereferenced. - * - * Decrease the reference count of the given stringref. If this - * reference count reaches zero, the stringref will be freed; thus - * you MUST NOT use this string after dereferencing it. - */ -void purple_stringref_unref(PurpleStringref *stringref); - -/** - * purple_stringref_value: - * @stringref: String reference from which to retrieve the value. - * - * Retrieve the value of a stringref. - * - * Note: This value should not be cached or stored in a local variable. - * While there is nothing inherently incorrect about doing so, it - * is easy to forget that the cached value is in fact a - * reference-counted object and accidentally use it after - * dereferencing. This is more problematic for a reference- - * counted object than a heap-allocated object, as it may seem to - * be valid or invalid nondeterministically based on how many - * other references to it exist. - * - * Returns: The contents of the string reference. - */ -const char *purple_stringref_value(const PurpleStringref *stringref); - -/** - * purple_stringref_cmp: - * @s1: The reference string. - * @s2: The string to compare against the reference. - * - * Compare two stringrefs for string equality. This returns the same - * value as strcmp would, where <0 indicates that s1 is "less than" s2 - * in the ASCII lexicography, 0 indicates equality, etc. - * - * Returns: An ordering indication on s1 and s2. - */ -int purple_stringref_cmp(const PurpleStringref *s1, const PurpleStringref *s2); - -/** - * purple_stringref_len: - * @stringref: The string in whose length we are interested. - * - * Find the length of the string inside a stringref. - * - * Returns: The length of the string in stringref - */ -size_t purple_stringref_len(const PurpleStringref *stringref); - -G_END_DECLS - -#endif /* PURPLE_STRINGREF_H */