Added some new modules
diff --git a/Modules/Setup.irix5 b/Modules/Setup.irix5
deleted file mode 100644
index c994044..0000000
--- a/Modules/Setup.irix5
+++ /dev/null
@@ -1,161 +0,0 @@
-# Each line in this file describes one or more optional modules.
-# Comment out lines to suppress modules.
-# Lines have the following structure:
-#
-# <module> ... [<objectfile> ...] [<cpparg> ...] [<library> ...]
-#
-# <objectfile> is anything ending in .o
-# <cpparg> is anything starting with -I, -D, -U or -C
-# <library> is anything ending in .a or beginning with -l or -L
-# <module> is anything else but should be a valid Python
-# identifier (letters, digits, underscores, beginning with non-digit)
-#
-# Lines can also have the form
-#
-# <name> = <value>
-#
-# which defines a Make variable definition inserted into Makefile.in
-#
-# NOTE: As a standard policy, as many modules as can be supported by a
-# platform should be present.  The distribution comes with all modules
-# enabled that are supported by most platforms and don't require you
-# to ftp sources from elsewhere.  To make this easier for SGI
-# platforms, you can copy Setup.sgi to Setup (or edit Makefile.in.in
-# to use Setup.sgi instead of Setup).
-
-
-# Some special rules to define PYTHONPATH
-# Edit the definitions below to indicate which options you are using
-
-# Don't edit this (usually)
-DESTLIB=$(prefix)/lib/python
-
-# Standard enabled (tests are always available)
-TESTPATH=:$(DESTLIB)/test
-
-# Enable this for SGI systems
-ARCHPATH=:$(DESTLIB)/sgi
-
-# Enable this for Sun systems
-#ARCHPATH=:$(DESTLIB)/sun4
-
-# Enable this if stdwin installed
-STDWINPATH=:$(DESTLIB)/stdwin
-
-PYTHONPATH=.:$(DESTLIB)$(TESTPATH)$(ARCHPATH)$(STDWINPATH)
-
-
-# Modules that should always be present (non UNIX dependent)
-
-array arraymodule.o	# array objects
-math mathmodule.o	# math library functions, e.g. sin()
-parser parsermodule.o	# raw interface to the Python parser
-posix posixmodule.o	# posix (UNIX) system calls
-regex regexmodule.o regexpr.o	# Regular expressions, GNU Emacs style
-strop stropmodule.o	# fast string operations implemented in C
-struct structmodule.o	# binary structure packing/unpacking
-time timemodule.o	# time operations and variables
-
-
-# Modules with some UNIX dependencies -- on by default.
-# Note that some UNIX versions still don't support all of these
-# so you may have to comment them out before the build completes.
-
-dbm dbmmodule.o		# dbm(3) may require -ldbm or similar
-fcntl fcntlmodule.o	# fcntl(2) and ioctl(2)
-nis nismodule.o		# Sun yellow pages -- not everywhere
-pwd grp pwdmodule.o	# pwd(3) and grp(3)
-crypt cryptmodule.o	# crypt(3)
-select selectmodule.o	# select(2); not on ancient System V
-socket socketmodule.o	# socket(2); not on ancient System V
-
-
-# Multimedia modules -- on by default
-# These represent audio samples or images as strings
-
-audioop audioopmodule.o # Operations on audio samples
-imageop imageopmodule.o # Operations on images
-rgbimg rgbimgmodule.o   # Read SGI RGB image files (but coded portably)
-
-
-# The stdwin module provides a simple, portable (between X11 and Mac)
-# windowing interface.  You need to ftp the STDWIN library, e.g. from
-# ftp://ftp.cwi.nl/pub/stdwin.  The STDWIN variable must point to the
-# STDWIN toplevel directory.  The ARCH variable must be set to the
-# architecture identifier used to build STDWIN.  NB if you combine this
-# with the gl module on an SGI machine, you should replace "-lX11" with
-# "-lX11_s".
-
-#STDWIN=/ufs/guido/src/stdwin
-#ARCH=sgi
-#stdwin stdwinmodule.o -I$(STDWIN)/H $(STDWIN)/Build/$(ARCH)/x11/lib/lib.a -lX11_s
-
-
-# The md5 module implements the RSA Data Security, Inc. MD5
-# Message-Digest Algorithm, described in RFC 1321.  The necessary files
-# md5c.c and md5.h are included here.
-
-md5 md5module.o md5c.o
-
-
-# The mpz module interfaces to the GNU Multiple Precision library.
-# You need to ftp the GNU MP library.  This was last tested with a
-# somewhat modified (to get around bugs) version of GMP 1.2; it will
-# likely need some work for more recent versions.  The GMP variable
-# must point to the GMP source directory.
-
-#GMP=/ufs/guido/src/gmp
-#mpz mpzmodule.o -I$(GMP) $(GMP)/libgmp.a
-
-
-# The rotor module (contributed by Lance Ellinghouse) implements a
-# rotor-based encryption algorithm.  It is self-contained.
-
-rotor rotormodule.o
-
-
-# SGI IRIX specific modules -- off by default.
-# Switch this on if you have an SGI machine.
-# Note that some required libraries and header files aren't always
-# installed; you may be better off switching on only 'fm' and 'gl'
-# (Font Manager and Graphics Library).
-
-#al almodule.o -laudio		# audio
-#cd cdmodule.o -lcdaudio -lds	#
-#cl clmodule.o -lcl
-fm fmmodule.o -lfm_s -lgl_s
-gl glmodule.o -lgl_s -lX11_s
-#imgfile imgfilemodule.o -limage -lgutil -lm
-sgi sgimodule.o
-#sv svmodule.o yuvconvert.o -lsvideo -lXext -lX11_s
-
-# The FORMS library, by Mark Overmars, implements user interface
-# components such as dialogs and buttons using SGI's GL and FM
-# libraries.  You must ftp the FORMS library separately from
-# ftp://ftp.cs.ruu.nl/pub/SGI/FORMS.  It was tested with FORMS 2.2a.
-# The FORMS variable must point to the FORMS subdirectory of the forms
-# toplevel directory.
-
-#FORMS=/ufs/guido/src/forms/FORMS
-#fl flmodule.o -I$(FORMS) $(FORMS)/libforms.a
-
-
-# SunOS specific modules -- off by default
-
-# sunaudiodev sunaudiodevmodule.o
-
-
-# Thread module -- works on SGI IRIX and on SunOS 5.x (SOLARIS) only.
-# Note that you must have configured (and built!) Python with the
-# --with-thread option passed to the configure script for this to work.
-
-thread threadmodule.o
-
-
-# GNN's timing module
-timing timingmodule.o
-
-
-# Example -- included for reference only
-
-# xx xxmodule.o
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
new file mode 100644
index 0000000..b6457cd
--- /dev/null
+++ b/Modules/dlmodule.c
@@ -0,0 +1,244 @@
+/***********************************************************
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
+
+                        All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its 
+documentation for any purpose and without fee is hereby granted, 
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in 
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+/* dl module */
+
+#include "allobjects.h"
+#include "modsupport.h"
+
+#include <dlfcn.h>
+
+#ifndef RTLD_LAZY
+#define RTLD_LAZY 1
+#endif
+
+typedef struct {
+	OB_HEAD
+	ANY *dl_handle;
+} dlobject;
+
+staticforward typeobject Dltype;
+
+static object *Dlerror;
+
+static object *
+newdlobject(handle)
+	ANY *handle;
+{
+	dlobject *xp;
+	xp = NEWOBJ(dlobject, &Dltype);
+	if (xp == NULL)
+		return NULL;
+	xp->dl_handle = handle;
+	return (object *)xp;
+}
+
+static void
+dl_dealloc(xp)
+	dlobject *xp;
+{
+	if (xp->dl_handle != NULL)
+		dlclose(xp->dl_handle);
+	DEL(xp);
+}
+
+static object *
+dl_close(xp, args)
+	dlobject *xp;
+	object *args;
+{
+	if (!getargs(args, ""))
+		return NULL;
+	if (xp->dl_handle != NULL) {
+		dlclose(xp->dl_handle);
+		xp->dl_handle = NULL;
+	}
+	INCREF(None);
+	return None;
+}
+
+static object *
+dl_sym(xp, args)
+	dlobject *xp;
+	object *args;
+{
+	char *name;
+	ANY *func;
+	if (!getargs(args, "s", &name))
+		return NULL;
+	func = dlsym(xp->dl_handle, name);
+	if (func == NULL) {
+		INCREF(None);
+		return None;
+	}
+	return newintobject((long)func);
+}
+
+static object *
+dl_call(xp, args)
+	dlobject *xp;
+	object *args; /* (varargs) */
+{
+	object *name;
+	long (*func)();
+	long alist[10];
+	long res;
+	int i;
+	int n = gettuplesize(args);
+	if (n < 1) {
+		err_setstr(TypeError, "at least a name is needed");
+		return NULL;
+	}
+	name = gettupleitem(args, 0);
+	if (!is_stringobject(name)) {
+		err_setstr(TypeError, "function name must be a string");
+		return NULL;
+	}
+	func = dlsym(xp->dl_handle, getstringvalue(name));
+	if (func == NULL) {
+		err_setstr(ValueError, dlerror());
+		return NULL;
+	}
+	if (n-1 > 10) {
+		err_setstr(TypeError, "too many arguments (max 10)");
+		return NULL;
+	}
+	for (i = 1; i < n; i++) {
+		object *v = gettupleitem(args, i);
+		if (is_intobject(v))
+			alist[i-1] = getintvalue(v);
+		else if (is_stringobject(v))
+			alist[i-1] = (long)getstringvalue(v);
+		else if (v == None)
+			alist[i-1] = (long) ((char *)NULL);
+		else {
+			err_setstr(TypeError,
+				   "arguments must be int, string or None");
+			return NULL;
+		}
+	}
+	for (; i <= 10; i++)
+		alist[i-1] = 0;
+	res = (*func)(alist[0], alist[1], alist[2], alist[3], alist[4],
+		      alist[5], alist[6], alist[7], alist[8], alist[9]);
+	return newintobject(res);
+}
+
+static struct methodlist dlobject_methods[] = {
+	{"call",	(method)dl_call,	1 /* varargs */},
+	{"sym", 	(method)dl_sym},
+	{"close",	(method)dl_close},
+	{NULL,  	NULL}			/* Sentinel */
+};
+
+static object *
+dl_getattr(xp, name)
+	dlobject *xp;
+	char *name;
+{
+	return findmethod(dlobject_methods, (object *)xp, name);
+}
+
+
+static typeobject Dltype = {
+	OB_HEAD_INIT(&Typetype)
+	0,			/*ob_size*/
+	"dl",			/*tp_name*/
+	sizeof(dlobject),	/*tp_basicsize*/
+	0,			/*tp_itemsize*/
+	/* methods */
+	(destructor)dl_dealloc, /*tp_dealloc*/
+	0,			/*tp_print*/
+	(getattrfunc)dl_getattr,/*tp_getattr*/
+	0,			/*tp_setattr*/
+	0,			/*tp_compare*/
+	0,			/*tp_repr*/
+	0,			/*tp_as_number*/
+	0,			/*tp_as_sequence*/
+	0,			/*tp_as_mapping*/
+	0,			/*tp_hash*/
+};
+
+static object *
+dl_open(self, args)
+	object *self;
+	object *args;
+{
+	char *name;
+	int mode;
+	ANY *handle;
+	if (getargs(args, "z", &name))
+		mode = RTLD_LAZY;
+	else {
+		err_clear();
+		if (!getargs(args, "(zi)", &name, &mode))
+			return NULL;
+#ifndef RTLD_NOW
+		if (mode != RTLD_LAZY) {
+			err_setstr(ValueError, "mode must be 1");
+			return NULL;
+		}
+#endif
+	}
+	handle = dlopen(name, mode);
+	if (handle == NULL) {
+		err_setstr(Dlerror, dlerror());
+		return NULL;
+	}
+	return newdlobject(handle);
+}
+
+static struct methodlist dl_methods[] = {
+	{"open",	dl_open},
+	{NULL,		NULL}		/* sentinel */
+};
+
+void
+initdl()
+{
+	object *m, *d, *x;
+
+	if (sizeof(int) != sizeof(long) ||
+	    sizeof(long) != sizeof(char *))
+		fatal(
+ "module dl requires sizeof(int) == sizeof(long) == sizeof(char*)");
+
+	/* Create the module and add the functions */
+	m = initmodule("dl", dl_methods);
+
+	/* Add some symbolic constants to the module */
+	d = getmoduledict(m);
+	Dlerror = x = newstringobject("dl.error");
+	dictinsert(d, "error", x);
+	x = newintobject((long)RTLD_LAZY);
+	dictinsert(d, "RTLD_LAZY", x);
+#ifdef RTLD_NOW
+	x = newintobject((long)RTLD_NOW);
+	dictinsert(d, "RTLD_NOW", x);
+#endif
+
+	/* Check for errors */
+	if (err_occurred())
+		fatal("can't initialize module dl");
+}
diff --git a/Modules/newmodule.c b/Modules/newmodule.c
new file mode 100644
index 0000000..aa5f77e
--- /dev/null
+++ b/Modules/newmodule.c
@@ -0,0 +1,111 @@
+/* newmodule.c */
+#include "allobjects.h"
+#include "compile.h"
+#include "modsupport.h"
+
+
+object*
+new_instancemethod(unused, args)
+    object* unused;
+    object* args;
+{
+    object* func;
+    object* self;
+    object* classObj;
+  
+    if (!getargs(args, "(OOO)", &func, &self, &classObj)) {
+	return NULL;
+    } else if (!is_funcobject(func) || !is_instanceobject(self) || !is_classobject(classObj)) {
+	err_setstr(TypeError, "expected a function, instance and classobject as args");
+	return NULL;
+    }
+    return newinstancemethodobject(func, self, classObj);
+}
+    
+
+object*
+new_function(unused, args)
+    object* unused;
+    object* args;
+{
+    object* code;
+    object* globals;
+    object* name;
+    object* newfunc;
+    object* argcount;
+    object* argdefs;
+  
+    if (!getargs(args, "(OOOOO)", &code, &globals, &name, &argcount, &argdefs)) {
+	return NULL;
+    } else if (!is_codeobject(code) || !is_mappingobject(globals) || !is_stringobject(name) || !is_intobject(argcount) || !is_tupleobject(argdefs)) {
+	err_setstr(TypeError, "expected a code object, a dict for globals, a string name, an integer default argument count and a tuple of default argument definitions.");
+	return NULL;
+    }
+
+    newfunc = newfuncobject(code, globals);
+
+    ((funcobject *)newfunc)->func_name = name;
+    XINCREF( name );
+    XDECREF( ((codeobject*)(((funcobject *)(newfunc))->func_code))->co_name );
+
+    ((funcobject *)newfunc)->func_argcount = getintvalue(argcount);
+    ((funcobject *)newfunc)->func_argdefs  = argdefs;
+    XINCREF( argdefs );
+
+    return newfunc;
+}
+    
+
+object*
+new_code(unused, args)
+    object* unused;
+    object* args;
+{
+    object* code;
+    object* consts;
+    object* names;
+    object* filename;
+    object* name;
+  
+    if (!getargs(args, "(OOOOO)", &code, &consts, &names, &filename, &name)) {
+	return NULL;
+    } else if (!is_stringobject(code) || !is_listobject(consts) ||    \
+	       !is_listobject(names) || !is_stringobject(filename) || \
+	       !is_stringobject(name)) {
+	err_setstr(TypeError, "expected a string of compiled code, a list of constants,   \
+                               a list of names used, a string filename, and a string name \
+                               as args");
+	return NULL;
+    }
+    return (object *)newcodeobject(code, consts, names, filename, name);
+}
+    
+
+object*
+new_module(unused, args)
+    object* unused;
+    object* args;
+{
+    object* name;
+  
+    if (!getargs(args, "S", &name)) {
+	err_setstr(TypeError, "expected a string name as args");
+	return NULL;
+    }
+    return newmoduleobject(getstringvalue(name));
+}
+    
+
+static struct methodlist new_methods[] = {
+    { "instancemethod", new_instancemethod },
+    { "function",       new_function },
+    { "code",           new_code },
+    { "module",         new_module },
+    {NULL,		NULL}		/* sentinel */
+};
+
+void
+initnew()
+{
+    initmodule("new", new_methods);
+}