This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Add XDR support (only built #if cygwin, for now)


Charles Wilson wrote:
> The attached patch(es) add XDR support to newlib. eXternal Data

This update is in response to the previous discussion.  It is presented
as patch, to be applied "on top of" the original patch (but I didn't
include ripple to Makefile.in).  Changes:

include/rpc/types.h: guard quad_t/u_quad_t typedef with
___int64_t_defined, and check for mem_alloc/mem_free (pre)definition
before defining.

include/rpc/xdr.h: don't include stdio.h.  Guard functions related to
64bit integral types with ___int64_t_defined. Guard xdrstdio_create()
with _STDIO_H_.  (Did NOT guard the declaration of xdr_double() using
_DOUBLE_IS_32BIT; on those platforms we'll get a linker error rather
than a compile error if you try to use xdr_double).

xdr/README: New file.

xdr/xdr_float.c: refactor all vax-related code to xdr_float_vax.c. Guard
all code using the following structure:
   #if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BIG_ENDIAN)
   ... everything ...
   #elif defined(__vax__)
   #include "xdr_float_vax.c"
   #endif
for easier future extension. Don't include stdio.h.  Use
__IEEE_BIG_ENDIAN/__IEEE_LITTLE_ENDIAN instead of BYTEORDER and IEEEFP.
Don't implement xdr_double() if _DOUBLE_IS_32BIT.

xdr/xdr_float_vax.c: New file. Don't implement xdr_double() if
_DOUBLE_IS_32BIT.


xdr/Makefile.am: Only build xdr_stdio.c if stdio is supported (use
HAVE_STDIO_DIR AM_CONDITIONAL).  Add xdr_float_vax.c and README to
EXTRA_DIST.


xdr/xdr.c: Don't include stdio.h.  Do include errno.h.  Make sure to set
errno on out-of-memory.  Guard functions related to 64bit integral types
with ___int64_t_defined.

xdr/xdr_array.c: Don't include stdio.h.  Do include errno.h.  Make sure
to set errno on out-of-memory.

xdr/xdr_private.c: Don't include stdio.h.  In xdr_vwarnx, don't do
anything if the function pointer is null.

xdr/xdr_private.h: Don't include stdio.h.  Copy definition of __VALIST
from stdio.h.

xdr/xdr_rec.c: Don't include stdio.h.  Do include errno.h.  Make sure to
set errno on out-of-memory.

xdr/xdr_reference.c: Don't include stdio.h.  Do include errno.h.  Make
sure to set errno on out-of-memory.

xdr/xdr_sizeof.c: Use mem_free and mem_alloc instead of free() and malloc().

--
Chuck
diff -urN old/newlib/libc/include/rpc/types.h new/newlib/libc/include/rpc/types.h
--- old/newlib/libc/include/rpc/types.h	2010-02-26 18:12:05.326000000 -0500
+++ new/newlib/libc/include/rpc/types.h	2010-02-26 10:49:54.665200000 -0500
@@ -45,8 +45,10 @@
 extern "C" {
 #endif
 
+#if defined(___int64_t_defined)
 typedef u_int64_t u_quad_t;
 typedef int64_t   quad_t;
+#endif /* ___int64_t_defined */
 typedef int32_t   bool_t;
 typedef int32_t   enum_t;
 
@@ -63,8 +65,12 @@
 # define TRUE 1
 #endif
 
+#ifndef mem_alloc
 #define mem_alloc(bsize)        calloc(1, bsize)
+#endif
+#ifndef mem_free
 #define mem_free(ptr, bsize)    free(ptr)
+#endif
 
 #ifdef __cplusplus
 }
diff -urN old/newlib/libc/include/rpc/xdr.h new/newlib/libc/include/rpc/xdr.h
--- old/newlib/libc/include/rpc/xdr.h	2010-02-26 18:12:25.044400000 -0500
+++ new/newlib/libc/include/rpc/xdr.h	2010-02-26 10:48:44.340400000 -0500
@@ -41,7 +41,6 @@
 #ifndef _RPC_XDR_H
 #define _RPC_XDR_H
 #include <_ansi.h>
-#include <stdio.h>
 #include <rpc/types.h>
 
 #ifdef __cplusplus
@@ -299,9 +298,11 @@
 extern bool_t _EXFUN (xdr_int32_t, (XDR *, int32_t *));
 extern bool_t _EXFUN (xdr_uint32_t, (XDR *, uint32_t *));
 extern bool_t _EXFUN (xdr_u_int32_t, (XDR *, u_int32_t *));
+#if defined(___int64_t_defined)
 extern bool_t _EXFUN (xdr_int64_t, (XDR *, int64_t *));
 extern bool_t _EXFUN (xdr_uint64_t, (XDR *, uint64_t *));
 extern bool_t _EXFUN (xdr_u_int64_t, (XDR *, u_int64_t *));
+#endif /* ___int64_t_defined */
 extern bool_t _EXFUN (xdr_bool, (XDR *, bool_t *));
 extern bool_t _EXFUN (xdr_enum, (XDR *, enum_t *));
 extern bool_t _EXFUN (xdr_array, (XDR *, char **, u_int *, u_int, u_int, xdrproc_t));
@@ -319,10 +320,12 @@
 extern bool_t _EXFUN (xdr_reference, (XDR *, char **, u_int, xdrproc_t));
 extern bool_t _EXFUN (xdr_pointer, (XDR *, char **, u_int, xdrproc_t));
 extern bool_t _EXFUN (xdr_wrapstring, (XDR *, char **));
+#if defined(___int64_t_defined)
 extern bool_t _EXFUN (xdr_hyper, (XDR *, quad_t *));
 extern bool_t _EXFUN (xdr_u_hyper, (XDR *, u_quad_t *));
 extern bool_t _EXFUN (xdr_longlong_t, (XDR *, quad_t *));
 extern bool_t _EXFUN (xdr_u_longlong_t, (XDR *, u_quad_t *));
+#endif /* ___int64_t_defined */
 extern u_long _EXFUN (xdr_sizeof, (xdrproc_t, void *));
 
 /*
@@ -347,7 +350,9 @@
 extern void _EXFUN (xdrmem_create, (XDR *, char *, u_int, enum xdr_op));
 
 /* XDR using stdio library */
+#if defined(_STDIO_H_)
 extern void _EXFUN (xdrstdio_create, (XDR *, FILE *, enum xdr_op));
+#endif
 
 /* XDR pseudo records for tcp */
 extern void _EXFUN (xdrrec_create, (XDR *, u_int, u_int, void *,
diff -x Makefile.in -urN old/newlib/libc/xdr/Makefile.am new/newlib/libc/xdr/Makefile.am
--- old/newlib/libc/xdr/Makefile.am	2010-02-18 18:37:29.514600000 -0500
+++ new/newlib/libc/xdr/Makefile.am	2010-02-26 13:25:25.804700000 -0500
@@ -12,9 +12,14 @@
   xdr_mem.c \
   xdr_rec.c \
   xdr_reference.c \
-  xdr_sizeof.c \
+  xdr_sizeof.c
+
+STDIO_SOURCES = \
   xdr_stdio.c
 
+EXTRA_SOURCES = \
+  xdr_float_vax.c
+
 ## None of these functions are specified by EL/IX
 if ELIX_LEVEL_1
 ELIX_SOURCES =
@@ -28,12 +33,17 @@
 if ELIX_LEVEL_4
 ELIX_SOURCES =
 else
+if HAVE_STDIO_DIR
+ELIX_SOURCES = $(GENERAL_SOURCES) $(STDIO_SOURCES)
+else
 ELIX_SOURCES = $(GENERAL_SOURCES)
 endif
 endif
 endif
 endif
+endif
 
+EXTRA_DIST = README $(EXTRA_SOURCES)
 
 libxdr_la_LDFLAGS = -Xcompiler -nostdlib
 
diff -x Makefile.in -urN old/newlib/libc/xdr/README new/newlib/libc/xdr/README
--- old/newlib/libc/xdr/README	1969-12-31 19:00:00.000000000 -0500
+++ new/newlib/libc/xdr/README	2010-02-26 18:09:40.838800000 -0500
@@ -0,0 +1,192 @@
+INTRODUCTION
+======================
+This directory contains a port of the Sun RPC code (derived
+from the relicensed -- to 3-clause BSD -- implementation in
+Fedora 11's libtirpc package version 0.1.10-7). It has been
+adapted for newlib in the following ways:
+
+1) xdr_* functions for fixed-width integral types have been
+   added, such as xdr_int32_t() and similar. The implementation
+   of stream-specific x_putlong() and x_getlong() functions
+   has been modified to work properly whenever possible, even
+   if sizeof(long) > 32bits -- and to correctly report failure
+   when that is not possible.
+2) Use of DEFUN(), EXFUN(), and various other portability
+   macros.
+3) Uses of 64bit types, such as xdr_hyper, xdr_u_longlong_t,
+   and xdr_int64_t, as well as the xdr-specific typedefs
+   quad_t and u_quad_t, are guarded by ___int64_t_defined.
+4) Out-of-memory conditions are indicated by returning FALSE
+   and setting errno = ENOMEM, rather than by printing error
+   messages to stderr. (See #8, below).
+5) Only xdrstdio.c requires stdio support, and it is only
+   compiled if the target supports stdio (see stdio_dir in
+   configure.host)
+6) Uses a local implementation of ntohl/htonl, rather than
+   one provided elsewhere. No dependency on any networking
+   functions.
+7) Floating point support refactored. Currently supports
+   IEEE single and double precision, and VAX single and
+   double precision.
+   a) Those platforms which use float to represent double
+      do not provide xdr_double().
+8) Error reporting can be customized using a private hook.
+   This is described below.
+
+xdr is compiled and supported only for those platforms which
+set xdr_dir nonempty in configure.host. At present, the list
+of platforms which do this is:
+   cygwin
+
+
+PORTING
+======================
+To port XDR to a new newlib target, first enable building it
+by modifying configure.host.  Search for the 'case' statement
+where various *_dir= variables are set, and look for your
+target's entry (or add one if not present).  Set xdr_dir:
+
+  *-*-myplatform*)
+        xdr_dir=xdr
+	;;
+
+If your platform does not use IEEE754 standard formats for
+floating point values (floats, doubles) you may need to add
+a new xdr_float_*.c implementation, and modify the bottom of
+xdr_float.c:
+
+  ...
+  #elif defined(__vax__)
+  #include "xdr_float_vax.c"
+ +#else defined(__my_platform__)
+ +#include "xdr_float_my_platform.c"
+  #endif
+
+You may want to customize your platform's startup objects to set
+the error reporting callback for xdr (not likely, but see ERROR
+MESSAGES section). 
+
+You may also want to customize the memory allocation semantics
+employed by the xdr routines.  As stated in the xdr.h header:
+
+  XDR_DECODE may allocate space if the pointer [to the location
+  at which the decoded data is to be stored] is NULL. This
+  data can be freed with the XDR_FREE operation.
+
+The default implementation defines the following macros in
+rpc/types.h, used throughout xdr/ to deal with memory
+allocation:
+
+  #ifndef mem_alloc
+  #define mem_alloc(bsize)        calloc(1, bsize)
+  #endif
+  #ifndef mem_free
+  #define mem_free(ptr, bsize)    free(ptr)
+  #endif
+
+By arranging that these symbols are #defined to some other
+memory allocation functions, different memory semantics can be
+imposed. To disallow memory allocation entirely, use the
+following:
+
+  -D'mem_alloc(a)'=NULL -D'mem_free(a,b)'='do { ; } while(0)'
+
+In this case, any operations which would otherwise require
+memory to be allocated, will instead fail (return FALSE),
+and set errno=ENOMEM.
+
+
+ERROR MESSAGES
+======================
+This implementation of xdr provides a special hook, so that
+error messages generated by xdr may be captured by a user-
+defined facility. For certain error conditions, the internal
+printf-like function
+  xdr_warnx (fmt, ...)
+is called.  However, that function simply delegates to an
+internal function pointer to a callback function if set;
+otherwise, xdr_warnx does nothing.
+
+By setting this function pointer to a user-defined callback,
+the user can enable these messages to go to a syslog, stderr,
+or some other facility.  The function should match the
+following typedef (see xdr_private.h):
+
+  typedef void (* xdr_vprintf_t) (const char *, va_list);
+
+The desired callback can be registered by calling:
+
+  xdr_vprintf_t xdr_set_vprintf (xdr_vprintf_t fnptr);
+
+The return value is the "old" function pointer, which may
+be NULL.
+
+However, neither the typedef or the registration function
+are declared in the public headers. Clients wishing to use
+them must either declare the necessary symbols manually,
+or #include "xdr_private.h". More on this point, below.
+
+For instance:
+  #include <stdarg.h>
+  #include <stdio.h>
+  typedef void (* xdr_vprintf_t) (const char *, va_list);
+  xdr_vprintf_t xdr_set_vprintf (xdr_vprintf_t fnptr);
+
+  void my_vwarnx (const char * fmt, va_list ap)
+  {
+    (void) fprintf (stderr, fmt, ap);
+  }
+  
+  main()
+  {
+    (void) xdr_set_vprintf (&my_vwarnx);
+    ...
+  }
+
+Will cause xdr-generated error messages to go to stderr.
+
+It is not expected that end-user applications will make use
+of this facility.  Rather, it is expected that IF certain
+*platforms* desire that these error messages be recorded,
+rather expecting client apps print error messages as
+necessary, then those platforms will, in their startup
+objects or static initialization, direct these messages to
+a logging facility, strace debug facility, etc.
+
+Therefore, the platform startup code, if part of newlib, can
+#include "xdr_private.h", or simply copy the two declarations
+from that file.
+
+However, most newlib targets will probably be satisfied with
+the default (silent) behavior. Note that the original Sun RPC,
+as well as the glibc implementation, print these error messages
+to stderr.  Cygwin, for greater similarity to glibc, registers
+an error message handler similar to the example above, within
+its startup code.
+
+(*) Client apps should already check for FALSE return values;
+    in this case they would then check errno and act appropriately.
+
+
+LICENSING AND PEDIGREE
+======================
+For years, the Sun RPC code, and the XDR implementation, was in
+legal license limbo
+  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=181493
+as its license terms, while open, were of debatable compatibility
+with the GPL. In February of 2009, that changed:
+  http://blogs.sun.com/webmink/entry/old_code_and_old_licenses
+  http://lwn.net/Articles/319648/
+
+As documented in the libtirpc rpm.spec file from Fedora 11:
+* Tue May 19 2009 Tom "spot" Callaway <xxxx@redhat.com> 0.1.10-7
+  - Replace the Sun RPC license with the BSD license, with the
+    explicit permission of Sun Microsystems
+
+So, in the XDR implementation from Fedora 11's libtirpc package,
+after the modification above by Tom Callaway, each file carries
+the 3-clause BSD license, and not the so-called "SunRPC" license.
+It is from this version that the newlib implementation here was
+derived, with the modifications described in the introduction,
+above.
+
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr.c new/newlib/libc/xdr/xdr.c
--- old/newlib/libc/xdr/xdr.c	2010-02-18 18:37:29.572600000 -0500
+++ new/newlib/libc/xdr/xdr.c	2010-02-26 12:56:51.472400000 -0500
@@ -36,9 +36,9 @@
  * xdr.
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
@@ -688,6 +688,7 @@
       if (sp == NULL)
         {
           xdr_warnx ("xdr_bytes: out of memory");
+          errno = ENOMEM;
           return FALSE;
         }
       /* FALLTHROUGH */
@@ -838,6 +839,7 @@
       if (sp == NULL)
         {
           xdr_warnx ("xdr_string: out of memory");
+          errno = ENOMEM;
           return FALSE;
         }
       sp[size] = 0;
@@ -866,6 +868,8 @@
   return xdr_string (xdrs, cpp, LASTUNSIGNED);
 }
 
+
+#if defined(___int64_t_defined)
 /*
  * NOTE: xdr_hyper(), xdr_u_hyper(), xdr_longlong_t(), and xdr_u_longlong_t()
  * are in the "non-portable" section because they require that a `long long'
@@ -1032,3 +1036,6 @@
    */
   return (xdr_uint64_t (xdrs, (uint64_t *) ullp));
 }
+
+#endif /* ___int64_t_defined */
+
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_array.c new/newlib/libc/xdr/xdr_array.c
--- old/newlib/libc/xdr/xdr_array.c	2010-02-18 18:37:29.588600000 -0500
+++ new/newlib/libc/xdr/xdr_array.c	2010-02-26 12:57:14.217200000 -0500
@@ -37,9 +37,9 @@
  */
 
 #include <limits.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
@@ -94,6 +94,7 @@
         if (target == NULL)
           {
             xdr_warnx ("xdr_array: out of memory");
+            errno = ENOMEM;
             return FALSE;
           }
         memset (target, 0, nodesize);
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_float.c new/newlib/libc/xdr/xdr_float.c
--- old/newlib/libc/xdr/xdr_float.c	2010-02-18 18:37:29.608600000 -0500
+++ new/newlib/libc/xdr/xdr_float.c	2010-02-26 16:52:31.804900000 -0500
@@ -38,8 +38,6 @@
  */
 
 #include <sys/types.h>
-#include <stdio.h>
-
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 
@@ -48,113 +46,31 @@
 /*
  * NB: Not portable.
  * This routine works on machines with IEEE754 FP and Vaxen.
- * Assume that xdr_private.h arranges things so that IEEEFP
- * is #defined, or __vax__. Otherwise, expect errors.
+ * Assume that xdr_private.h arranges things so that one of
+ *   1) __IEEE_LITTLE_ENDIAN
+ *   2) __IEEE_BIG_ENDIAN
+ *   3) __vax__
+ * is #defined.  Otherwise, expect errors.
  */
+#ifndef XDR_FLOAT_C
+#define XDR_FLOAT_C
+#endif
 
-#if defined(__vax__)
-
-/* What IEEE single precision floating point looks like on a Vax */
-struct ieee_single
-{
-  unsigned int mantissa:23;
-  unsigned int exp:8;
-  unsigned int sign:1;
-};
-
-/* Vax single precision floating point */
-struct vax_single
-{
-  unsigned int mantissa1:7;
-  unsigned int exp:8;
-  unsigned int sign:1;
-  unsigned int mantissa2:16;
-};
-
-# define VAX_SNG_BIAS   0x81
-# define IEEE_SNG_BIAS  0x7f
-
-/* *INDENT-OFF*
-*/
-static struct sgl_limits
-{
-  struct vax_single s;
-  struct ieee_single ieee;
-} sgl_limits[2] =
-{
-  {
-    {0x7f, 0xff, 0x0, 0xffff},   /* Max Vax */
-    {0x0, 0xff, 0x0}             /* Max IEEE */
-  },
-  {
-    {0x0, 0x0, 0x0, 0x0},        /* Min Vax */
-    {0x0, 0x0, 0x0}              /* Min IEEE */
-  }
-};
-/* *INDENT-ON*
-*/
-#endif /* __vax__ */
+#if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BIG_ENDIAN)
 
 bool_t
 _DEFUN (xdr_float, (xdrs, fp),
        XDR * xdrs _AND
        float *fp)
 {
-#ifndef IEEEFP
-  struct ieee_single is;
-  struct vax_single vs, *vsp;
-  struct sgl_limits *lim;
-  int i;
-#endif /* not IEEEFP */
   switch (xdrs->x_op)
     {
 
     case XDR_ENCODE:
-#ifdef IEEEFP
       return (XDR_PUTINT32 (xdrs, (int32_t *) fp));
-#else /* not IEEEFP */
-      vs = *((struct vax_single *) fp);
-      for (i = 0, lim = sgl_limits;
-           i < sizeof (sgl_limits) / sizeof (struct sgl_limits); i++, lim++)
-        {
-          if ((vs.mantissa2 == lim->s.mantissa2) &&
-              (vs.exp == lim->s.exp) && (vs.mantissa1 == lim->s.mantissa1))
-            {
-              is = lim->ieee;
-              goto shipit;
-            }
-        }
-      is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
-      is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
-    shipit:
-      is.sign = vs.sign;
-      return (XDR_PUTINT32 (xdrs, (int32_t *) & is));
-#endif /* not IEEEFP */
 
     case XDR_DECODE:
-#ifdef IEEEFP
       return (XDR_GETINT32 (xdrs, (int32_t *) fp));
-#else /* not IEEEFP */
-      vsp = (struct vax_single *) fp;
-      if (!XDR_GETINT32 (xdrs, (int32_t *) & is))
-        return FALSE;
-      for (i = 0, lim = sgl_limits;
-           i < sizeof (sgl_limits) / sizeof (struct sgl_limits); i++, lim++)
-        {
-          if ((is.exp == lim->ieee.exp) &&
-              (is.mantissa == lim->ieee.mantissa))
-            {
-              *vsp = lim->s;
-              goto doneit;
-            }
-        }
-      vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
-      vsp->mantissa2 = is.mantissa;
-      vsp->mantissa1 = (is.mantissa >> 16);
-    doneit:
-      vsp->sign = is.sign;
-      return TRUE;
-#endif /* not IEEEFP */
 
     case XDR_FREE:
       return TRUE;
@@ -162,153 +78,56 @@
   return FALSE;
 }
 
-#if defined(__vax__)
-/* What IEEE double precision floating point looks like on a Vax */
-struct ieee_double
-{
-  unsigned int mantissa1:20;
-  unsigned int exp:11;
-  unsigned int sign:1;
-  unsigned int mantissa2:32;
-};
-
-/* Vax double precision floating point */
-struct vax_double
-{
-  unsigned int mantissa1:7;
-  unsigned int exp:8;
-  unsigned int sign:1;
-  unsigned int mantissa2:16;
-  unsigned int mantissa3:16;
-  unsigned int mantissa4:16;
-};
-
-# define VAX_DBL_BIAS   0x81
-# define IEEE_DBL_BIAS  0x3ff
-# define MASK(nbits)    ((1 << nbits) - 1)
-
-/* *INDENT-OFF*
-*/
-static struct dbl_limits
-{
-  struct vax_double d;
-  struct ieee_double ieee;
-} dbl_limits[2] =
-{
-  {
-    {0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff},  /* Max Vax */
-    {0x0, 0x7ff, 0x0, 0x0}                      /* Max IEEE */
-  },
-  {
-    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0},             /* Min Vax */
-    {0x0, 0x0, 0x0, 0x0}                        /* Min IEEE */
-  }
-};
-/* *INDENT-ON*
-*/
-#endif /* __vax__ */
-
+#if !defined(_DOUBLE_IS_32BITS)
 bool_t
 _DEFUN (xdr_double, (xdrs, dp),
         XDR * xdrs _AND
 	double *dp)
 {
-#ifdef IEEEFP
   int32_t *i32p;
   bool_t rv;
-#else /* not IEEEFP */
-  int32_t *lp;
-  struct ieee_double id;
-  struct vax_double vd;
-  struct dbl_limits *lim;
-  int i;
-#endif /* not IEEEFP */
 
   switch (xdrs->x_op)
     {
 
     case XDR_ENCODE:
-#ifdef IEEEFP
       i32p = (int32_t *) (void *) dp;
-# if BYTE_ORDER == BIG_ENDIAN
+#if defined(__IEEE_BIG_ENDIAN)
       rv = XDR_PUTINT32 (xdrs, i32p);
       if (!rv)
         return (rv);
       rv = XDR_PUTINT32 (xdrs, i32p + 1);
-# else /* not BYTE_ORDER == BIG_ENDIAN */
+#else /* must be __IEEE_LITTLE_ENDIAN */
       rv = XDR_PUTINT32 (xdrs, i32p + 1);
       if (!rv)
         return (rv);
       rv = XDR_PUTINT32 (xdrs, i32p);
-# endif /* not BYTE_ORDER == BIG_ENDIAN */
+#endif /* __IEEE_LITTLE_ENDIAN */
       return (rv);
-#else /* not IEEEFP */
-      vd = *((struct vax_double *) dp);
-      for (i = 0, lim = dbl_limits;
-           i < sizeof (dbl_limits) / sizeof (struct dbl_limits); i++, lim++)
-        {
-          if ((vd.mantissa4 == lim->d.mantissa4) &&
-              (vd.mantissa3 == lim->d.mantissa3) &&
-              (vd.mantissa2 == lim->d.mantissa2) &&
-              (vd.mantissa1 == lim->d.mantissa1) && (vd.exp == lim->d.exp))
-            {
-              id = lim->ieee;
-              goto shipit;
-            }
-        }
-      id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
-      id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
-      id.mantissa2 = ((vd.mantissa2 & MASK (3)) << 29) |
-        (vd.mantissa3 << 13) | ((vd.mantissa4 >> 3) & MASK (13));
-    shipit:
-      id.sign = vd.sign;
-      lp = (int32_t *) & id;
-      return (XDR_PUTINT32 (xdrs, lp++) && XDR_PUTINT32 (xdrs, lp));
-#endif /* not IEEEFP */
 
     case XDR_DECODE:
-#ifdef IEEEFP
       i32p = (int32_t *) (void *) dp;
-# if BYTE_ORDER == BIG_ENDIAN
+#if defined(__IEEE_BIG_ENDIAN)
       rv = XDR_GETINT32 (xdrs, i32p);
       if (!rv)
         return (rv);
       rv = XDR_GETINT32 (xdrs, i32p + 1);
-# else /* not BYTE_ORDER == BIG_ENDIAN */
+#else /* must be __IEEE_LITTLE_ENDIAN */
       rv = XDR_GETINT32 (xdrs, i32p + 1);
       if (!rv)
         return (rv);
       rv = XDR_GETINT32 (xdrs, i32p);
-# endif /* not BYTE_ORDER == BIG_ENDIAN */
+#endif /* __IEEE_LITTLE_ENDIAN */
       return (rv);
-#else /* not IEEEFP */
-      lp = (int32_t *) & id;
-      if (!XDR_GETINT32 (xdrs, lp++) || !XDR_GETINT32 (xdrs, lp))
-        return FALSE;
-      for (i = 0, lim = dbl_limits;
-           i < sizeof (dbl_limits) / sizeof (struct dbl_limits); i++, lim++)
-        {
-          if ((id.mantissa2 == lim->ieee.mantissa2) &&
-              (id.mantissa1 == lim->ieee.mantissa1) &&
-              (id.exp == lim->ieee.exp))
-            {
-              vd = lim->d;
-              goto doneit;
-            }
-        }
-      vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
-      vd.mantissa1 = (id.mantissa1 >> 13);
-      vd.mantissa2 = ((id.mantissa1 & MASK (13)) << 3) | (id.mantissa2 >> 29);
-      vd.mantissa3 = (id.mantissa2 >> 13);
-      vd.mantissa4 = (id.mantissa2 << 3);
-    doneit:
-      vd.sign = id.sign;
-      *dp = *((double *) &vd);
-      return TRUE;
-#endif /* not IEEEFP */
 
     case XDR_FREE:
       return TRUE;
     }
   return FALSE;
 }
+#endif /* !_DOUBLE_IS_32BITS */
+
+#elif defined(__vax__)
+#include "xdr_float_vax.c"
+#endif
+
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_float_vax.c new/newlib/libc/xdr/xdr_float_vax.c
--- old/newlib/libc/xdr/xdr_float_vax.c	1969-12-31 19:00:00.000000000 -0500
+++ new/newlib/libc/xdr/xdr_float_vax.c	2010-02-26 16:52:57.326500000 -0500
@@ -0,0 +1,254 @@
+
+/*
+ * Copyright (c) 2009, Sun Microsystems, Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * - Neither the name of Sun Microsystems, Inc. nor the names of its
+ *   contributors may be used to endorse or promote products derived
+ *   from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * xdr_float_vax.c, XDR floating point routines for vax.
+ *
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ *
+ * These are the "floating point" xdr routines used to (de)serialize
+ * most common data items.  See xdr.h for more info on the interface to
+ * xdr.
+ */
+#ifndef XDR_FLOAT_C
+#error "Must be included from xdr_float.c"
+#endif
+
+/* What IEEE single precision floating point looks like on a Vax */
+struct ieee_single
+{
+  unsigned int mantissa:23;
+  unsigned int exp:8;
+  unsigned int sign:1;
+};
+
+/* Vax single precision floating point */
+struct vax_single
+{
+  unsigned int mantissa1:7;
+  unsigned int exp:8;
+  unsigned int sign:1;
+  unsigned int mantissa2:16;
+};
+
+# define VAX_SNG_BIAS   0x81
+# define IEEE_SNG_BIAS  0x7f
+
+/* *INDENT-OFF*
+*/
+static struct sgl_limits
+{
+  struct vax_single s;
+  struct ieee_single ieee;
+} sgl_limits[2] =
+{
+  {
+    {0x7f, 0xff, 0x0, 0xffff},   /* Max Vax */
+    {0x0, 0xff, 0x0}             /* Max IEEE */
+  },
+  {
+    {0x0, 0x0, 0x0, 0x0},        /* Min Vax */
+    {0x0, 0x0, 0x0}              /* Min IEEE */
+  }
+};
+/* *INDENT-ON*
+*/
+
+bool_t
+_DEFUN (xdr_float, (xdrs, fp),
+       XDR * xdrs _AND
+       float *fp)
+{
+  struct ieee_single is;
+  struct vax_single vs, *vsp;
+  struct sgl_limits *lim;
+  int i;
+  switch (xdrs->x_op)
+    {
+
+    case XDR_ENCODE:
+      vs = *((struct vax_single *) fp);
+      for (i = 0, lim = sgl_limits;
+           i < sizeof (sgl_limits) / sizeof (struct sgl_limits); i++, lim++)
+        {
+          if ((vs.mantissa2 == lim->s.mantissa2) &&
+              (vs.exp == lim->s.exp) && (vs.mantissa1 == lim->s.mantissa1))
+            {
+              is = lim->ieee;
+              goto shipit;
+            }
+        }
+      is.exp = vs.exp - VAX_SNG_BIAS + IEEE_SNG_BIAS;
+      is.mantissa = (vs.mantissa1 << 16) | vs.mantissa2;
+    shipit:
+      is.sign = vs.sign;
+      return (XDR_PUTINT32 (xdrs, (int32_t *) & is));
+
+    case XDR_DECODE:
+      vsp = (struct vax_single *) fp;
+      if (!XDR_GETINT32 (xdrs, (int32_t *) & is))
+        return FALSE;
+      for (i = 0, lim = sgl_limits;
+           i < sizeof (sgl_limits) / sizeof (struct sgl_limits); i++, lim++)
+        {
+          if ((is.exp == lim->ieee.exp) &&
+              (is.mantissa == lim->ieee.mantissa))
+            {
+              *vsp = lim->s;
+              goto doneit;
+            }
+        }
+      vsp->exp = is.exp - IEEE_SNG_BIAS + VAX_SNG_BIAS;
+      vsp->mantissa2 = is.mantissa;
+      vsp->mantissa1 = (is.mantissa >> 16);
+    doneit:
+      vsp->sign = is.sign;
+      return TRUE;
+
+    case XDR_FREE:
+      return TRUE;
+    }
+  return FALSE;
+}
+
+#if !defined(_DOUBLE_IS_32BITS)
+
+/* What IEEE double precision floating point looks like on a Vax */
+struct ieee_double
+{
+  unsigned int mantissa1:20;
+  unsigned int exp:11;
+  unsigned int sign:1;
+  unsigned int mantissa2:32;
+};
+
+/* Vax double precision floating point */
+struct vax_double
+{
+  unsigned int mantissa1:7;
+  unsigned int exp:8;
+  unsigned int sign:1;
+  unsigned int mantissa2:16;
+  unsigned int mantissa3:16;
+  unsigned int mantissa4:16;
+};
+
+# define VAX_DBL_BIAS   0x81
+# define IEEE_DBL_BIAS  0x3ff
+# define MASK(nbits)    ((1 << nbits) - 1)
+
+/* *INDENT-OFF*
+*/
+static struct dbl_limits
+{
+  struct vax_double d;
+  struct ieee_double ieee;
+} dbl_limits[2] =
+{
+  {
+    {0x7f, 0xff, 0x0, 0xffff, 0xffff, 0xffff},  /* Max Vax */
+    {0x0, 0x7ff, 0x0, 0x0}                      /* Max IEEE */
+  },
+  {
+    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0},             /* Min Vax */
+    {0x0, 0x0, 0x0, 0x0}                        /* Min IEEE */
+  }
+};
+/* *INDENT-ON*
+*/
+
+bool_t
+_DEFUN (xdr_double, (xdrs, dp),
+        XDR * xdrs _AND
+	double *dp)
+{
+  int32_t *lp;
+  struct ieee_double id;
+  struct vax_double vd;
+  struct dbl_limits *lim;
+  int i;
+
+  switch (xdrs->x_op)
+    {
+
+    case XDR_ENCODE:
+      vd = *((struct vax_double *) dp);
+      for (i = 0, lim = dbl_limits;
+           i < sizeof (dbl_limits) / sizeof (struct dbl_limits); i++, lim++)
+        {
+          if ((vd.mantissa4 == lim->d.mantissa4) &&
+              (vd.mantissa3 == lim->d.mantissa3) &&
+              (vd.mantissa2 == lim->d.mantissa2) &&
+              (vd.mantissa1 == lim->d.mantissa1) && (vd.exp == lim->d.exp))
+            {
+              id = lim->ieee;
+              goto shipit;
+            }
+        }
+      id.exp = vd.exp - VAX_DBL_BIAS + IEEE_DBL_BIAS;
+      id.mantissa1 = (vd.mantissa1 << 13) | (vd.mantissa2 >> 3);
+      id.mantissa2 = ((vd.mantissa2 & MASK (3)) << 29) |
+        (vd.mantissa3 << 13) | ((vd.mantissa4 >> 3) & MASK (13));
+    shipit:
+      id.sign = vd.sign;
+      lp = (int32_t *) & id;
+      return (XDR_PUTINT32 (xdrs, lp++) && XDR_PUTINT32 (xdrs, lp));
+
+    case XDR_DECODE:
+      lp = (int32_t *) & id;
+      if (!XDR_GETINT32 (xdrs, lp++) || !XDR_GETINT32 (xdrs, lp))
+        return FALSE;
+      for (i = 0, lim = dbl_limits;
+           i < sizeof (dbl_limits) / sizeof (struct dbl_limits); i++, lim++)
+        {
+          if ((id.mantissa2 == lim->ieee.mantissa2) &&
+              (id.mantissa1 == lim->ieee.mantissa1) &&
+              (id.exp == lim->ieee.exp))
+            {
+              vd = lim->d;
+              goto doneit;
+            }
+        }
+      vd.exp = id.exp - IEEE_DBL_BIAS + VAX_DBL_BIAS;
+      vd.mantissa1 = (id.mantissa1 >> 13);
+      vd.mantissa2 = ((id.mantissa1 & MASK (13)) << 3) | (id.mantissa2 >> 29);
+      vd.mantissa3 = (id.mantissa2 >> 13);
+      vd.mantissa4 = (id.mantissa2 << 3);
+    doneit:
+      vd.sign = id.sign;
+      *dp = *((double *) &vd);
+      return TRUE;
+
+    case XDR_FREE:
+      return TRUE;
+    }
+  return FALSE;
+}
+#endif /* !_DOUBLE_IS_32BITS */
+
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_private.c new/newlib/libc/xdr/xdr_private.c
--- old/newlib/libc/xdr/xdr_private.c	2010-02-18 18:37:29.639600000 -0500
+++ new/newlib/libc/xdr/xdr_private.c	2010-02-26 10:09:59.720200000 -0500
@@ -21,8 +21,6 @@
  * OTHER DEALINGS IN THE SOFTWARE.
  */
 #include <stdarg.h>
-#include <stdio.h>
-
 #include "xdr_private.h"
 
 static xdr_vprintf_t xdr_vprintf = NULL;
@@ -46,9 +44,7 @@
       (*xdr_vprintf)(format, ap);
       return;
     }
-  if (format)
-    vfprintf (stderr, format, ap);
-  putc ('\n', stderr);
+  /* otherwise, do nothing */
 }
 
 void
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_private.h new/newlib/libc/xdr/xdr_private.h
--- old/newlib/libc/xdr/xdr_private.h	2010-02-18 18:37:29.650600000 -0500
+++ new/newlib/libc/xdr/xdr_private.h	2010-02-26 11:21:56.226400000 -0500
@@ -27,14 +27,21 @@
 #include <stdarg.h>
 #include <sys/param.h>
 
+/* avoid including stdio header here */
+#ifndef __VALIST
+#ifdef __GNUC__
+#define __VALIST __gnuc_va_list
+#else
+#define __VALIST char*
+#endif
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 typedef void _EXFNPTR (xdr_vprintf_t, (const char *, va_list));
 
-/* FIXME: these error reporting functions should really be
- *        eliminated, in favor of an errno-based schema. */
 xdr_vprintf_t _EXFUN (xdr_set_vprintf, (xdr_vprintf_t));
 
 void _EXFUN (xdr_vwarnx, (const char *, __VALIST)
@@ -45,7 +52,6 @@
 
 /* endian issues */
 #include <machine/endian.h>
-#define IEEEFP
 
 /* byteswap and ntohl stuff; platform may provide optimzed version
  * of this, but we don't have access to that here.*/
@@ -57,7 +63,7 @@
   u_char *s = (u_char *)&x;
   return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
 #else
-# error Unsupported BYTEORDER
+# error Unsupported endian type
 #endif
 }
 #define xdr_htonl(x) xdr_ntohl(x)
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_rec.c new/newlib/libc/xdr/xdr_rec.c
--- old/newlib/libc/xdr/xdr_rec.c	2010-02-18 18:37:29.684600000 -0500
+++ new/newlib/libc/xdr/xdr_rec.c	2010-02-26 12:58:01.391600000 -0500
@@ -46,11 +46,11 @@
 
 #include <stddef.h>
 #include <sys/types.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
@@ -193,6 +193,7 @@
        *  This is bad.  Should rework xdrrec_create to
        *  return a handle, and in this case return NULL
        */
+      errno = ENOMEM;
       return;
     }
 
@@ -204,6 +205,7 @@
     {
       xdr_warnx ("xdrrec_create: out of memory");
       mem_free (rstrm, sizeof (RECSTREAM));
+      errno = ENOMEM;
       return;
     }
   for (rstrm->out_base = rstrm->out_buffer;
@@ -218,6 +220,7 @@
       xdr_warnx ("xdrrec_create: out of memory");
       mem_free (rstrm->out_buffer, sendsize + BYTES_PER_XDR_UNIT);
       mem_free (rstrm, sizeof (RECSTREAM));
+      errno = ENOMEM;
       return;
     }
   for (rstrm->in_base = rstrm->in_buffer;
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_reference.c new/newlib/libc/xdr/xdr_reference.c
--- old/newlib/libc/xdr/xdr_reference.c	2010-02-18 18:37:29.710600000 -0500
+++ new/newlib/libc/xdr/xdr_reference.c	2010-02-26 12:58:26.585600000 -0500
@@ -35,9 +35,9 @@
  * "pointers".  See xdr.h for more info on the interface to xdr.
  */
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
@@ -76,6 +76,7 @@
         if (loc == NULL)
           {
             xdr_warnx ("xdr_reference: out of memory");
+            errno = ENOMEM;
             return FALSE;
           }
         memset (loc, 0, size);
diff -x Makefile.in -urN old/newlib/libc/xdr/xdr_sizeof.c new/newlib/libc/xdr/xdr_sizeof.c
--- old/newlib/libc/xdr/xdr_sizeof.c	2010-02-18 18:37:29.722600000 -0500
+++ new/newlib/libc/xdr/xdr_sizeof.c	2010-02-26 10:52:45.204400000 -0500
@@ -98,8 +98,8 @@
     {
       /* Free the earlier space and allocate new area */
       if (xdrs->x_private)
-        free (xdrs->x_private);
-      if ((xdrs->x_private = (caddr_t) malloc (len)) == NULL)
+        mem_free (xdrs->x_private, sizeof (xdrs->x_private));
+      if ((xdrs->x_private = (caddr_t) mem_alloc (len)) == NULL)
         {
           xdrs->x_base = 0;
           return NULL;
@@ -125,7 +125,7 @@
   xdrs->x_base = 0;
   if (xdrs->x_private)
     {
-      free (xdrs->x_private);
+      mem_free (xdrs->x_private, sizeof (xdrs->x_private));
       xdrs->x_private = NULL;
     }
   return;
@@ -175,7 +175,7 @@
 
   stat = func (&x, data);
   if (x.x_private)
-    free (x.x_private);
+    mem_free (x.x_private, sizeof (x.x_private));
   return (stat == TRUE ? x.x_handy : 0);
 }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]