[#1611] set_trace_func/Array#fetch error — "Nathaniel Talbott" <nathaniel@...>

I've reduced the error I reported in ruby-talk:84013 to the following code:

17 messages 2003/10/11

PATCH: Revive NextStep, OpenStep, Rhapsody ports

From: Eric Sunshine <sunshine@...>
Date: 2003-10-09 15:15:39 UTC
List: ruby-core #1596
Hello,

Here is a patch which revives the NextStep, OpenStep, and Rhapsody ports of  
Ruby.  These ports seem to have languished for some time and have become  
unbuildable.  I also included an appropriate ChangeLog entry.

Eric

---- ChangeLog ----
Thu Oct  9 12:05:46 2003  Eric Sunshine <sunshine@sunshineco.com>

	* configure.in: revived NextStep, OpenStep, and Rhapsody ports which
	  had become unbuildable; enhanced --enable-fat-binary option so that
	  it accepts a list of desired architectures (rather than assuming a
	  fixed list), or defaults to a platform-appropriate list if user does
	  not provide an explicit list; made the default list of architectures
	  for MAB (fat binary) more comprehensive; now uses -fno-common even
	  when building the interpreter (in addition to using it for
	  extensions), thus allowing the interpreter to be embedded into a
	  plugin module of an external project (in addition to allowing
	  embedding directly into an application); added checks for
	  <netinet/in_systm.h> (needed by `socket' extension) and getcwd(); now
	  ensures that -I/usr/local/include is employed when extensions'
	  extconf.rb scripts invoke have_header() since extension checks on
	  NextStep and OpenStep will fail without it if the desired resource
	  resides in the /usr/local tree; fixed formatting of --help message.

	* Makefile.in: $(LIBRUBY_A) rule now deletes the archive before
	  invoking $(AR) since `ar' on Apple/NeXT can not "update" MAB archives
	  (see configure's --enable-fat-binary option); added rule for new
	  missing/getcwd.c.

	* defines.h: fixed endian handling during MAB build (see configure's
	  --enable-fat-binary option) to ensure that all portions of the
	  project see the correct WORDS_BIGENDIAN value (some extension modules
	  were getting the wrong endian setting); added missing constants
	  GETPGRP_VOID, WNOHANG, WUNTRACED, X_OK, and type pid_t for NextStep
	  and OpenStep; removed unnecessary and problematic HAVE_SYS_WAIT_H
	  define in NeXT section.

	* dir.c: do not allow NAMLEN() macro to trust dirent::d_namlen on
	  NextStep since, on some installations, this value always resolves
	  uselessly to zero.

	* dln.c: added error reporting to NextStep extension loader since the
	  previous behavior of failing silently was not useful; now ensures
	  that NSLINKMODULE_OPTION_BINDNOW compatibility constant is defined
	  for OpenStep and Rhapsody; no longer includes <mach-o/dyld.h> twice
	  on Rhapsody since this header lacks multiple-include protection,
	  which resulted in "redefinition" compilation errors.

	* MANIFEST: added aclocal.m4 and missing/getcwd.c.

	* aclocal.m4: added; works around Autoconf 2.5x `mkdir' test which
	  leaves bogus directory named `-p' on NextStep and OpenStep.

	* missing/getcwd.c: added.

	* missing.h: added HAVE_GETCWD and getcwd() prototype.

	* main.c: also create hard reference to objc_msgSend() on NeXT
	  platforms (in addition to Apple platforms).

	* lib/mkmf.rb: now exports XCFLAGS from configure script to extension
	  makefiles so that extensions can be built MAB (see configure's
	  --enable-fat-binary option); also utilize XCFLAGS in cc_command()
	  (but not cpp_command() because MAB flags are incompatible with
	  direct invocation of `cpp').

	* ext/curses/extconf.rb: now additionally checks for presence of these
	  curses functions which are not present on NextStep or Openstep:
	  bkgd(), bkgdset(), color(), curs(), getbkgd(), init(), scrl(), set(),
	  setscrreg(), wattroff(), wattron(), wattrset(), wbkgd(), wbkgdset(),
	  wscrl(), wsetscrreg()

	* ext/curses/curses.c: added appropriate #ifdef's for additional set of
	  curses functions now checked by extconf.rb; fixed curses_bkgd() and
	  window_bkgd() to correctly return boolean result rather than numeric
	  result; fixed window_getbkgd() to correctly signal an error by
	  returning nil rather than -1.

	* ext/etc/etc.c: setup_passwd() and setup_group() now check for null
	  pointers before invoking rb_tainted_str_new2() upon fields extracted
	  from `struct passwd' and `struct group' since null pointers in some
	  fields are common on NextStep/OpenStep (especially so for the
	  `pw_comment' field) and rb_tainted_str_new2() throws an exception
	  when it receives a null pointer.

	* ext/pty/pty.c: include "util.h" for strdup()/ruby_strdup() for
	  platforms such as NextStep and OpenStep which lack strdup().

	* ext/socket/getaddrinfo.c: cast first argument of getservbyname(),
	  gethostbyaddr(), and gethostbyname() from (const char*) to non-const
	  (char*) for older platforms such as NextStep and OpenStep.

	* ext/socket/socket.c: include "util.h" for strdup()/ruby_strdup() for
	  platforms such as NextStep and OpenStep which lack strdup(); include
	  <netinet/in_systm.h> if present for NextStep and OpenStep; cast first
	  argument of gethostbyaddr() and getservbyname() from (const char*) to
	  non-const (char*) for older platforms.

	* ext/syslog/syslog.c: include "util.h" for strdup()/ruby_strdup() for
	  platforms such as NextStep and OpenStep which lack strdup().
---- ChangeLog ----


diff -u -r -N -x CVS stable/ruby/MANIFEST ruby/MANIFEST
--- stable/ruby/MANIFEST	Wed Oct  8 10:11:01 2003
+++ ruby/MANIFEST	Wed Oct  8 10:13:13 2003
@@ -1,3 +1,4 @@
+aclocal.m4
 COPYING
 COPYING.ja
 ChangeLog
@@ -493,6 +494,7 @@
 missing/fileblocks.c
 missing/finite.c
 missing/flock.c
+missing/getcwd.c
 missing/hypot.c
 missing/isinf.c
 missing/isnan.c
diff -u -r -N -x CVS stable/ruby/Makefile.in ruby/Makefile.in
--- stable/ruby/Makefile.in	Wed Oct  1 09:41:30 2003
+++ ruby/Makefile.in	Tue Oct  7 15:39:42 2003
@@ -121,7 +121,11 @@
 		@rm -f $@
 		$(PURIFY) $(CC) $(LDFLAGS) $(XLDFLAGS) $(MAINLIBS)  
$(MAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@

+# We must `rm' the library each time this rule is invoked because "updating" a
+# MAB library on Apple/NeXT (see --enable-fat-binary in configure) is not
+# supported.
 $(LIBRUBY_A):	$(OBJS) $(DMYEXT)
+		@rm -f $@
 		@AR@ rcu $@ $(OBJS) $(DMYEXT)
 		@-@RANLIB@ $@ 2> /dev/null || true

@@ -297,6 +301,9 @@

 strtoul.@OBJEXT@: $(srcdir)/missing/strtoul.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/strtoul.c
+
+getcwd.@OBJEXT@: $(srcdir)/missing/getcwd.c
+	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/getcwd.c

 x68.@OBJEXT@: $(srcdir)/missing/x68.c
 	$(CC) $(CFLAGS) $(CPPFLAGS) -c $(srcdir)/missing/x68.c
diff -u -r -N -x CVS stable/ruby/aclocal.m4 ruby/aclocal.m4
--- stable/ruby/aclocal.m4	Wed Dec 31 19:00:00 1969
+++ ruby/aclocal.m4	Tue Oct  7 15:39:42 2003
@@ -0,0 +1,40 @@
+#------------------------------------------------------------------------------
+# Replacement for AS_MKDIR_P() from m4sugar/m4sh.m4 which fixes two issues
+# which are present in Autoconf 2.57 and probably all earlier 2.5x versions.
+# This bug, along with a patch, was submitted to the Autoconf GNATS database by
+# Eric Sunshine <sunshine@sunshineco.com> as #227 on 17-Dec-2002.  The bogus
+# "-p" directory bug was fixed for Autoconf 2.58 on 26-Sep-2003.  The "mkdirs"
+# optimization was not accepted (since it is unnecessary; it's only an
+# optimization).
+#
+# 1) Removes bogus "-p" directory which the stock AS_MKDIR_P() leaves laying
+#    around in the working directory if the mkdir command does not recognize
+#    the -p option.
+# 2) Takes advantage of the older "mkdirs" program if it exists and if "mkdir
+#    -p" does not work.
+#------------------------------------------------------------------------------
+m4_defun([_AS_MKDIR_P_PREPARE],
+[if mkdir -p . 2>/dev/null; then
+  as_mkdir_p='mkdir -p'
+elif mkdirs . 2>/dev/null; then
+  as_mkdir_p='mkdirs'
+else
+  as_mkdir_p=''
+fi
+test -d ./-p && rmdir ./-p
+])# _AS_MKDIR_P_PREPARE
+
+m4_define([AS_MKDIR_P],
+[AS_REQUIRE([_$0_PREPARE])dnl
+{ if test -n "$as_mkdir_p"; then
+    $as_mkdir_p $1
+  else
+    as_dir=$1
+    as_dirs=
+    while test ! -d "$as_dir"; do
+      as_dirs="$as_dir $as_dirs"
+      as_dir=`AS_DIRNAME("$as_dir")`
+    done
+    test ! -n "$as_dirs" || mkdir $as_dirs
+  fi || AS_ERROR([cannot create directory $1]); }
+])# AS_MKDIR_P
diff -u -r -N -x CVS stable/ruby/configure.in ruby/configure.in
--- stable/ruby/configure.in	Mon Sep 22 06:25:24 2003
+++ ruby/configure.in	Tue Oct  7 15:39:42 2003
@@ -74,48 +74,57 @@
 AC_CANONICAL_TARGET

 dnl checks for fat-binary
-fat_binary=no
 AC_ARG_ENABLE(fat-binary,
-       [  --enable-fat-binary     build a NeXT/Apple Multi Architecture Binary. ],
-       [fat_binary=$enableval])
- if test "$fat_binary" = yes ; then
+       [  --enable-fat-binary=ARCHS
+                          build an Apple/NeXT Multi Architecture Binary (MAB);
+                          ARCHS is a comma-delimited list of architectures for
+                          which to build; if ARCHS is omitted, then the package
+                          will be built for all architectures supported by the
+                          platform ("ppc" for MacOS/X and Darwin; "ppc,i386"
+                          for Rhapsody; "m68k,i386,sparc" for OpenStep;
+                          "m68k,i386,sparc,hppa" for NextStep); if this option
+                          is disabled or omitted entirely, then the package
+                          will be built only for the target platform],
+       [fat_binary=$enableval], [fat_binary=no])
+ if test "$fat_binary" != no; then
+
+    AC_MSG_CHECKING([target architectures])
+
+    # Respect TARGET_ARCHS setting from environment if available.
+    if test -z "$TARGET_ARCHS"; then
+	# Respect ARCH given to --enable-fat-binary if present.
+	if test "$fat_binary" != yes; then
+	    TARGET_ARCHS=`echo "$fat_binary" | tr ',' ' '`
+	else
+	    # Choose a default set of architectures based upon platform.
+	    case "$target_os" in
+	    darwin*)
+		TARGET_ARCHS="ppc"
+		;;
+	    rhapsody*)
+		TARGET_ARCHS="ppc i386"
+		;;
+	    openstep*)
+		TARGET_ARCHS="m68k i386 sparc"
+		;;
+	    nextstep*)
+		TARGET_ARCHS="m68k i386 sparc hppa"
+		;;
+	    *)
+		TARGET_ARCHS=`arch`
+	    esac
+	fi
+    fi

-    AC_MSG_CHECKING(target architecture)
+    AC_MSG_RESULT([$TARGET_ARCHS])

-    case "$target_os" in
-    rhapsody*)
-        echo -n "MacOS X Server: "
-	  	if test "$TARGET_ARCHS" = "" ; then
-   	        TARGET_ARCHS="ppc i386"
-  		fi
-	;;
-    nextstep*|openstep*)
-  	    echo -n "NeXTSTEP/OPENSTEP: "
-	    if test "$TARGET_ARCHS" = "" ; then
-	       if test `/usr/bin/arch` = "m68k" ; then
-		   TARGET_ARCHS="m68k i486"
-	       else # Black and Native one
-		   TARGET_ARCHS="m68k `/usr/bin/arch`"
-	       fi
-	    fi
-	# to ensure AC_HEADER_SYS_WAIT works
-	AC_DEFINE(_POSIX_SOURCE)
-        ;;
-    macos*|darwin*)
-        echo -n "MacOS X (Darwin): "
-            if test "$TARGET_ARCHS" = "" ; then
-                TARGET_ARCHS="ppc i386"
-            fi
-	;;
-    esac
     # /usr/lib/arch_tool -archify_list $TARGET_ARCHS
+    ARCH_FLAG=
     for archs in $TARGET_ARCHS
     do
-        ARCH_FLAG="$ARCH_FLAG -arch $archs "
-        echo -n " $archs"
+        ARCH_FLAG="$ARCH_FLAG -arch $archs"
     done
     AC_DEFINE(NEXT_FAT_BINARY)
-    echo "."
 fi

 case $target_cpu in
@@ -348,7 +357,7 @@
 AC_CHECK_HEADERS(stdlib.h string.h unistd.h limits.h sys/file.h sys/ioctl.h\
 		 fcntl.h sys/fcntl.h sys/select.h sys/time.h sys/times.h  
sys/param.h\
 		 syscall.h pwd.h grp.h a.out.h utime.h memory.h direct.h  
sys/resource.h \
-		 sys/mkdev.h sys/utime.h float.h)
+		 sys/mkdev.h sys/utime.h netinet/in_systm.h float.h)

 dnl Checks for typedefs, structures, and compiler characteristics.
 AC_TYPE_UID_T
@@ -365,7 +374,7 @@
 AC_FUNC_FSEEKO
 AC_CHECK_FUNCS(ftello)
 AC_REPLACE_FUNCS(dup2 memmove mkdir strcasecmp strncasecmp strerror strftime\
-		 strchr strstr strtoul crypt flock vsnprintf\
+		 strchr strstr strtoul getcwd crypt flock vsnprintf\
 		 isinf isnan finite hypot acosh erf)
 AC_CHECK_FUNCS(fmod killpg wait4 waitpid syscall chroot fsync\
 	      truncate chsize times utimes fcntl lockf lstat symlink readlink\
@@ -376,7 +385,8 @@
 	      setsid telldir seekdir fchmod mktime timegm cosh sinh tanh\
 	      setuid setgid)
 AC_ARG_ENABLE(setreuid,
-       [  --enable-setreuid       use setreuid()/setregid() according to  
need even if obsolete.],
+       [  --enable-setreuid       use setreuid()/setregid() according to  
need even if
+                          obsolete.],
        [use_setreuid=$enableval])
 if test "$use_setreuid" = yes; then
     AC_DEFINE(USE_SETREUID)
@@ -665,7 +675,8 @@
 DEFAULT_KCODE="KCODE_NONE"

 AC_ARG_WITH(default-kcode,
-	[  --with-default-kcode=CODE specify default value for \$KCODE  
(utf8|euc|sjis|none)],
+	[  --with-default-kcode=CODE
+                          specify default value for $KCODE (utf8|euc|sjis|none)], 
 	[case $withval in
 	utf8) DEFAULT_KCODE="KCODE_UTF8";;
 	euc)  DEFAULT_KCODE="KCODE_EUC";;
@@ -683,9 +694,6 @@
 	*)   with_dln_a_out=no;;
 	esac], [with_dln_a_out=no])

-AC_SUBST(XCFLAGS)dnl
-AC_SUBST(XLDFLAGS)dnl
-
 AC_CACHE_CHECK(whether ELF binaries are produced, rb_cv_binary_elf,
 [AC_TRY_RUN([
 /* Test for whether ELF binaries are produced */
@@ -748,9 +756,9 @@
   AC_MSG_CHECKING(whether OS depend dynamic link works)
   if test "$GCC" = yes; then
     case "$target_os" in
-    nextstep*)	;;
-    openstep*)	;;
-    rhapsody*)	;;
+    nextstep*)	CCDLFLAGS=-fno-common;;
+    openstep*)	CCDLFLAGS=-fno-common;;
+    rhapsody*)	CCDLFLAGS=-fno-common;;
     darwin*)	CCDLFLAGS=-fno-common;;
     human*)	;;
     bsdi*)	;;
@@ -964,7 +972,8 @@
 EXTSTATIC=
 AC_SUBST(EXTSTATIC)dnl
 AC_ARG_WITH(static-linked-ext,
-	    [  --with-static-linked-ext link external modules statically],
+	    [  --with-static-linked-ext
+                          link external modules statically],
             [case $withval in
 	     yes) STATIC=
 		  EXTSTATIC=static;;
@@ -1039,7 +1048,7 @@
   prefix=$ac_default_prefix
 fi

-if test "$fat_binary" = yes ; then
+if test "$fat_binary" != no ; then
   XCFLAGS="$ARCH_FLAG"
 fi

@@ -1170,17 +1179,22 @@
     netbsd*)
     	CFLAGS="$CFLAGS -pipe"
 	;;
-    nextstep*)
-    	CFLAGS="$CFLAGS -pipe"
-	;;
-    openstep*)
-    	CFLAGS="$CFLAGS -pipe"
+    nextstep*|openstep*)
+	# The -fno-common is needed if we wish to embed the Ruby interpreter
+	# into a plugin module of some project (as opposed to embedding it
+	# within the project's application).  The -I/usr/local/include is
+	# needed because CPP as discovered by configure (cc -E -traditional)
+	# fails to consult /usr/local/include by default.  This causes
+	# mkmf.rb's have_header() to fail if the desired resource happens to be
+	# installed in the /usr/local tree.
+    	CFLAGS="$CFLAGS -pipe -fno-common"
+	CPPFLAGS="$CPPFLAGS -I/usr/local/include"
 	;;
     rhapsody*)
-    	CFLAGS="$CFLAGS -pipe -no-precomp"
+    	CFLAGS="$CFLAGS -pipe -no-precomp -fno-common"
 	;;
     darwin*)
-    	CFLAGS="$CFLAGS -pipe"
+    	CFLAGS="$CFLAGS -pipe -fno-common"
 	;;
     os2-emx)
     	CFLAGS="$CFLAGS -DOS2 -Zmts"
@@ -1259,6 +1273,8 @@
   *msdosdjgpp*) FIRSTMAKEFILE=GNUmakefile:djgpp/GNUmakefile.in;;
 esac

+AC_SUBST(XCFLAGS)dnl
+AC_SUBST(XLDFLAGS)dnl
 AC_SUBST(LIBRUBY_LDSHARED)
 AC_SUBST(LIBRUBY_DLDFLAGS)
 AC_SUBST(RUBY_INSTALL_NAME)
@@ -1335,7 +1351,7 @@
 configure_args=$ac_configure_args
 AC_SUBST(configure_args)dnl

-if test "$fat_binary" = yes ; then
+if test "$fat_binary" != no ; then
     arch="fat-${target_os}"

     AC_DEFINE_UNQUOTED(RUBY_THIN_ARCHLIB,
@@ -1358,14 +1374,14 @@
 AC_DEFINE_UNQUOTED(RUBY_SITE_ARCHLIB, "${RUBY_SITE_LIB_PATH2}/${sitearch}")

 AC_ARG_WITH(search-path,
-		[  --with-search-path=DIR specify the additional search path],
+		[  --with-search-path=DIR  specify the additional search path],
 		[search_path=$withval])
 if test "$search_path" != ""; then
     AC_DEFINE_UNQUOTED(RUBY_SEARCH_PATH,"$search_path")
 fi

 AC_ARG_WITH(mantype,
-		[  --with-mantype=TYPE specify man page type; TYPE is one of  
man and doc],
+		[  --with-mantype=TYPE     specify man page type; TYPE is  
one of man and doc],
 		[
 			case "$withval" in
 			man|doc)
diff -u -r -N -x CVS stable/ruby/defines.h ruby/defines.h
--- stable/ruby/defines.h	Fri Sep 26 05:35:43 2003
+++ ruby/defines.h	Tue Oct  7 15:39:42 2003
@@ -98,15 +98,23 @@
 #endif
 #endif

-#ifdef NeXT
-#define DYNAMIC_ENDIAN		/* determine endian at runtime */
+#ifdef __NeXT__
+#define S_IXGRP 0000010         /* execute/search permission, group */
+#define S_IXOTH 0000001         /* execute/search permission, other */
 #ifndef __APPLE__
 #define S_IXUSR _S_IXUSR        /* execute/search permission, owner */
+#define GETPGRP_VOID 1
+#define WNOHANG 01
+#define WUNTRACED 02
+#define X_OK 1
+typedef int pid_t;
+/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may
+   result in a different endian. */
+#undef WORDS_BIGENDIAN
+#ifdef __BIG_ENDIAN__
+#define WORDS_BIGENDIAN
+#endif
 #endif
-#define S_IXGRP 0000010         /* execute/search permission, group */
-#define S_IXOTH 0000001         /* execute/search permission, other */
-
-#define HAVE_SYS_WAIT_H         /* configure fails to find this */
 #endif /* NeXT */

 #ifdef __CYGWIN__
diff -u -r -N -x CVS stable/ruby/dir.c ruby/dir.c
--- stable/ruby/dir.c	Sun Aug 17 22:23:13 2003
+++ ruby/dir.c	Tue Oct  7 15:39:42 2003
@@ -29,7 +29,12 @@
 # define NAMLEN(dirent) strlen((dirent)->d_name)
 #else
 # define dirent direct
-# define NAMLEN(dirent) (dirent)->d_namlen
+# if !defined __NeXT__
+#  define NAMLEN(dirent) (dirent)->d_namlen
+# else
+#  /* On some versions of NextStep, d_namlen is always zero, so avoid it. */
+#  define NAMLEN(dirent) strlen((dirent)->d_name)
+# endif
 # if HAVE_SYS_NDIR_H
 #  include <sys/ndir.h>
 # endif
diff -u -r -N -x CVS stable/ruby/dln.c ruby/dln.c
--- stable/ruby/dln.c	Fri Jul 25 01:36:47 2003
+++ ruby/dln.c	Wed Oct  8 10:46:54 2003
@@ -1139,12 +1139,15 @@
 #include <mach-o/rld.h>
 #else
 #include <mach-o/dyld.h>
+#ifndef NSLINKMODULE_OPTION_BINDNOW
+#define NSLINKMODULE_OPTION_BINDNOW 1
 #endif
 #endif
+#else
 #ifdef __APPLE__
 #include <mach-o/dyld.h>
 #endif
-
+#endif

 #if defined _WIN32 && !defined __CYGWIN__
 #include <windows.h>
@@ -1389,30 +1392,41 @@
    Special Thanks...
     Yu tomoak-i@is.aist-nara.ac.jp,
     Mi hisho@tasihara.nest.or.jp,
+    sunshine@sunshineco.com,
     and... Miss ARAI Akino(^^;)
  ----------------------------------------------------*/
 #if defined(NeXT) && (NS_TARGET_MAJOR < 4)/* NeXTSTEP rld functions */

     {
+        NXStream* s;
 	unsigned long init_address;
 	char *object_files[2] = {NULL, NULL};

 	void (*init_fct)();
 	
-	object_files[0] = file;
+	object_files[0] = (char*)file;
 	
+	s = NXOpenFile(2,NX_WRITEONLY);
+
 	/* Load object file, if return value ==0 ,  load failed*/
-	if(rld_load(NULL, NULL, object_files, NULL) == 0) {
+	if(rld_load(s, NULL, object_files, NULL) == 0) {
+	    NXFlush(s);
+	    NXClose(s);
 	    rb_loaderror("Failed to load %.200s", file);
 	}

 	/* lookup the initial function */
-	if(rld_lookup(NULL, buf, &init_address) == 0) {
+	if(rld_lookup(s, buf, &init_address) == 0) {
+	    NXFlush(s);
+	    NXClose(s);
 	    rb_loaderror("Failed to lookup Init function %.200s", file);
 	}

-	 /* Cannot call *init_address directory, so copy this value to
-	    funtion pointer */
+	NXFlush(s);
+	NXClose(s);
+
+	/* Cannot call *init_address directory, so copy this value to
+	   funtion pointer */
 	init_fct = (void(*)())init_address;
 	(*init_fct)();
 	return (void*)init_address;
diff -u -r -N -x CVS stable/ruby/ext/curses/curses.c ruby/ext/curses/curses.c
--- stable/ruby/ext/curses/curses.c	Mon Aug 18 12:24:42 2003
+++ ruby/ext/curses/curses.c	Tue Oct  7 15:39:42 2003
@@ -477,22 +477,34 @@
 static VALUE
 curses_curs_set(VALUE obj, VALUE visibility)
 {
+#ifdef HAVE_CURS_SET
   int n;
   return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
+#else
+  return Qnil;
+#endif
 }

 static VALUE
 curses_scrl(VALUE obj, VALUE n)
 {
   /* may have to raise exception on ERR */
+#ifdef HAVE_SCRL
   return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
 curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
 {
   /* may have to raise exception on ERR */
+#ifdef HAVE_SETSCRREG
   return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
@@ -519,14 +531,20 @@
 static VALUE
 curses_bkgdset(VALUE obj, VALUE ch)
 {
+#ifdef HAVE_BKGDSET
   bkgdset(NUM2CHR(ch));
+#endif
   return Qnil;
 }

 static VALUE
 curses_bkgd(VALUE obj, VALUE ch)
 {
-  return CHR2FIX(bkgd(NUM2CHR(ch)));
+#ifdef HAVE_BKGD
+  return (bkgd(NUM2CHR(ch)) == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
@@ -1125,6 +1143,7 @@
 static VALUE
 window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
 {
+#ifdef HAVE_WSETSCRREG
   struct windata *winp;
   int res;

@@ -1132,6 +1151,9 @@
   res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
   /* may have to raise exception on ERR */
   return (res == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
@@ -1147,25 +1169,34 @@
 static VALUE
 window_scrl(VALUE obj, VALUE n)
 {
+#ifdef HAVE_WSCRL
   struct windata *winp;

   GetWINDOW(obj, winp);
   /* may have to raise exception on ERR */
   return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
 window_attroff(VALUE obj, VALUE attrs)
 {
+#ifdef HAVE_WATTROFF
   struct windata *winp;

   GetWINDOW(obj,winp);
   return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
+#else
+  return Qtrue;
+#endif
 }

 static VALUE
 window_attron(VALUE obj, VALUE attrs)
 {
+#ifdef HAVE_WATTRON
   struct windata *winp;
   VALUE val;

@@ -1179,43 +1210,61 @@
   else{
     return val;
   }
+#else
+  return Qtrue;
+#endif
 }

 static VALUE
 window_attrset(VALUE obj, VALUE attrs)
 {
+#ifdef HAVE_WATTRSET
   struct windata *winp;

   GetWINDOW(obj,winp);
   return INT2FIX(wattrset(winp->window,NUM2INT(attrs)));
+#else
+  return Qtrue;
+#endif
 }

 static VALUE
 window_bkgdset(VALUE obj, VALUE ch)
 {
+#ifdef HAVE_WBKGDSET
   struct windata *winp;

   GetWINDOW(obj,winp);
   wbkgdset(winp->window, NUM2CHR(ch));
+#endif
   return Qnil;
 }

 static VALUE
 window_bkgd(VALUE obj, VALUE ch)
 {
+#ifdef HAVE_WBKGD
   struct windata *winp;

   GetWINDOW(obj,winp);
-  return CHR2FIX(wbkgd(winp->window, NUM2CHR(ch)));
+  return (wbkgd(winp->window, NUM2CHR(ch)) == OK) ? Qtrue : Qfalse;
+#else
+  return Qfalse;
+#endif
 }

 static VALUE
 window_getbkgd(VALUE obj)
 {
+#ifdef HAVE_WGETBKGD
+  char c;
   struct windata *winp;

   GetWINDOW(obj,winp);
-  return CHR2FIX(getbkgd(winp->window));
+  return (c = getbkgd(winp->window) != ERR) ? CHR2FIX(c) : Qnil;
+#else
+  return Qnil;
+#endif
 }

 static VALUE
diff -u -r -N -x CVS stable/ruby/ext/curses/extconf.rb ruby/ext/curses/extconf.rb
--- stable/ruby/ext/curses/extconf.rb	Mon Aug 18 12:24:42 2003
+++ ruby/ext/curses/extconf.rb	Tue Oct  7 15:39:42 2003
@@ -19,7 +19,7 @@
 end

 if make
-  for f in %w(isendwin ungetch beep getnstr wgetnstr doupdate flash  
deleteln wdeleteln keypad keyname init_color wresize resizeterm)
+  for f in %w(beep bkgd bkgdset color curs deleteln doupdate flash getbkgd  
getnstr init isendwin keyname keypad resizeterm scrl set setscrreg ungetch  
wattroff wattron wattrset wbkgd wbkgdset wdeleteln wgetnstr wresize wscrl  
wsetscrreg)
     have_func(f)
   end
   flag = "-D_XOPEN_SOURCE_EXTENDED"
diff -u -r -N -x CVS stable/ruby/ext/etc/etc.c ruby/ext/etc/etc.c
--- stable/ruby/ext/etc/etc.c	Wed Oct  1 11:26:06 2003
+++ ruby/ext/etc/etc.c	Tue Oct  7 15:39:43 2003
@@ -49,6 +49,16 @@
     return Qnil;
 }

+#if defined(HAVE_GETPWENT) || defined(HAVE_GETGRENT)
+static VALUE
+safe_setup_str(str)
+    const char *str;
+{
+    if (str == 0) str = "";
+    return rb_tainted_str_new2(str);
+}
+#endif
+
 #ifdef HAVE_GETPWENT
 static VALUE
 setup_passwd(pwd)
@@ -56,15 +66,15 @@
 {
     if (pwd == 0) rb_sys_fail("/etc/passwd");
     return rb_struct_new(sPasswd,
-			 rb_tainted_str_new2(pwd->pw_name),
-			 rb_tainted_str_new2(pwd->pw_passwd),
+			 safe_setup_str(pwd->pw_name),
+			 safe_setup_str(pwd->pw_passwd),
 			 INT2FIX(pwd->pw_uid),
 			 INT2FIX(pwd->pw_gid),
 #ifdef HAVE_ST_PW_GECOS
-			 rb_tainted_str_new2(pwd->pw_gecos),
+			 safe_setup_str(pwd->pw_gecos),
 #endif
-			 rb_tainted_str_new2(pwd->pw_dir),
-			 rb_tainted_str_new2(pwd->pw_shell),
+			 safe_setup_str(pwd->pw_dir),
+			 safe_setup_str(pwd->pw_shell),
 #ifdef HAVE_ST_PW_CHANGE
 			 INT2FIX(pwd->pw_change),
 #endif
@@ -75,10 +85,10 @@
 			 INT2FIX(pwd->pw_age),
 #endif
 #ifdef HAVE_ST_PW_CLASS
-			 rb_tainted_str_new2(pwd->pw_class),
+			 safe_setup_str(pwd->pw_class),
 #endif
 #ifdef HAVE_ST_PW_COMMENT
-			 rb_tainted_str_new2(pwd->pw_comment),
+			 safe_setup_str(pwd->pw_comment),
 #endif
 #ifdef HAVE_ST_PW_EXPIRE
 			 INT2FIX(pwd->pw_expire),
@@ -220,12 +230,12 @@
     mem = rb_ary_new();
     tbl = grp->gr_mem;
     while (*tbl) {
-	rb_ary_push(mem, rb_tainted_str_new2(*tbl));
+	rb_ary_push(mem, safe_setup_str(*tbl));
 	tbl++;
     }
     return rb_struct_new(sGroup,
-			 rb_tainted_str_new2(grp->gr_name),
-			 rb_tainted_str_new2(grp->gr_passwd),
+			 safe_setup_str(grp->gr_name),
+			 safe_setup_str(grp->gr_passwd),
 			 INT2FIX(grp->gr_gid),
 			 mem);
 }
diff -u -r -N -x CVS stable/ruby/ext/pty/pty.c ruby/ext/pty/pty.c
--- stable/ruby/ext/pty/pty.c	Mon May 19 11:45:29 2003
+++ ruby/ext/pty/pty.c	Tue Oct  7 15:39:43 2003
@@ -24,6 +24,7 @@

 #include "ruby.h"
 #include "rubyio.h"
+#include "util.h"

 #include <signal.h>
 #ifdef HAVE_SYS_STROPTS_H
diff -u -r -N -x CVS stable/ruby/ext/socket/getaddrinfo.c  
ruby/ext/socket/getaddrinfo.c
--- stable/ruby/ext/socket/getaddrinfo.c	Tue Sep  2 01:12:39 2003
+++ ruby/ext/socket/getaddrinfo.c	Tue Oct  7 15:39:43 2003
@@ -397,7 +397,7 @@
 				fprintf(stderr, "panic!\n");
 				break;
 			}
-			if ((sp = getservbyname(servname, proto)) == NULL)
+			if ((sp = getservbyname((char*)servname, proto)) == NULL)
 				ERR(EAI_SERVICE);
 			port = sp->s_port;
 			if (pai->ai_socktype == ANY)
@@ -554,7 +554,7 @@
 #ifdef INET6
 	hp = getipnodebyaddr(addr, afd->a_addrlen, afd->a_af, &h_error);
 #else
-	hp = gethostbyaddr(addr, afd->a_addrlen, AF_INET);
+	hp = gethostbyaddr((char*)addr, afd->a_addrlen, AF_INET);
 #endif
 	if (hp && hp->h_name && hp->h_name[0] && hp->h_addr_list[0]) {
 		GET_AI(cur, afd, hp->h_addr_list[0], port);
@@ -606,7 +606,7 @@
 	} else
 		hp = getipnodebyname(hostname, af, AI_ADDRCONFIG, &h_error);
 #else
-	hp = gethostbyname(hostname);
+	hp = gethostbyname((char*)hostname);
 	h_error = h_errno;
 #endif
 	if (hp == NULL) {
diff -u -r -N -x CVS stable/ruby/ext/socket/socket.c ruby/ext/socket/socket.c
--- stable/ruby/ext/socket/socket.c	Mon Oct  6 08:46:17 2003
+++ ruby/ext/socket/socket.c	Tue Oct  7 15:39:43 2003
@@ -13,6 +13,7 @@
 #include "ruby.h"
 #include "rubyio.h"
 #include "rubysig.h"
+#include "util.h"
 #include <stdio.h>
 #include <sys/types.h>

@@ -31,6 +32,9 @@
 # include <sys/socket.h>
 #endif
 #include <netinet/in.h>
+#ifdef HAVE_NETINET_IN_SYSTM_H
+# include <netinet/in_systm.h>
+#endif
 #ifdef HAVE_NETINET_TCP_H
 # include <netinet/tcp.h>
 #endif
@@ -2009,7 +2013,7 @@
 	t = AF_INET6;
     }
 #endif
-    h = gethostbyaddr(RSTRING(addr)->ptr, RSTRING(addr)->len, t);
+    h = gethostbyaddr((char*)RSTRING(addr)->ptr, RSTRING(addr)->len, t);
     if (h == NULL) {
 #ifdef HAVE_HSTRERROR
 	extern int h_errno;
@@ -2052,7 +2056,7 @@
     else proto = StringValuePtr(protocol);

     StringValue(service);
-    sp = getservbyname(RSTRING(service)->ptr, proto);
+    sp = getservbyname((char*)RSTRING(service)->ptr, proto);
     if (sp) {
 	port = ntohs(sp->s_port);
     }
diff -u -r -N -x CVS stable/ruby/ext/syslog/syslog.c ruby/ext/syslog/syslog.c
--- stable/ruby/ext/syslog/syslog.c	Thu Jan 16 02:38:40 2003
+++ ruby/ext/syslog/syslog.c	Tue Oct  7 15:39:43 2003
@@ -8,6 +8,7 @@
  */

 #include "ruby.h"
+#include "util.h"
 #include <syslog.h>

 /* Syslog class */
diff -u -r -N -x CVS stable/ruby/lib/mkmf.rb ruby/lib/mkmf.rb
--- stable/ruby/lib/mkmf.rb	Mon Oct  6 06:24:28 2003
+++ ruby/lib/mkmf.rb	Tue Oct  7 15:39:43 2003
@@ -215,6 +215,7 @@
 		 'INCFLAGS' => $INCFLAGS,
 		 'CPPFLAGS' => $CPPFLAGS,
 		 'CFLAGS' => "#$CFLAGS",
+		 'XCFLAGS' => "#$XCFLAGS",
 		 'LDFLAGS' => "#$LDFLAGS #{ldflags}",
 		 'LIBPATH' => libpathflag(libpath),
 		 'LOCAL_LIBS' => "#$LOCAL_LIBS #$libs",
@@ -223,7 +224,7 @@

 def cc_command(opt="")
   "$(CC) -c #$INCFLAGS -I#{$hdrdir} " \
-  "#$CPPFLAGS #$CFLAGS #{opt} #{CONFTEST_C}"
+  "#$CPPFLAGS #$CFLAGS #$XCFLAGS #{opt} #{CONFTEST_C}"
 end

 def cpp_command(outfile, opt="")
@@ -718,7 +719,7 @@
 LIBRUBYARG_SHARED = #$LIBRUBYARG_SHARED
 LIBRUBYARG_STATIC = #$LIBRUBYARG_STATIC

-CFLAGS   = #{CONFIG['CCDLFLAGS'] unless $static} #$CFLAGS
+CFLAGS   = #{CONFIG['CCDLFLAGS'] unless $static} #{CONFIG['XCFLAGS']} #$CFLAGS
 CPPFLAGS = -I. -I$(topdir) -I$(hdrdir) -I$(srcdir) #{$defs.join(" ")} #{$CPPFLAGS}
 CXXFLAGS = $(CFLAGS) #{CONFIG['CXXFLAGS']}
 DLDFLAGS = #$LDFLAGS #{CONFIG['DLDFLAGS']} #$DLDFLAGS
@@ -941,6 +942,7 @@
   $enable_shared = config['ENABLE_SHARED'] == 'yes'
   $defs = []
   $CFLAGS = with_config("cflags", arg_config("CFLAGS", config["CFLAGS"])).dup
+  $XCFLAGS = config['XCFLAGS'].dup
   $CPPFLAGS = with_config("cppflags", arg_config("CPPFLAGS",  
config["CPPFLAGS"])).dup
   $LDFLAGS = (with_config("ldflags") || "").dup
   $INCFLAGS = "-I#{$topdir}"
diff -u -r -N -x CVS stable/ruby/main.c ruby/main.c
--- stable/ruby/main.c	Thu Jan 16 02:34:01 2003
+++ ruby/main.c	Tue Oct  7 15:39:43 2003
@@ -29,7 +29,7 @@
 #endif

 /* to link startup code with ObjC support */
-#if defined(__APPLE__) && defined(__MACH__)
+#if (defined(__APPLE__) || defined(__NeXT__)) && defined(__MACH__)
 static void objcdummyfunction( void ) { objc_msgSend(); }
 #endif

diff -u -r -N -x CVS stable/ruby/missing/getcwd.c ruby/missing/getcwd.c
--- stable/ruby/missing/getcwd.c	Wed Dec 31 19:00:00 1969
+++ ruby/missing/getcwd.c	Tue Oct  7 15:39:43 2003
@@ -0,0 +1,10 @@
+#include <sys/types.h>
+extern char *getwd();
+
+char*
+getcwd(s, n)
+    char* s;
+    size_t n;
+{
+    return getwd(s);
+}
diff -u -r -N -x CVS stable/ruby/missing.h ruby/missing.h
--- stable/ruby/missing.h	Tue Aug  5 05:27:20 2003
+++ ruby/missing.h	Tue Oct  7 15:39:43 2003
@@ -122,6 +122,10 @@
 extern unsigned long strtoul _((char *, char **, int));
 #endif

+#ifndef HAVE_GETCWD
+extern char* getcwd _((char *, size_t));
+#endif
+
 #ifndef HAVE_VSNPRINTF
 # ifdef HAVE_STDARG_PROTOTYPES
 #  include <stdarg.h>

In This Thread

Prev Next