This is the mail archive of the cygwin-patches mailing list for the Cygwin 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]

Add xdr support


The attached patch(es) add XDR support to cygwin. eXternal Data
Representation (XDR) is a standard data encoding mechanism (RFC 1832,
4506) most frequently seen in the implementation of the SunRPC protocol.
 XDR allows binary data structures to be encoded in an architecture
independent manner for communication between heterogeneous computer systems.

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 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 <tcallawa@redhat.com> 0.1.10-7
- Replace the Sun RPC license with the BSD license, with the explicit
  permission of Sun Microsystems

So, the attached implementations were taken from Fedora 11's libtirpc
package, after the modifications by Tom Callaway. Thus, each file
carries the (3-clause) BSD license, and not the old "SunRPC" license.

Last year, I worked on it some to get it to compile cleanly under cygwin
(1.5,1.7), mingw, msvc80, and linux (32bit, 64bit), while being careful
to maintain the BSD license.  I also wrote a whole slew of tests to
guarantee correct operation and identical representation on all of these
platforms (these carry the MIT/X license). I won't say it has full test
coverage, but it's awfully close.  Anyway, I finally got around to
uploading that package to googlecode this week:

http://code.google.com/p/bsd-xdr/

The attached patch is basically a fork of that bsd-xdr core code. I
removed all the #ifdefs that made msvc80 and mingw happy, as they aren't
needed in newlib and would complicate any attempt to expand the use of
the new code to other newlib targets other than cygwin.  I reworked both
the headers and implementation files to follow newlib-isms like using
_EXFUN() and _DEFUN macros and such.  I did not, however, attempt to add
'chew'-able documentation to the various files.

This fork, rather than relying on <byteorder.h> (which isn't available
inside newlib), uses its own private ntohl/htonl implementations. Also,
while most xdr implementations print errors to stderr using the
BSD-flavor warnx() function, this version allows the caller to configure
an error reporting function (more below).

I did not include the test suite; it would take quite a bit of effort to
translate the bsd-xdr/test/ code into cygwin's testsuite framework --
newlib/libc/ itself doesn't appear to have a test suite AFAICT.  I'm not
sure it's worth the effort, actually -- none of the BSD's or glibc or
linux's include test code for XDR, which is why I had to code tests from
the ground up for my bsd-xdr package.  I did link my test suite against
this implementation inside a newly-built cygwin1.dll, and it passed with
flying colors.

Most of the code goes in newlib, but is only built for $host cygwin.
However, I post it here first for review and comments; rev 2 will go to
the newlib list.  The cygwin components are basically just adding the
new exports, and providing a callback function for the error reporting
framework in the xdr implementation, that uses (in effect) debug_printf().

Note that the newlib patches depend on the ones I posted earlier today
to the newlib list, concerning compatibility with the src/libtool.m4 and
src/ltmain.sh files which were recently updated, as well as
compatibility with ac-2.64 and am-1.11.1:
http://sourceware.org/ml/newlib/2010/msg00114.html

So, apply those two patches first, then these three.  Yes, three: (1)
newlib 'primary' changes, (2) newlib 're-autotool' changes, and (3)
cygwin changes.  I had to compress the first two, because they are too
large to include as inline attachments.

Obviously, the newlib contributions can retain their BSD (or MIT/X, for
two internal files) license, like all the other such files in newlib.
The cygwin components are GPL, and fall under my existing copyright
assignment to Red Hat.

Patch#1: newlib primary
==========================
2010-02-12  Charles Wilson  <...>

        Add eXtensible Data Record (XDR) support for cygwin
	* configure.host: Build libc/xdr only on cygwin.
	* Makefile.am: Install xdr headers.
	* libc/configure.in: Support new libc/xdr subdirectory.
	* libc/Makefile.am: Support new libc/xdr subdirectory.
	* libc/include/rpc/types.h: New.
	* libc/include/rpc/xdr.h: New.
	* libc/xdr/Makefile.am: New.
	* libc/xdr/dummy.c: New.
	* libc/xdr/xdr.c: New.
	* libc/xdr/xdr_array.c: New.
	* libc/xdr/xdr_float.c: New.
	* libc/xdr/xdr_mem.c: New.
	* libc/xdr/xdr_private.c: New.
	* libc/xdr/xdr_private.h: New.
	* libc/xdr/xdr_rec.c: New.
	* libc/xdr/xdr_reference.c: New.
	* libc/xdr/xdr_sizeof.c: New.
	* libc/xdr/xdr_stdio.c: New.

Patch#2: newlib auto
===========================
2010-02-12  Charles Wilson  <...>

	Regenerate using ac-2.64 and am-1.11.1
	* Makefile.in: Regenerate.
	* libc/configure: Regenerate.
	* libc/Makefile.in: Regenerate.
	* libc/argz/Makefile.in: Regenerate.
	* libc/ctype/Makefile.in: Regenerate.
	* libc/errno/Makefile.in: Regenerate.
	* libc/iconv/ccs/binary/Makefile.in: Regenerate.
	* libc/iconv/ccs/Makefile.in: Regenerate.
	* libc/iconv/ces/Makefile.in: Regenerate.
	* libc/iconv/lib/Makefile.in: Regenerate.
	* libc/iconv/Makefile.in: Regenerate.
	* libc/locale/Makefile.in: Regenerate.
	* libc/misc/Makefile.in: Regenerate.
	* libc/posix/Makefile.in: Regenerate.
	* libc/reent/Makefile.in: Regenerate.
	* libc/search/Makefile.in: Regenerate.
	* libc/signal/Makefile.in: Regenerate.
	* libc/stdio/Makefile.in: Regenerate.
	* libc/stdio64/Makefile.in: Regenerate.
	* libc/stdlib/Makefile.in: Regenerate.
	* libc/string/Makefile.in: Regenerate.
	* libc/syscalls/Makefile.in: Regenerate.
	* libc/time/Makefile.in: Regenerate.
	* libc/unix/Makefile.in: Regenerate.
	* libc/xdr/Makefile.in: Regenerate.

Patch #3: cygwin
=========================
2010-02-12  Charles Wilson  <...>

	Add XDR support.
	* cygwin.din: Export xdr functions.
	* include/cygwin/version.h: Bump version.
	* cygxdr.cc: New.
	* cygxdr.h: New.
	* init.cc: Ensure that xdr functions use an approximation
	to debug_print for warnings, rather than stderr.
	* Makefile.in: Add cygxdr.

--
Chuck
diff -u src-newlib-p/winsup/cygwin/cygwin.din src/winsup/cygwin/cygwin.din
--- src-newlib-p/winsup/cygwin/cygwin.din	2010-02-12 01:17:47.586400000 -0500
+++ src/winsup/cygwin/cygwin.din	2010-02-12 19:24:06.883800000 -0500
@@ -1815,6 +1815,53 @@
 writev SIGFE
 _writev = writev SIGFE
 wscanf SIGFE
+xdr_array SIGFE
+xdr_bool SIGFE
+xdr_bytes SIGFE
+xdr_char SIGFE
+xdr_double SIGFE
+xdr_enum SIGFE
+xdr_float SIGFE
+xdr_free SIGFE
+xdr_hyper SIGFE
+xdr_int SIGFE
+xdr_int16_t SIGFE
+xdr_int32_t SIGFE
+xdr_int64_t SIGFE
+xdr_int8_t SIGFE
+xdr_long SIGFE
+xdr_longlong_t SIGFE
+xdr_netobj SIGFE
+xdr_opaque SIGFE
+xdr_pointer SIGFE
+xdr_reference SIGFE
+xdr_short SIGFE
+xdr_sizeof SIGFE
+xdr_string SIGFE
+xdr_u_char SIGFE
+xdr_u_hyper SIGFE
+xdr_u_int SIGFE
+xdr_u_int16_t SIGFE
+xdr_u_int32_t SIGFE
+xdr_u_int64_t SIGFE
+xdr_u_int8_t SIGFE
+xdr_u_long SIGFE
+xdr_u_longlong_t SIGFE
+xdr_u_short SIGFE
+xdr_uint16_t SIGFE
+xdr_uint32_t SIGFE
+xdr_uint64_t SIGFE
+xdr_uint8_t SIGFE
+xdr_union SIGFE
+xdr_vector SIGFE
+xdr_void SIGFE
+xdr_wrapstring SIGFE
+xdrmem_create SIGFE
+xdrrec_create SIGFE
+xdrrec_endofrecord SIGFE
+xdrrec_eof SIGFE
+xdrrec_skiprecord SIGFE
+xdrstdio_create SIGFE
 y0 NOSIGFE
 y0f NOSIGFE
 y1 NOSIGFE
diff -u src-newlib-p/winsup/cygwin/cygxdr.cc src/winsup/cygwin/cygxdr.cc
--- src-newlib-p/winsup/cygwin/cygxdr.cc	1969-12-31 19:00:00.000000000 -0500
+++ src/winsup/cygwin/cygxdr.cc	2010-02-12 20:14:43.634000000 -0500
@@ -0,0 +1,26 @@
+/* cygxdr.cc: 
+
+   Copyright 2010 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+
+#include "winsup.h"
+#include <stdarg.h>
+#include "cygxdr.h"
+
+extern "C" void
+cygxdr_vwarnx (const char * fmt, va_list ap)
+{
+  static const char * fake_func_name = "xdr-routines";
+
+  /* workaround missing debug_vprintf() */
+  if (fmt && *fmt && strace.active())
+    {
+      strace.vprntf (_STRACE_DEBUG, fake_func_name, fmt, ap);
+    }
+}
+
diff -u src-newlib-p/winsup/cygwin/cygxdr.h src/winsup/cygwin/cygxdr.h
--- src-newlib-p/winsup/cygwin/cygxdr.h	1969-12-31 19:00:00.000000000 -0500
+++ src/winsup/cygwin/cygxdr.h	2010-02-12 20:11:35.455000000 -0500
@@ -0,0 +1,25 @@
+/* cygxdr.h: 
+
+   Copyright 2010 Red Hat, Inc.
+
+This file is part of Cygwin.
+
+This software is a copyrighted work licensed under the terms of the
+Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
+details. */
+#ifndef _CYGXDR_H
+#define _CYGXDR_H
+
+extern "C"
+{
+
+typedef void (*xdr_vprintf_t)(const char *, va_list);
+
+xdr_vprintf_t xdr_set_vprintf (xdr_vprintf_t);
+
+void cygxdr_vwarnx (const char *, va_list);
+
+}
+
+#endif
+
diff -u src-newlib-p/winsup/cygwin/include/cygwin/version.h src/winsup/cygwin/include/cygwin/version.h
--- src-newlib-p/winsup/cygwin/include/cygwin/version.h	2010-02-12 01:17:49.738400000 -0500
+++ src/winsup/cygwin/include/cygwin/version.h	2010-02-12 19:25:24.951800000 -0500
@@ -376,12 +376,13 @@
       220: Export accept4, SOCK_CLOEXEC, SOCK_NONBLOCK.
       221: Export strfmon.
       222: CW_INT_SETLOCALE added.
+      223: Export xdr* functions.
      */
 
      /* Note that we forgot to bump the api for ualarm, strtoll, strtoull */
 
 #define CYGWIN_VERSION_API_MAJOR 0
-#define CYGWIN_VERSION_API_MINOR 222
+#define CYGWIN_VERSION_API_MINOR 223
 
      /* There is also a compatibity version number associated with the
 	shared memory regions.  It is incremented when incompatible
diff -u src-newlib-p/winsup/cygwin/init.cc src/winsup/cygwin/init.cc
--- src-newlib-p/winsup/cygwin/init.cc	2010-02-12 01:17:48.563400000 -0500
+++ src/winsup/cygwin/init.cc	2010-02-12 20:15:11.105000000 -0500
@@ -13,6 +13,7 @@
 #include "cygtls.h"
 #include "ntdll.h"
 #include "shared_info.h"
+#include "cygxdr.h"
 
 static DWORD _my_oldfunc;
 
@@ -138,6 +139,7 @@
 
       dll_crt0_0 ();
       _my_oldfunc = TlsAlloc ();
+      (void) xdr_set_vprintf (&cygxdr_vwarnx);
       break;
     case DLL_PROCESS_DETACH:
       if (dynamically_loaded)
diff -u src-newlib-p/winsup/cygwin/Makefile.in src/winsup/cygwin/Makefile.in
--- src-newlib-p/winsup/cygwin/Makefile.in	2010-02-12 01:17:47.477400000 -0500
+++ src/winsup/cygwin/Makefile.in	2010-02-12 20:04:17.184800000 -0500
@@ -136,7 +136,7 @@
 # Please maintain this list in sorted order, with maximum files per 86 col line
 #
 DLL_OFILES:=assert.o autoload.o bsdlib.o ctype.o cxx.o cygheap.o cygthread.o \
-	cygtls.o dcrt0.o debug.o devices.o dir.o dlfcn.o dll_init.o \
+	cygtls.o cygxdr.o dcrt0.o debug.o devices.o dir.o dlfcn.o dll_init.o \
 	dtable.o environ.o errno.o exceptions.o exec.o external.o fcntl.o \
 	fhandler.o fhandler_clipboard.o fhandler_console.o fhandler_disk_file.o \
 	fhandler_dsp.o fhandler_fifo.o fhandler_floppy.o fhandler_mailslot.o \

Attachment: xdr-newlib-primary.patch.lzma
Description: Binary data

Attachment: xdr-newlib-auto.patch.lzma
Description: Binary data


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