Re: More on 64-bit code changes
- From: Owen Taylor <otaylor redhat com>
- To: Mark Murnane Sun COM
- Cc: gtk-devel-list gnome org
- Subject: Re: More on 64-bit code changes
- Date: 20 Jun 2001 12:48:49 -0400
OK, I've (finally) finished going through and applying your patch. The
final result ended up being a fair bit different, because:
* I tried to be somewhat more consistent about when to use gsize, gssize,
glong, though I didn't completely succeed. A number of signed =>
unsigned changes I made beyond what you had required special care
to make sure things didn't break.
(The general rule I had in mind was: use gsize for all byte lengths and
byte offsets, except where negative values were accepted; in that
case, use gssize)
* I did a lot of cleaning up as I went along, and found a few unrelated
bugs.
* There were just a few problems with your patch (only real bug was
in the test program timeloop-basic.c, where you turned gint to
gsize in one place where a signed comparison was used) and quite
a few more places where I did something different because of
a matter of taste. (E.g., change to g_timeout_prepare)
* The IO-channel changes are not included, because there is a large
conflicting patch outstanding.
I'll probably wait a day or two before applying this just to make sure
that the rest of the GTK+ stack works OK here, but this set of changes
should be pretty much final.
Regards,
Owen
For reference for cleaning up the rest of Pango/GTK+, the
source-incompatible API changes in this patch are:
gchar* g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
bytes_read/bytes_written variables now are gsize; using an int will
_not_ work on 64 bit platforms. Also change from signed to
unsigned means code using these results needs to be checked
for improper signed/unsigned comparisons.
Same for g_convert_with_fallback(), g_locale/filename_to/from_utf8().
gboolean g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error);
Again, an out parameter is now wider.
diff -u -r1.4 gmarkup.h
--- gmarkup.h 2001/03/09 21:23:33 1.4
+++ gmarkup.h 2001/06/20 16:27:01
@@ -72,7 +72,7 @@
/* text is not nul-terminated */
void (*text) (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
@@ -83,7 +83,7 @@
/* text is not nul-terminated. */
void (*passthrough) (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
Prototypes for these callback functions have changed, note change
from signed to unsigned.
gunichar2 *g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
Again, out parameters are now wide. (Same for all of)
g_{utf8,utf16,ucs4}_to_{utf8,utf16,ucs4}
Regards,
Owen
? docs/glib-config.1
? docs/reference/glib/glib-undocumented.txt
? docs/reference/gobject/gobject-undocumented.txt
? gobject/gsignal.S
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/ChangeLog,v
retrieving revision 1.730
diff -u -r1.730 ChangeLog
--- ChangeLog 2001/06/15 18:28:06 1.730
+++ ChangeLog 2001/06/20 16:27:01
@@ -1,3 +1,76 @@
+Wed Jun 20 12:00:54 2001 Owen Taylor <otaylor redhat com>
+
+ Changes for 64-bit cleanliness, loosely based on patch
+ from Mark Murnane.
+
+ * gconvert.c (g_convert/g_convert_with_fallback): Remove
+ workarounds for since-fixed GNU libc bugs. Minor
+ doc fix.
+
+ * gconvert.[ch]: Change gint to gsize/gssize as
+ appropriate.
+
+ * gconvert.c (g_locale/filename_to/from_utf8): Fix incorrect
+ computation of bytes_read / bytes_written.
+
+ * gfileutils.[ch] (g_file_get_contents): Make length
+ out parameter 'gsize *len'.
+
+ * ghook.c (g_hook_compare_ids): Don't compare a
+ and b as 'a - b'.
+
+ * gmacros.h (GSIZE_TO_POINTER): Add GPOINTER_TO_SIZE,
+ GSIZE_TO_POINTER.
+
+ * gmain.c (g_timeout_prepare): Rewrite to avoid
+ overflows. (Fixes bug when system clock skews
+ backwards more than 24 days.)
+
+ * gmarkup.[ch]: Make lengths passed to callbacks
+ gsize, length for g_markup_parse-context_parse(),
+ g_markup_escape_text() gssize.
+
+ * gmessages.[ch] (g_printf_string_upper_bound): Change
+ return value to gsize.
+
+ * gmessages.c (printf_string_upper_bound): Remove
+ a ridiculous use of 'inline' on a 300 line function.
+
+ * gstring.[ch]: Represent size of string as a gsize,
+ not gint. Make parameters to functions take gsize,
+ or gssize where -1 is allowed.
+
+ * gstring.c (g_string_erase): Make
+ g_string_erase (string, pos, -1) a synonym for
+ g_string_truncate for consistency with other G*
+ APIs.
+
+ * gstrfuncs.[ch]: Make all functions taking a string
+ length, take a gsize, or gssize if -1 is allowed.
+ (g_strstr_len, g_strrstr_len). Also fix some boundary
+ conditions in g_str[r]str[_len].
+
+ * gutf8.c tests/unicode-encoding.c: Make parameters that
+ are byte lengths gsize, gssize as appropriate. Make
+ character offsets, other counts, glong.
+
+ * gasyncqueue.c gcompletion.c
+ timeloop.c timeloop-basic.c gutils.c gspawn.c.
+ Small 64 bit cleanliness fixups.
+
+ * glist.c (g_list_sort2, g_list_sort_real): Fix functions
+ that should have been static.
+
+ * gdate.c (g_date_fill_parse_tokens): Fix extra
+ declaration that was shadowing another.
+
+ * tests/module-test.c: Include string.h
+
+xMon Jun 18 15:43:29 2001 Owen Taylor <otaylor redhat com>
+
+ * gutf8.c (g_get_charset): Make argument
+ G_CONST_RETURN char **.
+
Thu Jun 14 14:09:46 2001 Owen Taylor <otaylor redhat com>
* gstrfuncs.c (g_strconcat): Fix a use of strcat that
Index: garray.c
===================================================================
RCS file: /cvs/gnome/glib/garray.c,v
retrieving revision 1.25
diff -u -r1.25 garray.c
--- garray.c 2001/05/23 10:20:54 1.25
+++ garray.c 2001/06/20 16:27:01
@@ -515,7 +515,7 @@
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
@@ -536,7 +536,7 @@
gpointer data)
{
GRealPtrArray* array = (GRealPtrArray*) farray;
- int i;
+ guint i;
g_return_val_if_fail (array, FALSE);
Index: gasyncqueue.c
===================================================================
RCS file: /cvs/gnome/glib/gasyncqueue.c,v
retrieving revision 1.5
diff -u -r1.5 gasyncqueue.c
--- gasyncqueue.c 2001/06/07 13:46:10 1.5
+++ gasyncqueue.c 2001/06/20 16:27:01
@@ -405,7 +405,7 @@
gint
g_async_queue_length (GAsyncQueue* queue)
{
- glong retval;
+ gint retval;
g_return_val_if_fail (queue, 0);
g_return_val_if_fail (queue->ref_count > 0, 0);
Index: gcompletion.c
===================================================================
RCS file: /cvs/gnome/glib/gcompletion.c,v
retrieving revision 1.7
diff -u -r1.7 gcompletion.c
--- gcompletion.c 2000/11/28 23:44:14 1.7
+++ gcompletion.c 2001/06/20 16:27:01
@@ -121,9 +121,9 @@
gchar** new_prefix)
{
register GList* list;
- register gint len;
- register gint i;
- register gint plen;
+ register gsize len;
+ register gsize i;
+ register gsize plen;
gchar* postfix;
gchar* s;
@@ -165,8 +165,8 @@
gchar* prefix,
gchar** new_prefix)
{
- gint plen, len;
- gint done = 0;
+ gsize plen, len;
+ gboolean done = FALSE;
GList* list;
g_return_val_if_fail (cmp != NULL, NULL);
@@ -193,7 +193,7 @@
else
list = list->next;
}
- done = 1;
+ done = TRUE;
}
}
Index: gcompletion.h
===================================================================
RCS file: /cvs/gnome/glib/gcompletion.h,v
retrieving revision 1.5
diff -u -r1.5 gcompletion.h
--- gcompletion.h 2001/05/08 13:50:37 1.5
+++ gcompletion.h 2001/06/20 16:27:01
@@ -28,7 +28,6 @@
#define __G_COMPLETION_H__
#include <glist.h>
-#include <stddef.h> /* For size_t */
G_BEGIN_DECLS
@@ -41,7 +40,7 @@
typedef gint (*GCompletionStrncmpFunc) (const gchar *s1,
const gchar *s2,
- size_t n);
+ gsize n);
struct _GCompletion
{
Index: gconvert.c
===================================================================
RCS file: /cvs/gnome/glib/gconvert.c,v
retrieving revision 1.15
diff -u -r1.15 gconvert.c
--- gconvert.c 2001/04/16 20:05:23 1.15
+++ gconvert.c 2001/06/20 16:27:01
@@ -96,9 +96,9 @@
size_t
g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left)
+ gsize *outbytes_left)
{
iconv_t cd = (iconv_t)converter;
@@ -179,21 +179,21 @@
**/
gchar*
g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *dest;
gchar *outp;
const gchar *p;
- size_t inbytes_remaining;
- size_t outbytes_remaining;
- size_t err;
+ gsize inbytes_remaining;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
g_return_val_if_fail (str != NULL, NULL);
@@ -218,10 +218,7 @@
p = str;
inbytes_remaining = len;
-
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
@@ -241,19 +238,11 @@
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
goto again;
}
@@ -317,10 +306,7 @@
* input string that were successfully converted, or %NULL.
* Even if the conversion was succesful, this may be
* less than len if there were partial characters
- * at the end of the input. If the error
- * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
- * stored will the byte fofset after the last valid
- * input sequence.
+ * at the end of the input.
* @bytes_written: the stored in the output buffer (not including the
* terminating nul.
* @error: location to store the error occuring, or %NULL to ignore
@@ -340,12 +326,12 @@
**/
gchar*
g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
gchar *utf8;
@@ -353,13 +339,13 @@
gchar *outp;
const gchar *insert_str = NULL;
const gchar *p;
- int inbytes_remaining;
+ gsize inbytes_remaining;
const gchar *save_p = NULL;
- size_t save_inbytes = 0;
- size_t outbytes_remaining;
- size_t err;
+ gsize save_inbytes = 0;
+ gsize outbytes_remaining;
+ gsize err;
GIConv cd;
- size_t outbuf_size;
+ gsize outbuf_size;
gboolean have_error = FALSE;
gboolean done = FALSE;
@@ -419,9 +405,8 @@
* for the original string while we are converting the fallback
*/
p = utf8;
- /* Due to a GLIBC bug, round outbuf_size up to a multiple of 4 */
- /* + 1 for nul in case len == 1 */
- outbuf_size = ((len + 3) & ~3) + 1;
+
+ outbuf_size = len + 1; /* + 1 for nul in case len == 1 */
outbytes_remaining = outbuf_size - 1; /* -1 for nul */
outp = dest = g_malloc (outbuf_size);
@@ -442,19 +427,11 @@
{
size_t used = outp - dest;
- /* glibc's iconv can return E2BIG even if there is space
- * remaining if an internal buffer is exhausted. The
- * folllowing is a heuristic to catch this. The 16 is
- * pretty arbitrary.
- */
- if (used + 16 > outbuf_size)
- {
- outbuf_size = (outbuf_size - 1) * 2 + 1;
- dest = g_realloc (dest, outbuf_size);
-
- outp = dest + used;
- outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
- }
+ outbuf_size *= 2;
+ dest = g_realloc (dest, outbuf_size);
+
+ outp = dest + used;
+ outbytes_remaining = outbuf_size - used - 1; /* -1 for nul */
break;
}
@@ -538,6 +515,33 @@
*
*/
+static gchar *
+strdup_len (const gchar *string,
+ gssize len,
+ gsize *bytes_written,
+ gsize *bytes_read)
+
+{
+ gsize real_len;
+
+ if (len < 0)
+ real_len = strlen (string);
+ else
+ {
+ real_len = 0;
+
+ while (real_len < len && string[real_len])
+ real_len++;
+ }
+
+ if (bytes_read)
+ *bytes_read = real_len;
+ if (bytes_written)
+ *bytes_written = real_len;
+
+ return g_strndup (string, real_len);
+}
+
/**
* g_locale_to_utf8:
* @opsysstring: a string in the encoding of the current locale
@@ -564,9 +568,9 @@
**/
gchar *
g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
@@ -667,15 +671,14 @@
#else /* !G_PLATFORM_WIN32 */
- char *charset, *str;
+ const char *charset;
if (g_get_charset (&charset))
- return g_strdup (opsysstring);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
+ else
+ return g_convert (opsysstring, len,
+ "UTF-8", charset, bytes_read, bytes_written, error);
- str = g_convert (opsysstring, len,
- "UTF-8", charset, bytes_read, bytes_written, error);
-
- return str;
#endif /* !G_PLATFORM_WIN32 */
}
@@ -705,9 +708,9 @@
**/
gchar *
g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
@@ -813,17 +816,15 @@
return result;
#else /* !G_PLATFORM_WIN32 */
-
- gchar *charset, *str;
+
+ const gchar *charset;
if (g_get_charset (&charset))
- return g_strdup (utf8string);
-
- str = g_convert (utf8string, strlen (utf8string),
- charset, "UTF-8", bytes_read, bytes_written, error);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
+ else
+ return g_convert (utf8string, len,
+ charset, "UTF-8", bytes_read, bytes_written, error);
- return str;
-
#endif /* !G_PLATFORM_WIN32 */
}
@@ -852,9 +853,9 @@
**/
gchar*
g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
@@ -866,21 +867,8 @@
return g_locale_to_utf8 (opsysstring, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (opsysstring);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (opsysstring);
else
- return g_strndup (opsysstring, len);
+ return strdup_len (opsysstring, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
@@ -908,9 +896,9 @@
**/
gchar*
g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error)
{
#ifdef G_PLATFORM_WIN32
@@ -922,20 +910,7 @@
return g_locale_from_utf8 (utf8string, len,
bytes_read, bytes_written,
error);
-
- if (bytes_read || bytes_written)
- {
- gint len = strlen (utf8string);
-
- if (bytes_read)
- *bytes_read = len;
- if (bytes_written)
- *bytes_written = len;
- }
-
- if (len < 0)
- return g_strdup (utf8string);
else
- return g_strndup (utf8string, len);
+ return strdup_len (utf8string, len, bytes_read, bytes_written);
#endif /* !G_PLATFORM_WIN32 */
}
Index: gconvert.h
===================================================================
RCS file: /cvs/gnome/glib/gconvert.h,v
retrieving revision 1.5
diff -u -r1.5 gconvert.h
--- gconvert.h 2001/01/05 21:22:46 1.5
+++ gconvert.h 2001/06/20 16:27:01
@@ -41,7 +41,7 @@
} GConvertError;
#define G_CONVERT_ERROR g_convert_error_quark()
-GQuark g_convert_error_quark();
+GQuark g_convert_error_quark (void);
/* Thin wrappers around iconv
*/
@@ -51,54 +51,54 @@
const gchar *from_codeset);
size_t g_iconv (GIConv converter,
gchar **inbuf,
- size_t *inbytes_left,
+ gsize *inbytes_left,
gchar **outbuf,
- size_t *outbytes_left);
+ gsize *outbytes_left);
gint g_iconv_close (GIConv converter);
gchar* g_convert (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_convert_with_fallback (const gchar *str,
- gint len,
+ gssize len,
const gchar *to_codeset,
const gchar *from_codeset,
gchar *fallback,
- gint *bytes_read,
- gint *bytes_written,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between libc's idea of strings and UTF-8.
*/
gchar* g_locale_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_locale_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
/* Convert between the operating system (or C runtime)
* representation of file names and UTF-8.
*/
gchar* g_filename_to_utf8 (const gchar *opsysstring,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
gchar* g_filename_from_utf8 (const gchar *utf8string,
- gint len,
- gint *bytes_read,
- gint *bytes_written,
+ gssize len,
+ gsize *bytes_read,
+ gsize *bytes_written,
GError **error);
G_END_DECLS
Index: gdate.c
===================================================================
RCS file: /cvs/gnome/glib/gdate.c,v
retrieving revision 1.23
diff -u -r1.23 gdate.c
--- gdate.c 2001/06/05 20:59:01 1.23
+++ gdate.c 2001/06/20 16:27:01
@@ -513,7 +513,6 @@
if (pt->num_ints < 3)
{
gchar lcstr[128];
- int i = 1;
strncpy (lcstr, str, 127);
g_strdown (lcstr);
Index: gfileutils.c
===================================================================
RCS file: /cvs/gnome/glib/gfileutils.c,v
retrieving revision 1.19
diff -u -r1.19 gfileutils.c
--- gfileutils.c 2001/04/16 20:05:23 1.19
+++ gfileutils.c 2001/06/20 16:27:01
@@ -285,7 +285,7 @@
get_contents_stdio (const gchar *filename,
FILE *f,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar buf[2048];
@@ -333,7 +333,7 @@
struct stat *stat_buf,
gint fd,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
gchar *buf;
@@ -347,7 +347,7 @@
bytes_read = 0;
while (bytes_read < size)
{
- gint rc;
+ gssize rc;
rc = read (fd, buf + bytes_read, size - bytes_read);
@@ -387,7 +387,7 @@
static gboolean
get_contents_posix (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
struct stat stat_buf;
@@ -456,7 +456,7 @@
static gboolean
get_contents_win32 (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
FILE *f;
@@ -503,7 +503,7 @@
gboolean
g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error)
{
g_return_val_if_fail (filename != NULL, FALSE);
Index: gfileutils.h
===================================================================
RCS file: /cvs/gnome/glib/gfileutils.h,v
retrieving revision 1.6
diff -u -r1.6 gfileutils.h
--- gfileutils.h 2000/11/12 20:38:19 1.6
+++ gfileutils.h 2001/06/20 16:27:01
@@ -76,7 +76,7 @@
GFileTest test);
gboolean g_file_get_contents (const gchar *filename,
gchar **contents,
- guint *length,
+ gsize *length,
GError **error);
Index: ghook.c
===================================================================
RCS file: /cvs/gnome/glib/ghook.c,v
retrieving revision 1.19
diff -u -r1.19 ghook.c
--- ghook.c 2001/04/29 03:04:25 1.19
+++ ghook.c 2001/06/20 16:27:01
@@ -631,5 +631,10 @@
g_hook_compare_ids (GHook *new_hook,
GHook *sibling)
{
- return ((glong) new_hook->hook_id) - ((glong) sibling->hook_id);
+ if (new_hook->hook_id < sibling->hook_id)
+ return -1;
+ else if (new_hook->hook_id > sibling->hook_id)
+ return 1;
+
+ return 0;
}
Index: glist.c
===================================================================
RCS file: /cvs/gnome/glib/glist.c,v
retrieving revision 1.24
diff -u -r1.24 glist.c
--- glist.c 2001/05/03 10:47:31 1.24
+++ glist.c 2001/06/20 16:27:01
@@ -717,7 +717,7 @@
return list.next;
}
-GList*
+static GList*
g_list_sort_real (GList *list,
GFunc compare_func,
gboolean use_data,
@@ -765,7 +765,7 @@
return g_list_sort_real (list, (GFunc) compare_func, TRUE, user_data);
}
-GList*
+static GList*
g_list_sort2 (GList *list,
GCompareFunc compare_func)
{
Index: gmacros.h
===================================================================
RCS file: /cvs/gnome/glib/gmacros.h,v
retrieving revision 1.2
diff -u -r1.2 gmacros.h
--- gmacros.h 2000/12/01 05:42:51 1.2
+++ gmacros.h 2001/06/20 16:27:01
@@ -141,6 +141,11 @@
*/
#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.
*/
Index: gmain.c
===================================================================
RCS file: /cvs/gnome/glib/gmain.c,v
retrieving revision 1.59
diff -u -r1.59 gmain.c
--- gmain.c 2001/05/27 18:28:56 1.59
+++ gmain.c 2001/06/20 16:27:01
@@ -95,7 +95,7 @@
GMemChunk *poll_chunk;
guint n_poll_records;
GPollFD *cached_poll_array;
- gint cached_poll_array_size;
+ guint cached_poll_array_size;
#ifdef G_THREADS_ENABLED
#ifndef G_OS_WIN32
@@ -1533,7 +1533,7 @@
static void
g_main_dispatch (GMainContext *context)
{
- gint i;
+ guint i;
for (i = 0; i < context->pending_dispatches->len; i++)
{
@@ -2619,29 +2619,51 @@
g_timeout_prepare (GSource *source,
gint *timeout)
{
+ glong sec;
glong msec;
GTimeVal current_time;
GTimeoutSource *timeout_source = (GTimeoutSource *)source;
g_source_get_current_time (source, ¤t_time);
-
- msec = ((timeout_source->expiration.tv_sec - current_time.tv_sec) * 1000 +
- (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000);
+
+ sec = timeout_source->expiration.tv_sec - current_time.tv_sec;
+ msec = (timeout_source->expiration.tv_usec - current_time.tv_usec) / 1000;
- if (msec < 0)
+ /* We do the following in a rather convoluted fashion to deal with
+ * the fact that we don't have an integral type big enough to hold
+ * the difference of two timevals in millseconds.
+ */
+ if (sec < 0 || (sec == 0 && msec < 0))
msec = 0;
- else if (msec > timeout_source->interval)
+ else
{
- /* The system time has been set backwards, so we
- * reset the expiration time to now + timeout_source->interval;
- * this at least avoids hanging for long periods of time.
- */
- g_timeout_set_expiration (timeout_source, ¤t_time);
- msec = timeout_source->interval;
+ glong interval_sec = timeout_source->interval / 1000;
+ glong interval_msec = timeout_source->interval % 1000;
+
+ if (msec < 0)
+ {
+ msec += 1000;
+ sec -= 1;
+ }
+
+ if (sec > interval_sec ||
+ (sec == interval_sec && msec > interval_msec))
+ {
+ /* The system time has been set backwards, so we
+ * reset the expiration time to now + timeout_source->interval;
+ * this at least avoids hanging for long periods of time.
+ */
+ g_timeout_set_expiration (timeout_source, ¤t_time);
+ msec = timeout_source->interval;
+ }
+ else
+ {
+ msec += sec * 1000;
+ }
}
-
- *timeout = msec;
+
+ *timeout = (gint)msec;
return msec == 0;
}
Index: gmarkup.c
===================================================================
RCS file: /cvs/gnome/glib/gmarkup.c,v
retrieving revision 1.11
diff -u -r1.11 gmarkup.c
--- gmarkup.c 2001/05/24 19:30:40 1.11
+++ gmarkup.c 2001/06/20 16:27:01
@@ -82,7 +82,7 @@
gint alloc_attrs;
const gchar *current_text;
- gint current_text_len;
+ gssize current_text_len;
const gchar *current_text_end;
GString *leftover_char_portion;
@@ -540,8 +540,7 @@
(l >= 0x10000 && l <= 0x10FFFF))
{
gchar buf[7];
- g_string_append (str,
- char_str (l, buf));
+ g_string_append (str, char_str (l, buf));
}
else
{
@@ -756,7 +755,7 @@
gboolean
g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error)
{
const gchar *first_invalid;
@@ -1662,7 +1661,7 @@
static void
append_escaped_text (GString *str,
const gchar *text,
- gint length)
+ gssize length)
{
const gchar *p;
const gchar *end;
@@ -1720,7 +1719,7 @@
**/
gchar*
g_markup_escape_text (const gchar *text,
- gint length)
+ gssize length)
{
GString *str;
Index: gmarkup.h
===================================================================
RCS file: /cvs/gnome/glib/gmarkup.h,v
retrieving revision 1.4
diff -u -r1.4 gmarkup.h
--- gmarkup.h 2001/03/09 21:23:33 1.4
+++ gmarkup.h 2001/06/20 16:27:01
@@ -72,7 +72,7 @@
/* text is not nul-terminated */
void (*text) (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
@@ -83,7 +83,7 @@
/* text is not nul-terminated. */
void (*passthrough) (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error);
@@ -102,7 +102,7 @@
void g_markup_parse_context_free (GMarkupParseContext *context);
gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gssize text_len,
GError **error);
gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
@@ -115,7 +115,7 @@
/* useful when saving */
gchar* g_markup_escape_text (const gchar *text,
- gint length);
+ gssize length);
G_END_DECLS
Index: gmessages.c
===================================================================
RCS file: /cvs/gnome/glib/gmessages.c,v
retrieving revision 1.29
diff -u -r1.29 gmessages.c
--- gmessages.c 2001/05/22 12:06:59 1.29
+++ gmessages.c 2001/06/20 16:27:01
@@ -71,9 +71,9 @@
/* --- prototypes --- */
-static inline guint printf_string_upper_bound (const gchar *format,
- gboolean may_warn,
- va_list args);
+static guint printf_string_upper_bound (const gchar *format,
+ gboolean may_warn,
+ va_list args);
/* --- variables --- */
@@ -156,9 +156,9 @@
#endif
static void
-write_unsigned (GFileDescriptor fd,
- gulong num,
- guint radix)
+write_unsigned (GFileDescriptor fd,
+ gulong num,
+ guint radix)
{
char buffer[64];
gulong tmp;
@@ -939,13 +939,13 @@
gboolean mod_half, mod_long, mod_extra_long;
} PrintfArgSpec;
-static inline guint
+static gsize
printf_string_upper_bound (const gchar *format,
gboolean may_warn,
va_list args)
{
static const gboolean honour_longs = SIZEOF_LONG > 4 || SIZEOF_VOID_P > 4;
- guint len = 1;
+ gsize len = 1;
if (!format)
return len;
@@ -960,7 +960,7 @@
{
PrintfArgSpec spec = { 0, };
gboolean seen_l = FALSE, conv_done = FALSE;
- guint conv_len = 0;
+ gsize conv_len = 0;
const gchar *spec_start = format;
do
@@ -1241,7 +1241,7 @@
return len;
}
-guint
+gsize
g_printf_string_upper_bound (const gchar *format,
va_list args)
{
Index: gmessages.h
===================================================================
RCS file: /cvs/gnome/glib/gmessages.h,v
retrieving revision 1.5
diff -u -r1.5 gmessages.h
--- gmessages.h 2001/05/29 13:47:05 1.5
+++ gmessages.h 2001/06/20 16:27:01
@@ -34,7 +34,7 @@
/* calculate a string size, guarranteed to fit format + args.
*/
-guint g_printf_string_upper_bound (const gchar* format,
+gsize g_printf_string_upper_bound (const gchar* format,
va_list args);
/* Log level shift offset for user defined
Index: gspawn.c
===================================================================
RCS file: /cvs/gnome/glib/gspawn.c,v
retrieving revision 1.6
diff -u -r1.6 gspawn.c
--- gspawn.c 2001/06/08 19:41:49 1.6
+++ gspawn.c 2001/06/20 16:27:01
@@ -135,8 +135,8 @@
gint fd,
GError **error)
{
- gint bytes;
- gchar buf[4096];
+ gssize bytes;
+ gchar buf[4096];
again:
@@ -875,15 +875,15 @@
static gboolean
read_ints (int fd,
gint* buf,
- gint n_ints_in_buf,
- gint *n_ints_read,
+ gint n_ints_in_buf,
+ gint *n_ints_read,
GError **error)
{
- gint bytes = 0;
+ gsize bytes = 0;
while (TRUE)
{
- gint chunk;
+ gssize chunk;
if (bytes >= sizeof(gint)*2)
break; /* give up, who knows what happened, should not be
@@ -893,7 +893,7 @@
again:
chunk = read (fd,
((gchar*)buf) + bytes,
- sizeof(gint)*n_ints_in_buf - bytes);
+ sizeof(gint) * n_ints_in_buf - bytes);
if (chunk < 0 && errno == EINTR)
goto again;
@@ -911,15 +911,11 @@
}
else if (chunk == 0)
break; /* EOF */
- else
- {
- g_assert (chunk > 0);
-
- bytes += chunk;
- }
+ else /* chunk > 0 */
+ bytes += chunk;
}
- *n_ints_read = bytes/4;
+ *n_ints_read = (gint)(bytes / sizeof(gint));
return TRUE;
}
@@ -1072,7 +1068,7 @@
/* Parent */
gint buf[2];
- gint n_ints = 0;
+ gint n_ints = 0;
/* Close the uncared-about ends of the pipes */
close_and_invalidate (&child_err_report_pipe[1]);
Index: gstrfuncs.c
===================================================================
RCS file: /cvs/gnome/glib/gstrfuncs.c,v
retrieving revision 1.57
diff -u -r1.57 gstrfuncs.c
--- gstrfuncs.c 2001/06/15 18:28:06 1.57
+++ gstrfuncs.c 2001/06/20 16:27:01
@@ -88,7 +88,7 @@
gchar*
g_strndup (const gchar *str,
- guint n)
+ gsize n)
{
gchar *new_str;
@@ -105,7 +105,7 @@
}
gchar*
-g_strnfill (guint length,
+g_strnfill (gsize length,
gchar fill_char)
{
register gchar *str, *s, *end;
@@ -188,7 +188,7 @@
gchar*
g_strconcat (const gchar *string1, ...)
{
- guint l;
+ gsize l;
va_list args;
gchar *s;
gchar *concat;
@@ -1062,7 +1062,7 @@
gint
g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n)
+ gsize n)
{
#ifdef HAVE_STRNCASECMP
return strncasecmp (s1, s2, n);
@@ -1319,11 +1319,11 @@
s = strstr (string, delimiter);
if (s)
{
- guint delimiter_len = strlen (delimiter);
+ gsize delimiter_len = strlen (delimiter);
do
{
- guint len;
+ gsize len;
gchar *new_string;
len = s - string;
@@ -1417,8 +1417,9 @@
if (*str_array)
{
- guint i, len;
- guint separator_len;
+ gint i;
+ gsize len;
+ gsize separator_len;
separator_len = strlen (separator);
/* First part, getting length */
@@ -1448,8 +1449,8 @@
{
gchar *string, *s;
va_list args;
- guint len;
- guint separator_len;
+ gsize len;
+ gsize separator_len;
gchar *ptr;
if (separator == NULL)
@@ -1514,11 +1515,9 @@
**/
gchar *
g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
@@ -1526,27 +1525,33 @@
return strstr (haystack, needle);
else
{
- const char *p = haystack;
- int needle_len = strlen (needle);
- const char *end = haystack + haystack_len - needle_len;
-
+ const gchar *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *end;
+ gsize i;
+
if (needle_len == 0)
- return (char *)haystack;
+ return (gchar *)haystack;
+ if (haystack_len < needle_len)
+ return NULL;
+
+ end = haystack + haystack_len - needle_len;
+
while (*p && p <= end)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p++;
}
+
+ return NULL;
}
-
- return NULL;
}
/**
@@ -1564,24 +1569,32 @@
g_strrstr (const gchar *haystack,
const gchar *needle)
{
- int i;
- int needle_len = strlen (needle);
- int haystack_len = strlen (haystack);
- const char *p = haystack + haystack_len - needle_len;
+ gsize i;
+ gsize needle_len;
+ gsize haystack_len;
+ const gchar *p;
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
-
+
+ needle_len = strlen (needle);
+ haystack_len = strlen (haystack);
+
if (needle_len == 0)
- return (char *)p;
+ return (gchar *)haystack;
+
+ if (haystack_len < needle_len)
+ return NULL;
+ p = haystack + haystack_len - needle_len;
+
while (p >= haystack)
{
for (i = 0; i < needle_len; i++)
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
@@ -1608,8 +1621,6 @@
gint haystack_len,
const gchar *needle)
{
- int i;
-
g_return_val_if_fail (haystack != NULL, NULL);
g_return_val_if_fail (needle != NULL, NULL);
@@ -1617,13 +1628,17 @@
return g_strrstr (haystack, needle);
else
{
- int needle_len = strlen (needle);
- const char *haystack_max = haystack + haystack_len;
- const char *p = haystack;
+ gsize needle_len = strlen (needle);
+ const gchar *haystack_max = haystack + haystack_len;
+ const gchar *p = haystack;
+ gsize i;
while (p < haystack_max && *p)
p++;
+ if (p < haystack + needle_len)
+ return NULL;
+
p -= needle_len;
while (p >= haystack)
@@ -1632,14 +1647,14 @@
if (p[i] != needle[i])
goto next;
- return (char *)p;
+ return (gchar *)p;
next:
p--;
}
- }
- return NULL;
+ return NULL;
+ }
}
Index: gstrfuncs.h
===================================================================
RCS file: /cvs/gnome/glib/gstrfuncs.h,v
retrieving revision 1.7
diff -u -r1.7 gstrfuncs.h
--- gstrfuncs.h 2001/06/08 23:14:02 1.7
+++ gstrfuncs.h 2001/06/20 16:27:01
@@ -46,11 +46,11 @@
gchar **endptr);
G_CONST_RETURN gchar* g_strerror (gint errnum) G_GNUC_CONST;
G_CONST_RETURN gchar* g_strsignal (gint signum) G_GNUC_CONST;
-gint g_strcasecmp (const gchar *s1,
+gint g_strcasecmp (const gchar *s1,
const gchar *s2);
-gint g_strncasecmp (const gchar *s1,
+gint g_strncasecmp (const gchar *s1,
const gchar *s2,
- guint n);
+ gsize n);
gchar* g_strdown (gchar *string);
gchar* g_strup (gchar *string);
gchar* g_strreverse (gchar *string);
@@ -61,12 +61,12 @@
const gchar *src,
gsize dest_size);
gchar * g_strstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
gchar * g_strrstr (const gchar *haystack,
const gchar *needle);
gchar * g_strrstr_len (const gchar *haystack,
- gint haystack_len,
+ gssize haystack_len,
const gchar *needle);
/* removes leading spaces */
@@ -85,8 +85,8 @@
gchar* g_strdup_vprintf (const gchar *format,
va_list args);
gchar* g_strndup (const gchar *str,
- guint n);
-gchar* g_strnfill (guint length,
+ gsize n);
+gchar* g_strnfill (gsize length,
gchar fill_char);
gchar* g_strconcat (const gchar *string1,
...); /* NULL terminated */
Index: gstring.c
===================================================================
RCS file: /cvs/gnome/glib/gstring.c,v
retrieving revision 1.22
diff -u -r1.22 gstring.c
--- gstring.c 2001/03/07 14:46:41 1.22
+++ gstring.c 2001/06/20 16:27:01
@@ -49,16 +49,16 @@
{
GHashTable *const_table;
GSList *storage_list;
- gint storage_next;
- gint this_size;
- gint default_size;
+ gsize storage_next;
+ gsize this_size;
+ gsize default_size;
};
struct _GRealString
{
gchar *str;
- gint len;
- gint alloc;
+ gsize len;
+ gsize alloc;
};
G_LOCK_DEFINE_STATIC (string_mem_chunk);
@@ -91,18 +91,36 @@
return h;
}
+#define MY_MAXSIZE ((gsize)-1)
+static inline gsize
+nearest_power (gsize base, gsize num)
+{
+ if (num > MY_MAXSIZE / 2)
+ {
+ return MY_MAXSIZE;
+ }
+ else
+ {
+ gsize n = base;
+
+ while (n < num)
+ n <<= 1;
+
+ return n;
+ }
+}
+
/* String Chunks.
*/
GStringChunk*
-g_string_chunk_new (gint default_size)
+g_string_chunk_new (gsize default_size)
{
GRealStringChunk *new_chunk = g_new (GRealStringChunk, 1);
- gint size = 1;
+ gsize size = 1;
- while (size < default_size)
- size <<= 1;
+ size = nearest_power (1, default_size);
new_chunk->const_table = NULL;
new_chunk->storage_list = NULL;
@@ -140,18 +158,15 @@
const gchar *string)
{
GRealStringChunk *chunk = (GRealStringChunk*) fchunk;
- gint len = strlen (string);
+ gsize len = strlen (string);
char* pos;
g_return_val_if_fail (chunk != NULL, NULL);
if ((chunk->storage_next + len + 1) > chunk->this_size)
{
- gint new_size = chunk->default_size;
+ gsize new_size = nearest_power (chunk->default_size, len + 1);
- while (new_size < len+1)
- new_size <<= 1;
-
chunk->storage_list = g_slist_prepend (chunk->storage_list,
g_new (char, new_size));
@@ -193,29 +208,19 @@
/* Strings.
*/
-static inline gint
-nearest_power (gint num)
-{
- gint n = 1;
-
- while (n < num)
- n <<= 1;
-
- return n;
-}
-
static void
-g_string_maybe_expand (GRealString* string, gint len)
+g_string_maybe_expand (GRealString* string,
+ gsize len)
{
if (string->len + len >= string->alloc)
{
- string->alloc = nearest_power (string->len + len + 1);
+ string->alloc = nearest_power (1, string->len + len + 1);
string->str = g_realloc (string->str, string->alloc);
}
}
GString*
-g_string_sized_new (guint dfl_size)
+g_string_sized_new (gsize dfl_size)
{
GRealString *string;
@@ -253,7 +258,7 @@
GString*
g_string_new_len (const gchar *init,
- gint len)
+ gssize len)
{
GString *string;
@@ -300,7 +305,7 @@
gchar *p, *q;
GRealString *string1 = (GRealString *) v;
GRealString *string2 = (GRealString *) v2;
- gint i = string1->len;
+ gsize i = string1->len;
if (i != string2->len)
return FALSE;
@@ -323,7 +328,7 @@
g_string_hash (const GString *str)
{
const gchar *p = str->str;
- gint n = str->len;
+ gsize n = str->len;
guint h = 0;
while (n--)
@@ -350,7 +355,7 @@
GString*
g_string_truncate (GString *fstring,
- guint len)
+ gsize len)
{
GRealString *string = (GRealString *) fstring;
@@ -365,21 +370,22 @@
GString*
g_string_insert_len (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len)
+ gssize len)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= string->len, fstring);
if (len < 0)
len = strlen (val);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, len);
@@ -412,7 +418,7 @@
GString*
g_string_append_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
@@ -442,7 +448,7 @@
GString*
g_string_prepend_len (GString *string,
const gchar *val,
- gint len)
+ gssize len)
{
g_return_val_if_fail (string != NULL, NULL);
g_return_val_if_fail (val != NULL, string);
@@ -461,30 +467,32 @@
GString*
g_string_insert (GString *fstring,
- gint pos,
+ gssize pos,
const gchar *val)
{
g_return_val_if_fail (fstring != NULL, NULL);
g_return_val_if_fail (val != NULL, fstring);
- g_return_val_if_fail (pos <= fstring->len, fstring);
+ if (pos >= 0)
+ g_return_val_if_fail (pos <= fstring->len, fstring);
return g_string_insert_len (fstring, pos, val, -1);
}
GString*
g_string_insert_c (GString *fstring,
- gint pos,
+ gssize pos,
gchar c)
{
GRealString *string = (GRealString *) fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (pos <= string->len, fstring);
g_string_maybe_expand (string, 1);
if (pos < 0)
pos = string->len;
+ else
+ g_return_val_if_fail (pos <= string->len, fstring);
/* If not just an append, move the old stuff */
if (pos < string->len)
@@ -501,19 +509,24 @@
GString*
g_string_erase (GString *fstring,
- gint pos,
- gint len)
+ gsize pos,
+ gsize len)
{
GRealString *string = (GRealString*)fstring;
g_return_val_if_fail (string != NULL, NULL);
- g_return_val_if_fail (len >= 0, fstring);
g_return_val_if_fail (pos >= 0, fstring);
g_return_val_if_fail (pos <= string->len, fstring);
- g_return_val_if_fail (pos + len <= string->len, fstring);
+
+ if (len < 0)
+ len = string->len - pos;
+ else
+ {
+ g_return_val_if_fail (pos + len <= string->len, fstring);
- if (pos + len < string->len)
- g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ if (pos + len < string->len)
+ g_memmove (string->str + pos, string->str + pos + len, string->len - (pos + len));
+ }
string->len -= len;
@@ -527,7 +540,7 @@
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
@@ -548,7 +561,7 @@
{
GRealString *string = (GRealString *) fstring;
guchar *s;
- gint n = string->len;
+ glong n = string->len;
g_return_val_if_fail (string != NULL, NULL);
Index: gstring.h
===================================================================
RCS file: /cvs/gnome/glib/gstring.h,v
retrieving revision 1.3
diff -u -r1.3 gstring.h
--- gstring.h 2001/03/07 14:46:41 1.3
+++ gstring.h 2001/06/20 16:27:01
@@ -36,13 +36,13 @@
struct _GString
{
- gchar *str;
- gint len;
+ gchar *str;
+ gssize len;
};
/* String Chunks
*/
-GStringChunk* g_string_chunk_new (gint size);
+GStringChunk* g_string_chunk_new (gsize size);
void g_string_chunk_free (GStringChunk *chunk);
gchar* g_string_chunk_insert (GStringChunk *chunk,
const gchar *string);
@@ -54,8 +54,8 @@
*/
GString* g_string_new (const gchar *init);
GString* g_string_new_len (const gchar *init,
- gint len);
-GString* g_string_sized_new (guint dfl_size);
+ 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,
@@ -64,16 +64,16 @@
GString* g_string_assign (GString *string,
const gchar *rval);
GString* g_string_truncate (GString *string,
- guint len);
+ gsize len);
GString* g_string_insert_len (GString *string,
- gint pos,
+ gssize pos,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append (GString *string,
const gchar *val);
GString* g_string_append_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_append_c (GString *string,
gchar c);
GString* g_string_prepend (GString *string,
@@ -82,16 +82,16 @@
gchar c);
GString* g_string_prepend_len (GString *string,
const gchar *val,
- gint len);
+ gssize len);
GString* g_string_insert (GString *string,
- gint pos,
+ gssize pos,
const gchar *val);
GString* g_string_insert_c (GString *string,
- gint pos,
+ gssize pos,
gchar c);
GString* g_string_erase (GString *string,
- gint pos,
- gint len);
+ gsize pos,
+ gsize len);
GString* g_string_down (GString *string);
GString* g_string_up (GString *string);
void g_string_printf (GString *string,
Index: gunicode.h
===================================================================
RCS file: /cvs/gnome/glib/gunicode.h,v
retrieving revision 1.19
diff -u -r1.19 gunicode.h
--- gunicode.h 2001/06/08 23:14:02 1.19
+++ gunicode.h 2001/06/20 16:27:01
@@ -109,7 +109,7 @@
* in case the locale's charset will be changed later using setlocale()
* or in some other way.
*/
-gboolean g_get_charset (char **charset);
+gboolean g_get_charset (G_CONST_RETURN char **charset);
/* These are all analogs of the <ctype.h> functions.
*/
@@ -169,8 +169,8 @@
gunichar g_utf8_get_char (const gchar *p);
gchar* g_utf8_offset_to_pointer (const gchar *str,
- gint offset);
-gint g_utf8_pointer_to_offset (const gchar *str,
+ glong offset);
+glong g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos);
gchar* g_utf8_prev_char (const gchar *p);
gchar* g_utf8_find_next_char (const gchar *p,
@@ -178,8 +178,8 @@
gchar* g_utf8_find_prev_char (const gchar *str,
const gchar *p);
-gint g_utf8_strlen (const gchar *p,
- gint max);
+glong g_utf8_strlen (const gchar *p,
+ gssize max);
/* Copies n characters from src to dest */
gchar* g_utf8_strncpy (gchar *dest,
@@ -189,44 +189,44 @@
/* 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,
- gint len,
+ gssize len,
gunichar c);
gchar* g_utf8_strrchr (const gchar *p,
- gint len,
+ gssize len,
gunichar c);
gunichar2 *g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar * g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written);
+ glong len,
+ glong *items_written);
gunichar * g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gunichar2 *g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
gchar* g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error);
/* Convert a single character into UTF-8. outbuf must have at
@@ -234,14 +234,14 @@
* result.
*/
gint g_unichar_to_utf8 (gunichar c,
- char *outbuf);
+ gchar *outbuf);
/* Validate a UTF8 string, return TRUE if valid, put pointer to
* first invalid char in **end
*/
gboolean g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end);
/* Validate a Unicode character */
Index: gutf8.c
===================================================================
RCS file: /cvs/gnome/glib/gutf8.c,v
retrieving revision 1.20
diff -u -r1.20 gutf8.c
--- gutf8.c 2001/06/08 23:14:02 1.20
+++ gutf8.c 2001/06/20 16:27:02
@@ -201,11 +201,11 @@
*
* Return value: the length of the string in characters
**/
-gint
+glong
g_utf8_strlen (const gchar *p,
- gint max)
+ gssize max)
{
- int len = 0;
+ glong len = 0;
const gchar *start = p;
if (max < 0)
@@ -276,7 +276,7 @@
**/
gchar *
g_utf8_offset_to_pointer (const gchar *str,
- gint offset)
+ glong offset)
{
const gchar *s = str;
while (offset--)
@@ -295,12 +295,12 @@
*
* Return value: the resulting character offset
**/
-gint
+glong
g_utf8_pointer_to_offset (const gchar *str,
const gchar *pos)
{
const gchar *s = str;
- gint offset = 0;
+ glong offset = 0;
while (s < pos)
{
@@ -413,7 +413,7 @@
* Return value: %TRUE if the returned charset is UTF-8
**/
gboolean
-g_get_charset (char **charset)
+g_get_charset (G_CONST_RETURN char **charset)
{
if (utf8_locale_cache != -1)
{
@@ -441,9 +441,10 @@
* Return value: number of bytes written
**/
int
-g_unichar_to_utf8 (gunichar c, gchar *outbuf)
+g_unichar_to_utf8 (gunichar c,
+ gchar *outbuf)
{
- size_t len = 0;
+ guint len = 0;
int first;
int i;
@@ -506,7 +507,7 @@
**/
gchar *
g_utf8_strchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
@@ -533,7 +534,7 @@
**/
gchar *
g_utf8_strrchr (const char *p,
- gint p_len,
+ gssize p_len,
gunichar c)
{
gchar ch[10];
@@ -549,9 +550,9 @@
* and return (gunichar)-2 on incomplete trailing character
*/
static inline gunichar
-g_utf8_get_char_extended (const gchar *p, int max_len)
+g_utf8_get_char_extended (const gchar *p, gsize max_len)
{
- gint i, len;
+ guint i, len;
gunichar wc = (guchar) *p;
if (wc < 0x80)
@@ -592,8 +593,6 @@
return (gunichar)-1;
}
- if (len == -1)
- return (gunichar)-1;
if (max_len >= 0 && len > max_len)
{
for (i = 1; i < max_len; i++)
@@ -644,8 +643,8 @@
**/
gunichar *
g_utf8_to_ucs4_fast (const gchar *str,
- gint len,
- gint *items_written)
+ glong len,
+ glong *items_written)
{
gint j, charlen;
gunichar *result;
@@ -759,9 +758,9 @@
**/
gunichar *
g_utf8_to_ucs4 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar *result = NULL;
@@ -838,9 +837,9 @@
**/
gchar *
g_ucs4_to_utf8 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gint result_length;
@@ -915,9 +914,9 @@
**/
gchar *
g_utf16_to_utf8 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
/* This function and g_utf16_to_ucs4 are almost exactly identical - The lines that differ
@@ -1059,9 +1058,9 @@
**/
gunichar *
g_utf16_to_ucs4 (const gunichar2 *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
const gunichar2 *in;
@@ -1202,9 +1201,9 @@
**/
gunichar2 *
g_utf8_to_utf16 (const gchar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
@@ -1317,9 +1316,9 @@
**/
gunichar2 *
g_ucs4_to_utf16 (const gunichar *str,
- gint len,
- gint *items_read,
- gint *items_written,
+ glong len,
+ glong *items_read,
+ glong *items_written,
GError **error)
{
gunichar2 *result = NULL;
@@ -1407,7 +1406,7 @@
**/
gboolean
g_utf8_validate (const gchar *str,
- gint max_len,
+ gssize max_len,
const gchar **end)
{
Index: gutils.c
===================================================================
RCS file: /cvs/gnome/glib/gutils.c,v
retrieving revision 1.95
diff -u -r1.95 gutils.c
--- gutils.c 2001/05/14 14:53:59 1.95
+++ gutils.c 2001/06/20 16:27:02
@@ -484,17 +484,17 @@
gchar*
g_path_get_basename (const gchar *file_name)
{
- register gint base;
- register gint last_nonslash;
- guint len;
+ register gssize base;
+ register gssize last_nonslash;
+ gsize len;
gchar *retval;
g_return_val_if_fail (file_name != NULL, NULL);
-
+
if (file_name[0] == '\0')
/* empty string */
return g_strdup (".");
-
+
last_nonslash = strlen (file_name) - 1;
while (last_nonslash >= 0 && file_name [last_nonslash] == G_DIR_SEPARATOR)
@@ -595,7 +595,7 @@
g_path_get_dirname (const gchar *file_name)
{
register gchar *base;
- register guint len;
+ register gsize len;
g_return_val_if_fail (file_name != NULL, NULL);
@@ -759,11 +759,11 @@
#ifdef P_tmpdir
if (!g_tmp_dir)
{
- int k;
+ gsize k;
g_tmp_dir = g_strdup (P_tmpdir);
k = strlen (g_tmp_dir);
- if (g_tmp_dir[k-1] == G_DIR_SEPARATOR)
- g_tmp_dir[k-1] = '\0';
+ if (k > 1 && g_tmp_dir[k - 1] == G_DIR_SEPARATOR)
+ g_tmp_dir[k - 1] = '\0';
}
#endif
@@ -827,9 +827,9 @@
struct passwd pwd;
# ifdef _SC_GETPW_R_SIZE_MAX
/* This reurns the maximum length */
- guint bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
+ glong bufsize = sysconf (_SC_GETPW_R_SIZE_MAX);
# else /* _SC_GETPW_R_SIZE_MAX */
- guint bufsize = 64;
+ glong bufsize = 64;
# endif /* _SC_GETPW_R_SIZE_MAX */
gint error;
Index: timeloop-basic.c
===================================================================
RCS file: /cvs/gnome/glib/timeloop-basic.c,v
retrieving revision 1.1
diff -u -r1.1 timeloop-basic.c
--- timeloop-basic.c 2000/12/05 20:45:32 1.1
+++ timeloop-basic.c 2001/06/20 16:27:02
@@ -30,8 +30,8 @@
int
read_all (int fd, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ size_t bytes_read = 0;
+ ssize_t count;
while (bytes_read < len)
{
@@ -53,8 +53,8 @@
int
write_all (int fd, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ size_t bytes_written = 0;
+ ssize_t count;
while (bytes_written < len)
{
Index: timeloop.c
===================================================================
RCS file: /cvs/gnome/glib/timeloop.c,v
retrieving revision 1.3
diff -u -r1.3 timeloop.c
--- timeloop.c 2001/03/26 19:23:17 1.3
+++ timeloop.c 2001/06/20 16:27:02
@@ -12,7 +12,7 @@
static int n_iters = 10000;
static GMainLoop *loop;
-void
+static void
io_pipe (GIOChannel **channels)
{
int fds[2];
@@ -27,11 +27,11 @@
channels[1] = g_io_channel_unix_new (fds[1]);
}
-gboolean
+static gboolean
read_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_read = 0;
- int count;
+ gsize bytes_read = 0;
+ gsize count;
GIOError err;
while (bytes_read < len)
@@ -51,11 +51,11 @@
return TRUE;
}
-gboolean
+static gboolean
write_all (GIOChannel *channel, char *buf, int len)
{
- int bytes_written = 0;
- int count;
+ gsize bytes_written = 0;
+ gsize count;
GIOError err;
while (bytes_written < len)
@@ -70,7 +70,7 @@
return TRUE;
}
-void
+static void
run_child (GIOChannel *in_channel, GIOChannel *out_channel)
{
int i;
@@ -94,7 +94,7 @@
exit (0);
}
-gboolean
+static gboolean
input_callback (GIOChannel *source,
GIOCondition condition,
gpointer data)
@@ -130,7 +130,7 @@
}
}
-void
+static void
create_child ()
{
int pid;
Index: docs/reference/glib/tmpl/macros_misc.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/macros_misc.sgml,v
retrieving revision 1.27
diff -u -r1.27 macros_misc.sgml
--- docs/reference/glib/tmpl/macros_misc.sgml 2001/06/19 12:13:21 1.27
+++ docs/reference/glib/tmpl/macros_misc.sgml 2001/06/20 16:27:02
@@ -71,7 +71,6 @@
Portable way to copy <type>va_list</type> variables.
</para>
-<!-- # Unused Parameters # -->
@ap1: the <type>va_list</type> variable to place a copy of @ap2 in.
@ap2: a <type>va_list</type>.
Index: docs/reference/glib/tmpl/strings.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/strings.sgml,v
retrieving revision 1.11
diff -u -r1.11 strings.sgml
--- docs/reference/glib/tmpl/strings.sgml 2001/05/19 05:32:50 1.11
+++ docs/reference/glib/tmpl/strings.sgml 2001/06/20 16:27:02
@@ -232,7 +232,8 @@
@string: a #GString.
@pos: the position of the characters to remove.
- len: the number of characters to remove.
+ len: the number of characters to remove, or -1 to remove all
+ following characters.
@Returns: the #GString.
Index: docs/reference/glib/tmpl/unicode.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/unicode.sgml,v
retrieving revision 1.6
diff -u -r1.6 unicode.sgml
--- docs/reference/glib/tmpl/unicode.sgml 2001/06/12 20:05:43 1.6
+++ docs/reference/glib/tmpl/unicode.sgml 2001/06/20 16:27:02
@@ -31,8 +31,9 @@
</para>
- charset:
@Returns:
+<!-- # Unused Parameters # -->
+ charset:
<!-- ##### FUNCTION g_unichar_validate ##### -->
Index: gmodule/ChangeLog
===================================================================
RCS file: /cvs/gnome/glib/gmodule/ChangeLog,v
retrieving revision 1.57
diff -u -r1.57 ChangeLog
--- gmodule/ChangeLog 2001/05/29 13:48:18 1.57
+++ gmodule/ChangeLog 2001/06/20 16:27:02
@@ -1,3 +1,9 @@
+2001-05-21 Mark Murnane <Mark Murnane ireland sun com>
+
+ * gmodule.c (g_str_check_suffix): Modified type of string_len
+ and suffix_len to be gsize. Properly accommodates return from
+ strlen().
+
2001-05-29 Sebastian Wilhelmi <wilhelmi ira uka de>
* gmodule.c (g_module_set_error_unduped): Do not g_strdup, as
Index: gmodule/gmodule.c
===================================================================
RCS file: /cvs/gnome/glib/gmodule/gmodule.c,v
retrieving revision 1.37
diff -u -r1.37 gmodule.c
--- gmodule/gmodule.c 2001/05/29 13:48:18 1.37
+++ gmodule/gmodule.c 2001/06/20 16:27:02
@@ -279,8 +279,8 @@
str_check_suffix (const gchar* string,
const gchar* suffix)
{
- guint string_len = strlen (string);
- guint suffix_len = strlen (suffix);
+ gsize string_len = strlen (string);
+ gsize suffix_len = strlen (suffix);
return string_len >= suffix_len &&
strcmp (string + string_len - suffix_len, suffix) == 0;
Index: tests/markup-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/markup-test.c,v
retrieving revision 1.1
diff -u -r1.1 markup-test.c
--- tests/markup-test.c 2000/10/27 02:46:03 1.1
+++ tests/markup-test.c 2001/06/20 16:27:02
@@ -56,7 +56,7 @@
static void
text_handler (GMarkupParseContext *context,
const gchar *text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error)
{
@@ -68,7 +68,7 @@
static void
passthrough_handler (GMarkupParseContext *context,
const gchar *passthrough_text,
- gint text_len,
+ gsize text_len,
gpointer user_data,
GError **error)
{
Index: tests/module-test.c
===================================================================
RCS file: /cvs/gnome/glib/tests/module-test.c,v
retrieving revision 1.1
diff -u -r1.1 module-test.c
--- tests/module-test.c 2000/12/22 13:44:25 1.1
+++ tests/module-test.c 2001/06/20 16:27:02
@@ -25,6 +25,7 @@
*/
#include <gmodule.h>
+#include <string.h>
gchar* global_state;
Index: tests/unicode-encoding.c
===================================================================
RCS file: /cvs/gnome/glib/tests/unicode-encoding.c,v
retrieving revision 1.2
diff -u -r1.2 unicode-encoding.c
--- tests/unicode-encoding.c 2001/01/06 03:09:46 1.2
+++ tests/unicode-encoding.c 2001/06/20 16:27:02
@@ -6,7 +6,7 @@
static gint exit_status = 0;
-void
+static void
croak (char *format, ...)
{
va_list va;
@@ -18,7 +18,7 @@
exit (1);
}
-void
+static void
fail (char *format, ...)
{
va_list va;
@@ -84,7 +84,7 @@
const gchar *end;
gboolean is_valid = g_utf8_validate (utf8, -1, &end);
GError *error = NULL;
- gint items_read, items_written;
+ glong items_read, items_written;
switch (status)
{
@@ -188,7 +188,7 @@
gunichar2 *utf16_from_utf8;
gunichar2 *utf16_from_ucs4;
gunichar *ucs4_result;
- gint bytes_written;
+ gsize bytes_written;
gint n_chars;
gchar *utf8_result;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]