mirror of https://github.com/GNOME/gimp.git
remove the usage of printf()/scanf() when sending doubles over the wire.
2001-07-15 Michael Natterer <mitch@gimp.org> * libgimpbase/gimpwire.c: remove the usage of printf()/scanf() when sending doubles over the wire. Instead, rely on the memory layout of gdouble being IEEE compliant and transmit 8 bytes in network byte order. * libgimpbase/gimpprotocol.h: increase GP_VERSION because this makes the wire protocol binary incompatible. * app/main.c * libgimp/gimp.c: removed the setlocate(LC_NUMERIC,"C") workaround.
This commit is contained in:
parent
b280b493c7
commit
dcaeb08a13
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
||||||
|
2001-07-15 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
|
* libgimpbase/gimpwire.c: remove the usage of printf()/scanf()
|
||||||
|
when sending doubles over the wire. Instead, rely on the memory
|
||||||
|
layout of gdouble being IEEE compliant and transmit 8 bytes in
|
||||||
|
network byte order.
|
||||||
|
|
||||||
|
* libgimpbase/gimpprotocol.h: increase GP_VERSION because this
|
||||||
|
makes the wire protocol binary incompatible.
|
||||||
|
|
||||||
|
* app/main.c
|
||||||
|
* libgimp/gimp.c: removed the setlocate(LC_NUMERIC,"C") workaround.
|
||||||
|
|
||||||
2001-07-15 Michael Natterer <mitch@gimp.org>
|
2001-07-15 Michael Natterer <mitch@gimp.org>
|
||||||
|
|
||||||
* app/core/gimp.c: don't use the global "the_gimp" variable.
|
* app/core/gimp.c: don't use the global "the_gimp" variable.
|
||||||
|
|
|
@ -124,8 +124,6 @@ main (int argc,
|
||||||
|
|
||||||
gtk_init (&argc, &argv);
|
gtk_init (&argc, &argv);
|
||||||
|
|
||||||
setlocale (LC_NUMERIC, "C"); /* gtk seems to zap this during init.. */
|
|
||||||
|
|
||||||
#ifdef HAVE_PUTENV
|
#ifdef HAVE_PUTENV
|
||||||
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
|
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
|
||||||
putenv (display_env);
|
putenv (display_env);
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <locale.h>
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -173,11 +172,9 @@ gimp_main (int argc,
|
||||||
char *argv[])
|
char *argv[])
|
||||||
{
|
{
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
int i, j, k;
|
gint i, j, k;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
setlocale (LC_NUMERIC, "C");
|
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
g_assert (PLUG_IN_INFO_PTR != NULL);
|
g_assert (PLUG_IN_INFO_PTR != NULL);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ extern "C" {
|
||||||
|
|
||||||
/* Increment every time the protocol changes
|
/* Increment every time the protocol changes
|
||||||
*/
|
*/
|
||||||
#define GP_VERSION 0x0008
|
#define GP_VERSION 0x0009
|
||||||
|
|
||||||
|
|
||||||
enum
|
enum
|
||||||
|
|
|
@ -31,13 +31,13 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
|
||||||
#ifdef G_OS_WIN32
|
#ifdef G_OS_WIN32
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <glib.h>
|
|
||||||
|
|
||||||
#include "gimpwire.h"
|
#include "gimpwire.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,11 +58,11 @@ static gboolean wire_compare (guint32 *a,
|
||||||
guint32 *b);
|
guint32 *b);
|
||||||
|
|
||||||
|
|
||||||
static GHashTable *wire_ht = NULL;
|
static GHashTable *wire_ht = NULL;
|
||||||
static WireIOFunc wire_read_func = NULL;
|
static WireIOFunc wire_read_func = NULL;
|
||||||
static WireIOFunc wire_write_func = NULL;
|
static WireIOFunc wire_write_func = NULL;
|
||||||
static WireFlushFunc wire_flush_func = NULL;
|
static WireFlushFunc wire_flush_func = NULL;
|
||||||
static gboolean wire_error_val = FALSE;
|
static gboolean wire_error_val = FALSE;
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -130,7 +130,7 @@ wire_read (GIOChannel *channel,
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
error = g_io_channel_read (channel, (char*) buf, count, &bytes);
|
error = g_io_channel_read (channel, (gchar *) buf, count, &bytes);
|
||||||
}
|
}
|
||||||
while ((error == G_IO_ERROR_AGAIN) ||
|
while ((error == G_IO_ERROR_AGAIN) ||
|
||||||
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
|
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
|
||||||
|
@ -181,7 +181,7 @@ wire_write (GIOChannel *channel,
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
bytes = 0;
|
bytes = 0;
|
||||||
error = g_io_channel_write (channel, (char*) buf, count, &bytes);
|
error = g_io_channel_write (channel, (gchar *) buf, count, &bytes);
|
||||||
}
|
}
|
||||||
while ((error == G_IO_ERROR_AGAIN) ||
|
while ((error == G_IO_ERROR_AGAIN) ||
|
||||||
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
|
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
|
||||||
|
@ -231,7 +231,7 @@ wire_read_msg (GIOChannel *channel,
|
||||||
if (wire_error_val)
|
if (wire_error_val)
|
||||||
return !wire_error_val;
|
return !wire_error_val;
|
||||||
|
|
||||||
if (!wire_read_int32 (channel, &msg->type, 1))
|
if (! wire_read_int32 (channel, &msg->type, 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
handler = g_hash_table_lookup (wire_ht, &msg->type);
|
handler = g_hash_table_lookup (wire_ht, &msg->type);
|
||||||
|
@ -256,7 +256,7 @@ wire_write_msg (GIOChannel *channel,
|
||||||
if (!handler)
|
if (!handler)
|
||||||
g_error ("could not find handler for message: %d", msg->type);
|
g_error ("could not find handler for message: %d", msg->type);
|
||||||
|
|
||||||
if (!wire_write_int32 (channel, &msg->type, 1))
|
if (! wire_write_int32 (channel, &msg->type, 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
(* handler->write_func) (channel, msg);
|
(* handler->write_func) (channel, msg);
|
||||||
|
@ -283,7 +283,7 @@ wire_read_int32 (GIOChannel *channel,
|
||||||
{
|
{
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
if (!wire_read_int8 (channel, (guint8*) data, count * 4))
|
if (! wire_read_int8 (channel, (guint8 *) data, count * 4))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
|
@ -303,7 +303,7 @@ wire_read_int16 (GIOChannel *channel,
|
||||||
{
|
{
|
||||||
if (count > 0)
|
if (count > 0)
|
||||||
{
|
{
|
||||||
if (!wire_read_int8 (channel, (guint8*) data, count * 2))
|
if (! wire_read_int8 (channel, (guint8 *) data, count * 2))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
while (count--)
|
while (count--)
|
||||||
|
@ -329,15 +329,27 @@ wire_read_double (GIOChannel *channel,
|
||||||
gdouble *data,
|
gdouble *data,
|
||||||
gint count)
|
gint count)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gdouble *t;
|
||||||
gint i;
|
guint32 tmp[2];
|
||||||
|
gint i;
|
||||||
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
||||||
|
guint32 swap;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
t = (gdouble *) tmp;
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
if (!wire_read_string (channel, &str, 1))
|
if (! wire_read_int8 (channel, (guint8 *) tmp, 8))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
sscanf (str, "%le", &data[i]);
|
|
||||||
g_free (str);
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
||||||
|
swap = g_ntohl (tmp[1]);
|
||||||
|
tmp[1] = g_ntohl (tmp[0]);
|
||||||
|
tmp[0] = swap;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
data[i] = *t;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -359,7 +371,7 @@ wire_read_string (GIOChannel *channel,
|
||||||
if (tmp > 0)
|
if (tmp > 0)
|
||||||
{
|
{
|
||||||
data[i] = g_new (gchar, tmp);
|
data[i] = g_new (gchar, tmp);
|
||||||
if (!wire_read_int8 (channel, (guint8*) data[i], tmp))
|
if (! wire_read_int8 (channel, (guint8 *) data[i], tmp))
|
||||||
{
|
{
|
||||||
g_free (data[i]);
|
g_free (data[i]);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -387,7 +399,7 @@ wire_write_int32 (GIOChannel *channel,
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
tmp = g_htonl (data[i]);
|
tmp = g_htonl (data[i]);
|
||||||
if (!wire_write_int8 (channel, (guint8*) &tmp, 4))
|
if (! wire_write_int8 (channel, (guint8 *) &tmp, 4))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -408,7 +420,7 @@ wire_write_int16 (GIOChannel *channel,
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
tmp = g_htons (data[i]);
|
tmp = g_htons (data[i]);
|
||||||
if (!wire_write_int8 (channel, (guint8*) &tmp, 2))
|
if (! wire_write_int8 (channel, (guint8 *) &tmp, 2))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -429,16 +441,42 @@ wire_write_double (GIOChannel *channel,
|
||||||
gdouble *data,
|
gdouble *data,
|
||||||
gint count)
|
gint count)
|
||||||
{
|
{
|
||||||
gchar *t;
|
gdouble *t;
|
||||||
gchar buf[128];
|
guint32 tmp[2];
|
||||||
gint i;
|
gint i;
|
||||||
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
||||||
|
guint32 swap;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
t = (gdouble *) tmp;
|
||||||
|
|
||||||
t = buf;
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
g_snprintf (buf, sizeof (buf), "%0.50e", data[i]);
|
*t = data[i];
|
||||||
if (!wire_write_string (channel, &t, 1))
|
|
||||||
|
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
|
||||||
|
swap = g_htonl (tmp[1]);
|
||||||
|
tmp[1] = g_htonl (tmp[0]);
|
||||||
|
tmp[0] = swap;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (! wire_write_int8 (channel, (guint8 *) tmp, 8))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
{
|
||||||
|
gint j;
|
||||||
|
|
||||||
|
g_print ("Wire representation of %f:\t", data[i]);
|
||||||
|
|
||||||
|
for (j = 0; j < 8; j++)
|
||||||
|
{
|
||||||
|
g_print ("%02x ", ((guchar *) tmp)[j]);
|
||||||
|
}
|
||||||
|
|
||||||
|
g_print ("\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -459,10 +497,10 @@ wire_write_string (GIOChannel *channel,
|
||||||
else
|
else
|
||||||
tmp = 0;
|
tmp = 0;
|
||||||
|
|
||||||
if (!wire_write_int32 (channel, &tmp, 1))
|
if (! wire_write_int32 (channel, &tmp, 1))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (tmp > 0)
|
if (tmp > 0)
|
||||||
if (!wire_write_int8 (channel, (guint8*) data[i], tmp))
|
if (! wire_write_int8 (channel, (guint8 *) data[i], tmp))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue