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:
Michael Natterer 2001-07-15 20:47:03 +00:00 committed by Michael Natterer
parent b280b493c7
commit dcaeb08a13
5 changed files with 80 additions and 34 deletions

View File

@ -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>
* app/core/gimp.c: don't use the global "the_gimp" variable.

View File

@ -124,8 +124,6 @@ main (int argc,
gtk_init (&argc, &argv);
setlocale (LC_NUMERIC, "C"); /* gtk seems to zap this during init.. */
#ifdef HAVE_PUTENV
display_env = g_strconcat ("DISPLAY=", gdk_get_display (), NULL);
putenv (display_env);

View File

@ -21,7 +21,6 @@
#include "config.h"
#include <locale.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
@ -173,11 +172,9 @@ gimp_main (int argc,
char *argv[])
{
#ifdef G_OS_WIN32
int i, j, k;
gint i, j, k;
#endif
setlocale (LC_NUMERIC, "C");
#ifdef G_OS_WIN32
g_assert (PLUG_IN_INFO_PTR != NULL);

View File

@ -29,7 +29,7 @@ extern "C" {
/* Increment every time the protocol changes
*/
#define GP_VERSION 0x0008
#define GP_VERSION 0x0009
enum

View File

@ -31,13 +31,13 @@
#include <unistd.h>
#endif
#include <glib.h>
#ifdef G_OS_WIN32
#include <process.h>
#include <io.h>
#endif
#include <glib.h>
#include "gimpwire.h"
@ -130,7 +130,7 @@ wire_read (GIOChannel *channel,
do
{
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) ||
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
@ -181,7 +181,7 @@ wire_write (GIOChannel *channel,
do
{
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) ||
(error == G_IO_ERROR_UNKNOWN && errno == EINTR));
@ -329,15 +329,27 @@ wire_read_double (GIOChannel *channel,
gdouble *data,
gint count)
{
gchar *str;
gdouble *t;
guint32 tmp[2];
gint i;
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
guint32 swap;
#endif
t = (gdouble *) tmp;
for (i = 0; i < count; i++)
{
if (!wire_read_string (channel, &str, 1))
if (! wire_read_int8 (channel, (guint8 *) tmp, 8))
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;
@ -429,16 +441,42 @@ wire_write_double (GIOChannel *channel,
gdouble *data,
gint count)
{
gchar *t;
gchar buf[128];
gdouble *t;
guint32 tmp[2];
gint i;
#if (G_BYTE_ORDER == G_LITTLE_ENDIAN)
guint32 swap;
#endif
t = (gdouble *) tmp;
t = buf;
for (i = 0; i < count; i++)
{
g_snprintf (buf, sizeof (buf), "%0.50e", data[i]);
if (!wire_write_string (channel, &t, 1))
*t = data[i];
#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;
#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;