Re: GLib and 64-bit Windows
- From: Jake Goulding <goulding vivisimo com>
- To: GTK Devel List <gtk-devel-list gnome org>
- Cc: Tor Lillqvist <tml iki fi>, Hans Breuer <hans breuer org>, Owen Taylor <otaylor redhat com>
- Subject: Re: GLib and 64-bit Windows
- Date: Thu, 19 Apr 2007 11:49:56 -0400
I'll wait to hear about the proper place to put these... but here are
the mess of patches I currently apply against 2.12.9 to get something
working under Windows 64-bit.
I tried to split all the patches into clearly-defined sections, but
there is the chance that some overlap occurs. I simply apply all the
patches, so I'm not sure if anything really depends on anything else.
Criticism is much appreciated (especially about the memory function
signature changes)!
-Jake
diff -r --unified glib-2.12.9/glibconfig.h.win32 glib/glibconfig.h.win32
--- glib-2.12.9/glibconfig.h.win32 2007-01-16 18:50:49.000000000 -0500
+++ glib/glibconfig.h.win32 2007-04-13 17:41:09.687500000 -0400
@@ -64,6 +64,17 @@
#define G_GINT64_FORMAT "I64i"
#define G_GUINT64_FORMAT "I64u"
+#if defined(_MSC_VER) && defined (_M_X64)
+#define GLIB_SIZEOF_VOID_P 8
+#define GLIB_SIZEOF_LONG 4
+#define GLIB_SIZEOF_SIZE_T 8
+
+typedef signed __int64 gssize;
+typedef unsigned __int64 gsize;
+#define G_GSIZE_MODIFIER "I64"
+#define G_GSSIZE_FORMAT "I64i"
+#define G_GSIZE_FORMAT "I64u"
+#else
#define GLIB_SIZEOF_VOID_P 4
#define GLIB_SIZEOF_LONG 4
#define GLIB_SIZEOF_SIZE_T 4
@@ -73,14 +84,23 @@
#define G_GSIZE_MODIFIER ""
#define G_GSSIZE_FORMAT "i"
#define G_GSIZE_FORMAT "u"
+#endif
#define G_MAXSIZE G_MAXUINT
+#if defined(_MSC_VER) && defined (_M_X64)
+#define GPOINTER_TO_INT(p) ((gint) (long long) (p))
+#define GPOINTER_TO_UINT(p) ((guint) (long long) (p))
+
+#define GINT_TO_POINTER(i) ((gpointer) (long long) (i))
+#define GUINT_TO_POINTER(u) ((gpointer) (long long) (u))
+#else
#define GPOINTER_TO_INT(p) ((gint) (p))
#define GPOINTER_TO_UINT(p) ((guint) (p))
#define GINT_TO_POINTER(i) ((gpointer) (i))
#define GUINT_TO_POINTER(u) ((gpointer) (u))
+#endif
#ifdef NeXT /* @#% ! NeXTStep */
# define g_ATEXIT(proc) (!atexit (proc))
diff -r --unified glib-2.12.9/glib/gbacktrace.h glib/glib/gbacktrace.h
--- glib-2.12.9/glib/gbacktrace.h 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gbacktrace.h 2007-04-13 17:41:09.312500000 -0400
@@ -50,6 +50,8 @@
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("int $03"); }G_STMT_END
#elif defined (_MSC_VER) && defined (_M_IX86)
# define G_BREAKPOINT() G_STMT_START{ __asm int 3h }G_STMT_END
+#elif defined (_MSC_VER) && defined (_M_X64)
+# define G_BREAKPOINT() G_STMT_START{}G_STMT_END
#elif defined (__alpha__) && !defined(__osf__) && defined (__GNUC__) && __GNUC__ >= 2
# define G_BREAKPOINT() G_STMT_START{ __asm__ __volatile__ ("bpt"); }G_STMT_END
#else /* !__i386__ && !__alpha__ */
diff -r --unified glib-2.12.9/glib/giowin32.c glib/glib/giowin32.c
--- glib-2.12.9/glib/giowin32.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/giowin32.c 2007-04-13 17:41:09.375000000 -0400
@@ -57,13 +57,13 @@
G_IO_WIN32_FILE_DESC, /* Unix-like file descriptors from
* _open() or _pipe(). Read with read().
* Have to create separate thread to read.
- */
+5~5~ */
G_IO_WIN32_SOCKET /* Sockets. No separate thread */
} GIOWin32ChannelType;
struct _GIOWin32Channel {
GIOChannel channel;
- gint fd; /* Either a Unix-like file handle as provided
+ gint64 fd; /* Either a Unix-like file handle as provided
* by the Microsoft C runtime, or a SOCKET
* as provided by WinSock.
*/
@@ -112,7 +112,7 @@
/* Following fields used by socket channels */
int event_mask;
int last_events;
- int event;
+ gpointer event;
gboolean write_would_have_blocked;
};
@@ -390,11 +390,11 @@
g_io_channel_ref ((GIOChannel *)channel);
if (channel->debug)
- g_print ("read_thread %#x: start fd=%d, data_avail=%#x space_avail=%#x\n",
+ g_print ("read_thread %#x: start fd=%d, data_avail=%p space_avail=%p\n",
channel->thread_id,
channel->fd,
- (guint) channel->data_avail_event,
- (guint) channel->space_avail_event);
+ channel->data_avail_event,
+ channel->space_avail_event);
channel->direction = 0;
channel->buffer = g_malloc (BUFFER_SIZE);
@@ -501,11 +501,11 @@
g_io_channel_ref ((GIOChannel *)channel);
if (channel->debug)
- g_print ("write_thread %#x: start fd=%d, data_avail=%#x space_avail=%#x\n",
+ g_print ("write_thread %#x: start fd=%d, data_avail=%p space_avail=%p\n",
channel->thread_id,
channel->fd,
- (guint) channel->data_avail_event,
- (guint) channel->space_avail_event);
+ channel->data_avail_event,
+ channel->space_avail_event);
channel->direction = 1;
channel->buffer = g_malloc (BUFFER_SIZE);
@@ -924,6 +924,9 @@
g_assert_not_reached ();
abort ();
}
+
+ /* Never reached, just fixes a warning */
+ return FALSE;
}
static gboolean
@@ -1015,8 +1018,8 @@
}
if (win32_channel->debug)
- g_print ("g_io_win32_msg_read: for %#x\n",
- (guint) win32_channel->hwnd);
+ g_print ("g_io_win32_msg_read: for %p\n",
+ win32_channel->hwnd);
if (!PeekMessage (&msg, win32_channel->hwnd, 0, 0, PM_REMOVE))
return G_IO_STATUS_AGAIN;
@@ -1102,7 +1105,7 @@
watch->condition = condition;
- watch->pollfd.fd = G_WIN32_MSG_HANDLE;
+ watch->pollfd.fd = GINT_TO_POINTER(G_WIN32_MSG_HANDLE);
watch->pollfd.events = condition;
g_source_add_poll (source, &watch->pollfd);
@@ -1306,7 +1309,7 @@
if (win32_channel->data_avail_event == NULL)
create_events (win32_channel);
- watch->pollfd.fd = (gint) win32_channel->data_avail_event;
+ watch->pollfd.fd = win32_channel->data_avail_event;
watch->pollfd.events = condition;
if (win32_channel->debug)
@@ -1473,7 +1476,7 @@
watch->condition = condition;
if (win32_channel->event == 0)
- win32_channel->event = (int) WSACreateEvent ();
+ win32_channel->event = WSACreateEvent ();
watch->pollfd.fd = win32_channel->event;
watch->pollfd.events = condition;
@@ -1973,7 +1976,7 @@
if (win32_channel->data_avail_event == NULL)
create_events (win32_channel);
- fd->fd = (gint) win32_channel->data_avail_event;
+ fd->fd = win32_channel->data_avail_event;
if (win32_channel->thread_id == 0 && (condition & G_IO_IN))
{
@@ -1985,11 +1988,11 @@
break;
case G_IO_WIN32_SOCKET:
- fd->fd = (int) WSACreateEvent ();
+ fd->fd = WSACreateEvent ();
break;
case G_IO_WIN32_WINDOWS_MESSAGES:
- fd->fd = G_WIN32_MSG_HANDLE;
+ fd->fd = GINT_TO_POINTER(G_WIN32_MSG_HANDLE);
break;
default:
diff -r --unified glib-2.12.9/glib/gmain.c glib/glib/gmain.c
--- glib-2.12.9/glib/gmain.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gmain.c 2007-04-13 17:41:09.437500000 -0400
@@ -330,7 +330,7 @@
for (f = fds; f < &fds[nfds]; ++f)
if (f->fd >= 0)
{
- if (f->fd == G_WIN32_MSG_HANDLE)
+ if (f->fd == GINT_TO_POINTER(G_WIN32_MSG_HANDLE))
poll_msgs = TRUE;
else if (nhandles == MAXIMUM_WAIT_OBJECTS)
{
@@ -481,14 +481,14 @@
if (f->fd >= 0)
{
if (f->events & G_IO_IN)
- if (f->fd == G_WIN32_MSG_HANDLE)
+ if (f->fd == GINT_TO_POINTER(G_WIN32_MSG_HANDLE))
f->revents |= G_IO_IN;
}
}
else if (ready >= WAIT_OBJECT_0 && ready < WAIT_OBJECT_0 + nhandles)
for (f = fds; f < &fds[nfds]; ++f)
{
- if (f->fd == (gint) handles[ready - WAIT_OBJECT_0])
+ if (f->fd == handles[ready - WAIT_OBJECT_0])
{
f->revents = f->events;
#ifdef G_MAIN_POLL_DEBUG
@@ -686,7 +686,7 @@
if (context->wake_up_semaphore == NULL)
g_error ("Cannot create wake-up semaphore: %s",
g_win32_error_message (GetLastError ()));
- context->wake_up_rec.fd = (gint) context->wake_up_semaphore;
+ context->wake_up_rec.fd = context->wake_up_semaphore;
context->wake_up_rec.events = G_IO_IN;
# ifdef G_MAIN_POLL_DEBUG
g_print ("wake-up semaphore: %#x\n", (guint) context->wake_up_semaphore);
@@ -3807,7 +3807,7 @@
GChildWatchSource *child_watch_source = (GChildWatchSource *)source;
#ifdef G_OS_WIN32
- child_watch_source->poll.fd = (int)pid;
+ child_watch_source->poll.fd = pid;
child_watch_source->poll.events = G_IO_IN;
g_source_add_poll (source, &child_watch_source->poll);
diff -r --unified glib-2.12.9/glib/gmain.h glib/glib/gmain.h
--- glib-2.12.9/glib/gmain.h 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gmain.h 2007-04-13 17:41:09.437500000 -0400
@@ -120,7 +120,8 @@
struct _GPollFD
{
- gint fd;
+// gint fd;
+ gpointer fd;
gushort events;
gushort revents;
};
diff -r --unified glib-2.12.9/glib/gmem.c glib/glib/gmem.c
--- glib-2.12.9/glib/gmem.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gmem.c 2007-04-13 17:41:09.453125000 -0400
@@ -120,7 +120,7 @@
/* --- functions --- */
gpointer
-g_malloc (gulong n_bytes)
+g_malloc (gsize n_bytes)
{
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
@@ -139,7 +139,7 @@
}
gpointer
-g_malloc0 (gulong n_bytes)
+g_malloc0 (gsize n_bytes)
{
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
@@ -159,7 +159,7 @@
gpointer
g_realloc (gpointer mem,
- gulong n_bytes)
+ gsize n_bytes)
{
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
@@ -188,7 +188,7 @@
}
gpointer
-g_try_malloc (gulong n_bytes)
+g_try_malloc (gsize n_bytes)
{
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
@@ -199,7 +199,7 @@
}
gpointer
-g_try_malloc0 (gulong n_bytes)
+g_try_malloc0 (gsize n_bytes)
{
gpointer mem;
@@ -213,7 +213,7 @@
gpointer
g_try_realloc (gpointer mem,
- gulong n_bytes)
+ gsize n_bytes)
{
if (G_UNLIKELY (!g_mem_initialized))
g_mem_init_nomessage();
@@ -312,7 +312,7 @@
static void
profiler_log (ProfilerJob job,
- gulong n_bytes,
+ gsize n_bytes,
gboolean success)
{
g_mutex_lock (gmem_profile_mutex);
@@ -604,7 +604,7 @@
GMemChunk*
g_mem_chunk_new (const gchar *name,
gint atom_size,
- gulong area_size,
+ gsize area_size,
gint type)
{
GMemChunk *mem_chunk;
diff -r --unified glib-2.12.9/glib/gmem.h glib/glib/gmem.h
--- glib-2.12.9/glib/gmem.h 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gmem.h 2007-04-13 17:41:09.453125000 -0400
@@ -44,15 +44,15 @@
/* Memory allocation functions
*/
-gpointer g_malloc (gulong n_bytes) G_GNUC_MALLOC;
-gpointer g_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
+gpointer g_malloc (gsize n_bytes) G_GNUC_MALLOC;
+gpointer g_malloc0 (gsize n_bytes) G_GNUC_MALLOC;
gpointer g_realloc (gpointer mem,
- gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+ gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
void g_free (gpointer mem);
-gpointer g_try_malloc (gulong n_bytes) G_GNUC_MALLOC;
-gpointer g_try_malloc0 (gulong n_bytes) G_GNUC_MALLOC;
+gpointer g_try_malloc (gsize n_bytes) G_GNUC_MALLOC;
+gpointer g_try_malloc0 (gsize n_bytes) G_GNUC_MALLOC;
gpointer g_try_realloc (gpointer mem,
- gulong n_bytes) G_GNUC_WARN_UNUSED_RESULT;
+ gsize n_bytes) G_GNUC_WARN_UNUSED_RESULT;
/* Convenience memory allocators
@@ -123,7 +123,7 @@
#define G_ALLOC_AND_FREE 2
GMemChunk* g_mem_chunk_new (const gchar *name,
gint atom_size,
- gulong area_size,
+ gsize area_size,
gint type);
void g_mem_chunk_destroy (GMemChunk *mem_chunk);
gpointer g_mem_chunk_alloc (GMemChunk *mem_chunk);
diff -r --unified glib-2.12.9/glib/gbase64.c glib/glib/gbase64.c
--- glib-2.12.9/glib/gbase64.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gbase64.c 2007-04-13 17:41:09.312500000 -0400
@@ -338,7 +338,8 @@
gsize *out_len)
{
guchar *ret;
- gint inlen, state = 0;
+ gsize inlen;
+ gint state = 0;
guint save = 0;
inlen = strlen (text);
diff -r --unified glib-2.12.9/glib/gdate.c glib/glib/gdate.c
--- glib-2.12.9/glib/gdate.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gdate.c 2007-04-13 17:41:09.343750000 -0400
@@ -931,7 +931,7 @@
*/
void
g_date_set_time (GDate *date,
- GTime *time_)
+ GTime time_)
{
g_date_set_time_t (date, (time_t) time_);
}
diff -r --unified glib-2.12.9/glib/gqsort.c glib/glib/gqsort.c
--- glib-2.12.9/glib/gqsort.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gqsort.c 2007-04-13 17:41:09.515625000 -0400
@@ -235,7 +235,9 @@
of the array to sort, and END_PTR points at the very last element in
the array (*not* one beyond it!). */
+#ifndef min
#define min(x, y) ((x) < (y) ? (x) : (y))
+#endif
{
char *const end_ptr = &base_ptr[size * (total_elems - 1)];
diff -r --unified glib-2.12.9/glib/gstrfuncs.c glib/glib/gstrfuncs.c
--- glib-2.12.9/glib/gstrfuncs.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gstrfuncs.c 2007-04-13 17:41:09.546875000 -0400
@@ -2037,7 +2037,7 @@
g_strcompress (const gchar *source)
{
const gchar *p = source, *octal;
- gchar *dest = g_malloc (strlen (source) + 1);
+ gchar *dest = g_malloc ((size_t)strlen (source) + 1);
gchar *q = dest;
while (*p)
diff -r --unified glib-2.12.9/glib/gtimer.c glib/glib/gtimer.c
--- glib-2.12.9/glib/gtimer.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gtimer.c 2007-04-13 17:41:09.578125000 -0400
@@ -390,16 +390,19 @@
g_time_val_to_iso8601 (GTimeVal *time_)
{
gchar *retval;
+ time_t a;
g_return_val_if_fail (time_->tv_usec >= 0 && time_->tv_usec < G_USEC_PER_SEC, NULL);
#define ISO_8601_LEN 21
#define ISO_8601_FORMAT "%Y-%m-%dT%H:%M:%SZ"
retval = g_new0 (gchar, ISO_8601_LEN + 1);
+
+ a = time_->tv_sec;
strftime (retval, ISO_8601_LEN,
ISO_8601_FORMAT,
- gmtime (&(time_->tv_sec)));
+ gmtime (&(a)));
return retval;
}
diff -r --unified glib-2.12.9/glib/makefile.msc glib/glib/makefile.msc
--- glib-2.12.9/glib/makefile.msc 2007-01-16 18:50:30.000000000 -0500
+++ glib/glib/makefile.msc 2007-04-13 18:04:54.484375000 -0400
@@ -100,7 +100,7 @@
glib.def: glib.symbols
echo EXPORTS > glib.def
- cl /EP -DINCLUDE_VARIABLES -DG_OS_WIN32 -DINCLUDE_INTERNAL_SYMBOLS -DALL_FILES glib.symbols >> glib.def
+ cl /EP -DINCLUDE_VARIABLES -DG_OS_WIN32 -DINCLUDE_INTERNAL_SYMBOLS -DALL_FILES -DG_GNUC_MALLOC= -DG_GNUC_CONST= -DG_GNUC_NULL_TERMINATED= -DG_GNUC_NORETURN= -DG_GNUC_PRINTF=;G_GNUC_PRINTF glib.symbols >> glib.def
glib.res : glib.rc
rc -DBUILDNUMBER=0 -r -fo glib.res glib.rc
diff -r --unified glib-2.12.9/gobject/makefile.msc glib/gobject/makefile.msc
--- glib-2.12.9/gobject/makefile.msc 2007-01-16 18:50:31.000000000 -0500
+++ glib/gobject/makefile.msc 2007-04-13 17:41:09.875000000 -0400
@@ -50,7 +50,7 @@
gobject.def: gobject.symbols
echo EXPORTS > gobject.def
- cl /EP -DINCLUDE_VARIABLES -DG_OS_WIN32 -DALL_FILES gobject.symbols >> gobject.def
+ cl /EP -DINCLUDE_VARIABLES -DG_OS_WIN32 -DALL_FILES -DG_GNUC_MALLOC= -DG_GNUC_CONST= -DG_GNUC_NULL_TERMINATED= -DG_GNUC_NORETURN= -DG_GNUC_PRINTF=;G_GNUC_PRINTF gobject.symbols >> gobject.def
gobject.res : gobject.rc
rc -DBUILDNUMBER=0 -r -fo gobject.res gobject.rc
diff -r --unified glib-2.12.9/tests/testglib.c glib/tests/testglib.c
--- glib-2.12.9/tests/testglib.c 2007-01-16 18:24:32.000000000 -0500
+++ glib/tests/testglib.c 2007-04-13 17:41:14.640625000 -0400
@@ -1473,9 +1473,10 @@
strcpy (template, "foobar");
fd = g_mkstemp (template);
- if (fd != -1)
+ if (fd != -1) {
g_print ("g_mkstemp works even if template doesn't end in XXXXXX\n");
- close (fd);
+ close (fd);
+ }
strcpy (template, "fooXXXXXX");
fd = g_mkstemp (template);
if (fd == -1)
@@ -1497,53 +1498,59 @@
if (strcmp (chars, hello) != 0)
g_print ("wrote '%s', but got '%s'\n", hello, chars);
- close (fd);
+ if (fd != -1)
+ close (fd);
remove (template);
error = NULL;
strcpy (template, "zap" G_DIR_SEPARATOR_S "barXXXXXX");
fd = g_file_open_tmp (template, &name_used, &error);
- if (fd != -1)
+ if (fd != -1) {
g_print ("g_file_open_tmp works even if template contains '%s'\n",
G_DIR_SEPARATOR_S);
+ close (fd);
+ }
else
g_print ("g_file_open_tmp correctly returns error: %s\n",
error->message);
- close (fd);
+
g_clear_error (&error);
#ifdef G_OS_WIN32
strcpy (template, "zap/barXXXXXX");
fd = g_file_open_tmp (template, &name_used, &error);
- if (fd != -1)
+ if (fd != -1) {
g_print ("g_file_open_tmp works even if template contains '/'\n");
+ close (fd);
+ }
else
g_print ("g_file_open_tmp correctly returns error: %s\n",
error->message);
- close (fd);
g_clear_error (&error);
#endif
strcpy (template, "zapXXXXXX");
fd = g_file_open_tmp (template, &name_used, &error);
- if (fd == -1)
+ if (fd == -1) {
g_print ("g_file_open_tmp didn't work for template '%s': %s\n",
template, error->message);
+ close (fd);
+ }
else
g_print ("g_file_open_tmp for template '%s' used name '%s'\n",
template, name_used);
- close (fd);
g_clear_error (&error);
remove (name_used);
fd = g_file_open_tmp (NULL, &name_used, &error);
- if (fd == -1)
+ if (fd == -1) {
g_print ("g_file_open_tmp didn't work for a NULL template: %s\n",
error->message);
+ close (fd);
+ }
else
g_print ("g_file_open_tmp for NULL template used name '%s'\n",
name_used);
- close (fd);
g_clear_error (&error);
remove (name_used);
diff -r --unified glib-2.12.9/tests/thread-test.c glib/tests/thread-test.c
--- glib-2.12.9/tests/thread-test.c 2007-01-16 18:24:32.000000000 -0500
+++ glib/tests/thread-test.c 2007-04-13 17:41:15.000000000 -0400
@@ -396,7 +396,8 @@
g_thread_use_default_impl = FALSE;
run_all_tests ();
-
+#else
+ fprintf(stderr, "Threads disabled\n");
#endif
return 0;
}
diff -r --unified glib-2.12.9/glib/gthread.c glib/glib/gthread.c
--- glib-2.12.9/glib/gthread.c 2007-01-16 18:24:35.000000000 -0500
+++ glib/glib/gthread.c 2007-04-13 17:41:09.562500000 -0400
@@ -89,12 +89,12 @@
gboolean g_threads_got_initialized = FALSE;
GThreadFunctions g_thread_functions_for_glib_use = {
- (GMutex*(*)())g_thread_fail, /* mutex_new */
+ (GMutex*(*)(void))g_thread_fail, /* mutex_new */
NULL, /* mutex_lock */
NULL, /* mutex_trylock */
NULL, /* mutex_unlock */
NULL, /* mutex_free */
- (GCond*(*)())g_thread_fail, /* cond_new */
+ (GCond*(*)(void))g_thread_fail, /* cond_new */
NULL, /* cond_signal */
NULL, /* cond_broadcast */
NULL, /* cond_wait */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]