summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
committerGuido van Rossum <guido@python.org>1994-08-01 11:34:53 (GMT)
commitb6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af (patch)
tree9362939305b2d088b8f19a530c9015d886bc2801
parent2979b01ff88ac4c5b316d9bf98edbaaaffac8e24 (diff)
downloadcpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.zip
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.gz
cpython-b6775db241f5fe5e3dc2ca09fc6c9e6164d4b2af.tar.bz2
Merge alpha100 branch back to main trunk
-rw-r--r--Include/accessobject.h2
-rw-r--r--Include/allobjects.h8
-rw-r--r--Include/assert.h8
-rw-r--r--Include/bitset.h2
-rw-r--r--Include/bltinmodule.h3
-rw-r--r--Include/ceval.h9
-rw-r--r--Include/cgensupport.h4
-rw-r--r--Include/classobject.h2
-rw-r--r--Include/compile.h2
-rw-r--r--Include/dictobject.h2
-rw-r--r--Include/errcode.h12
-rwxr-xr-xInclude/errors.h7
-rw-r--r--Include/eval.h2
-rw-r--r--Include/fileobject.h3
-rw-r--r--Include/floatobject.h2
-rw-r--r--Include/frameobject.h14
-rw-r--r--Include/funcobject.h6
-rw-r--r--Include/grammar.h14
-rw-r--r--Include/import.h2
-rw-r--r--Include/intobject.h2
-rw-r--r--Include/intrcheck.h2
-rw-r--r--Include/listobject.h3
-rw-r--r--Include/longintrepr.h2
-rw-r--r--Include/longobject.h3
-rw-r--r--Include/mappingobject.h2
-rw-r--r--Include/marshal.h2
-rw-r--r--Include/metagrammar.h2
-rw-r--r--Include/methodobject.h2
-rw-r--r--Include/modsupport.h23
-rw-r--r--Include/moduleobject.h2
-rw-r--r--Include/mymalloc.h39
-rw-r--r--Include/myproto.h2
-rw-r--r--Include/myselect.h44
-rw-r--r--Include/mytime.h2
-rw-r--r--Include/node.h2
-rw-r--r--Include/object.h124
-rw-r--r--Include/objimpl.h2
-rw-r--r--Include/opcode.h4
-rw-r--r--Include/osdefs.h4
-rw-r--r--Include/parsetok.h16
-rw-r--r--Include/pgenheaders.h17
-rw-r--r--Include/pyerrors.h7
-rw-r--r--Include/pythonrun.h8
-rw-r--r--Include/pythread.h6
-rw-r--r--Include/rangeobject.h2
-rwxr-xr-xInclude/rename1.h2
-rw-r--r--Include/stringobject.h3
-rw-r--r--Include/structmember.h2
-rw-r--r--Include/sysmodule.h2
-rw-r--r--Include/thread.h6
-rw-r--r--Include/token.h2
-rw-r--r--Include/traceback.h2
-rw-r--r--Include/tupleobject.h2
-rw-r--r--Lib/UserList.py6
-rw-r--r--Lib/aifc.py5
-rw-r--r--Lib/audiodev.py55
-rw-r--r--Lib/bdb.py47
-rw-r--r--Lib/calendar.py7
-rw-r--r--Lib/cmd.py34
-rw-r--r--Lib/codehack.py4
-rw-r--r--Lib/dis.py4
-rw-r--r--Lib/ftplib.py113
-rwxr-xr-xLib/irix5/FCNTL.py58
-rwxr-xr-xLib/irix5/IN.py44
-rwxr-xr-xLib/irix5/SOCKET.py37
-rwxr-xr-xLib/irix5/cddb.py26
-rwxr-xr-xLib/irix5/flp.py8
-rw-r--r--Lib/lib-old/codehack.py4
-rw-r--r--Lib/lib-old/newdir.py8
-rw-r--r--Lib/lib-old/packmail.py24
-rw-r--r--Lib/lib-stdwin/WindowSched.py11
-rw-r--r--Lib/lib-stdwin/filewin.py6
-rw-r--r--Lib/lib-stdwin/wdb.py8
-rw-r--r--Lib/mimetools.py78
-rw-r--r--Lib/multifile.py11
-rw-r--r--Lib/newdir.py8
-rw-r--r--Lib/nntplib.py5
-rw-r--r--Lib/ospath.py18
-rw-r--r--Lib/packmail.py24
-rw-r--r--Lib/pdb.doc7
-rwxr-xr-xLib/pdb.py170
-rwxr-xr-xLib/plat-irix5/FCNTL.py58
-rwxr-xr-xLib/plat-irix5/IN.py44
-rwxr-xr-xLib/plat-irix5/SOCKET.py37
-rwxr-xr-xLib/plat-irix5/cddb.py26
-rwxr-xr-xLib/plat-irix5/flp.py8
-rwxr-xr-xLib/plat-sunos4/FCNTL.py9
-rwxr-xr-xLib/plat-sunos4/IN.py6
-rwxr-xr-xLib/plat-sunos4/SOCKET.py1
-rwxr-xr-xLib/plat-sunos4/WAIT.py13
-rwxr-xr-xLib/plat-sunos4/regen1
-rw-r--r--Lib/posixpath.py48
-rw-r--r--Lib/profile.doc776
-rwxr-xr-xLib/profile.py883
-rw-r--r--Lib/regexp.py8
-rw-r--r--Lib/repr.py13
-rw-r--r--Lib/rfc822.py216
-rw-r--r--Lib/sched.py11
-rwxr-xr-xLib/stdwin/WindowSched.py11
-rwxr-xr-xLib/stdwin/filewin.py6
-rwxr-xr-xLib/stdwin/wdb.py8
-rw-r--r--Lib/string.py75
-rw-r--r--Lib/stringold.py75
-rwxr-xr-xLib/sunos4/FCNTL.py9
-rwxr-xr-xLib/sunos4/IN.py6
-rwxr-xr-xLib/sunos4/SOCKET.py1
-rwxr-xr-xLib/sunos4/WAIT.py13
-rwxr-xr-xLib/sunos4/regen1
-rwxr-xr-xLib/symbol.py86
-rw-r--r--Lib/test/test_b1.py24
-rw-r--r--Lib/test/test_b2.py19
-rw-r--r--Lib/test/test_grammar.py120
-rw-r--r--Lib/test/test_types.py6
-rw-r--r--Lib/test/testall.out11
-rw-r--r--Lib/tzparse.py4
-rw-r--r--Lib/whrandom.py14
-rw-r--r--Modules/Makefile.pre.in119
-rw-r--r--Modules/Setup.in111
-rw-r--r--Modules/almodule.c81
-rw-r--r--Modules/arraymodule.c145
-rw-r--r--Modules/audioop.c175
-rw-r--r--Modules/cdmodule.c64
-rw-r--r--Modules/cgen.py23
-rw-r--r--Modules/cgensupport.h4
-rw-r--r--Modules/clmodule.c8
-rw-r--r--Modules/config.c.in454
-rw-r--r--Modules/cstubs24
-rw-r--r--Modules/dbmmodule.c36
-rw-r--r--Modules/fcntlmodule.c2
-rw-r--r--Modules/flmodule.c272
-rw-r--r--Modules/fmmodule.c38
-rw-r--r--Modules/imageop.c16
-rw-r--r--Modules/imgfile.c2
-rwxr-xr-xModules/makesetup127
-rw-r--r--Modules/mathmodule.c16
-rw-r--r--Modules/md5.h3
-rw-r--r--Modules/md5c.c3
-rw-r--r--Modules/md5module.c148
-rw-r--r--Modules/mpzmodule.c40
-rw-r--r--Modules/nismodule.c23
-rw-r--r--Modules/parsermodule.c10
-rw-r--r--Modules/posixmodule.c424
-rw-r--r--Modules/pwdmodule.c100
-rw-r--r--Modules/regexmodule.c210
-rw-r--r--Modules/regexpr.c8
-rw-r--r--Modules/regexpr.h10
-rw-r--r--Modules/rgbimgmodule.c8
-rw-r--r--Modules/rotormodule.c44
-rw-r--r--Modules/selectmodule.c15
-rw-r--r--Modules/sgimodule.c2
-rw-r--r--Modules/signalmodule.c14
-rw-r--r--Modules/socketmodule.c115
-rw-r--r--Modules/stdwinmodule.c226
-rw-r--r--Modules/stropmodule.c115
-rw-r--r--Modules/structmodule.c2
-rw-r--r--Modules/sunaudiodev.c44
-rw-r--r--Modules/svmodule.c96
-rw-r--r--Modules/threadmodule.c78
-rw-r--r--Modules/timemodule.c405
-rw-r--r--Modules/version.c396
-rw-r--r--Modules/yuv.h24
-rw-r--r--Modules/yuvconvert.c24
-rw-r--r--Objects/Makefile.in42
-rw-r--r--Objects/accessobject.c10
-rw-r--r--Objects/classobject.c102
-rw-r--r--Objects/fileobject.c104
-rw-r--r--Objects/floatobject.c79
-rw-r--r--Objects/xxobject.c14
-rw-r--r--Parser/Makefile.in49
-rw-r--r--Parser/assert.h8
-rw-r--r--Parser/myreadline.c77
-rw-r--r--Python/Makefile.in78
-rw-r--r--Python/dup2.c5
-rw-r--r--Python/getmtime.c10
-rw-r--r--Python/memmove.c2
-rw-r--r--Python/mystrtoul.c16
176 files changed, 5230 insertions, 3596 deletions
diff --git a/Include/accessobject.h b/Include/accessobject.h
index 31b7190..fd8c2e9 100644
--- a/Include/accessobject.h
+++ b/Include/accessobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/allobjects.h b/Include/allobjects.h
index 17d6dd2..2b361c1 100644
--- a/Include/allobjects.h
+++ b/Include/allobjects.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -30,6 +30,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* "allobjects.c" -- Source for precompiled header "allobjects.h" */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#ifdef THINK_C
#define macintosh
#endif
@@ -37,7 +41,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <stdio.h>
#include <string.h>
-#include "PROTO.h"
+#include "myproto.h"
#include "object.h"
#include "objimpl.h"
diff --git a/Include/assert.h b/Include/assert.h
index dbce369..d007eca 100644
--- a/Include/assert.h
+++ b/Include/assert.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,7 +28,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+#ifdef MPW /* This is for MPW's File command */
+
+#define assert(e) { if (!(e)) { printf("### Python: Assertion failed:\n\
+ File %s; Line %d\n", __FILE__, __LINE__); abort(); } }
+#else
#define assert(e) { if (!(e)) { printf("Assertion failed\n"); abort(); } }
+#endif
#ifdef __cplusplus
}
diff --git a/Include/bitset.h b/Include/bitset.h
index f7dbe8f..6fa5be6 100644
--- a/Include/bitset.h
+++ b/Include/bitset.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/bltinmodule.h b/Include/bltinmodule.h
index 0c8ecc2..e4f47e0 100644
--- a/Include/bltinmodule.h
+++ b/Include/bltinmodule.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -31,6 +31,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Built-in module interface */
extern object *getbuiltin PROTO((object *));
+extern int setbuiltin PROTO((char *, object *));
#ifdef __cplusplus
}
diff --git a/Include/ceval.h b/Include/ceval.h
index 1c830c3..3b16085 100644
--- a/Include/ceval.h
+++ b/Include/ceval.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,6 +35,7 @@ object *call_object PROTO((object *, object *));
object *getglobals PROTO((void));
object *getlocals PROTO((void));
object *getowner PROTO((void));
+object *getframe PROTO((void));
void printtraceback PROTO((object *));
void flushline PROTO((void));
@@ -87,7 +88,7 @@ extern void init_save_thread PROTO((void));
extern object *save_thread PROTO((void));
extern void restore_thread PROTO((object *));
-#ifdef USE_THREAD
+#ifdef WITH_THREAD
#define BGN_SAVE { \
object *_save; \
@@ -97,14 +98,14 @@ extern void restore_thread PROTO((object *));
#define END_SAVE restore_thread(_save); \
}
-#else /* !USE_THREAD */
+#else /* !WITH_THREAD */
#define BGN_SAVE {
#define RET_SAVE
#define RES_SAVE
#define END_SAVE }
-#endif /* !USE_THREAD */
+#endif /* !WITH_THREAD */
#ifdef __cplusplus
}
diff --git a/Include/cgensupport.h b/Include/cgensupport.h
index 8472b03..4b295b3 100644
--- a/Include/cgensupport.h
+++ b/Include/cgensupport.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,7 +35,7 @@ typedef char *string;
#define mknewlongobject(x) newintobject(x)
#define mknewshortobject(x) newintobject((long)x)
#define mknewfloatobject(x) newfloatobject(x)
-#define mknewcharobject(c) mkvalue("c", c)
+#define mknewcharobject(ch) mkvalue("c", ch)
extern int getiobjectarg PROTO((object *args, int nargs, int i, object **p_a));
extern int getilongarg PROTO((object *args, int nargs, int i, long *p_a));
diff --git a/Include/classobject.h b/Include/classobject.h
index a244ef8..bd6cc1d 100644
--- a/Include/classobject.h
+++ b/Include/classobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/compile.h b/Include/compile.h
index a23fea1..4526523 100644
--- a/Include/compile.h
+++ b/Include/compile.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/dictobject.h b/Include/dictobject.h
index f1df1ef..4afed79 100644
--- a/Include/dictobject.h
+++ b/Include/dictobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/errcode.h b/Include/errcode.h
index d2a2ac6..e8db943 100644
--- a/Include/errcode.h
+++ b/Include/errcode.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -29,11 +29,15 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
/* Error codes passed around between file input, tokenizer, parser and
- interpreter. This was necessary so we can turn them into Python
- exceptions at a higher level. */
+ interpreter. This is necessary so we can turn them into Python
+ exceptions at a higher level. Note that some errors have a
+ slightly different meaning when passed from the tokenizer to the
+ parser than when passed from the parser to the interpreter; e.g.
+ the parser only returns E_EOF when it hits EOF immediately, and it
+ never returns E_OK. */
#define E_OK 10 /* No error */
-#define E_EOF 11 /* (Unexpected) EOF read */
+#define E_EOF 11 /* End Of File */
#define E_INTR 12 /* Interrupted */
#define E_TOKEN 13 /* Bad token */
#define E_SYNTAX 14 /* Syntax error */
diff --git a/Include/errors.h b/Include/errors.h
index 2444ee1..050ff19 100755
--- a/Include/errors.h
+++ b/Include/errors.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -33,7 +33,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
void err_set PROTO((object *));
void err_setval PROTO((object *, object *));
void err_setstr PROTO((object *, char *));
-int err_occurred PROTO((void));
+object *err_occurred PROTO((void));
void err_get PROTO((object **, object **));
void err_clear PROTO((void));
@@ -64,12 +64,13 @@ extern object *ZeroDivisionError;
extern int err_badarg PROTO((void));
extern object *err_nomem PROTO((void));
extern object *err_errno PROTO((object *));
-extern void err_input PROTO((int));
extern void err_badcall PROTO((void));
extern object *err_getexc PROTO((void));
+extern int sigcheck PROTO((void)); /* In sigcheck.c or signalmodule.c */
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/eval.h b/Include/eval.h
index 91e2374..ed33d44 100644
--- a/Include/eval.h
+++ b/Include/eval.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/fileobject.h b/Include/fileobject.h
index 00e4ca9..c52a6aa 100644
--- a/Include/fileobject.h
+++ b/Include/fileobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,6 +35,7 @@ extern typeobject Filetype;
#define is_fileobject(op) ((op)->ob_type == &Filetype)
extern object *newfileobject PROTO((char *, char *));
+extern void setfilebufsize PROTO((object *, int));
extern object *newopenfileobject
PROTO((FILE *, char *, char *, int (*)FPROTO((FILE *))));
extern FILE *getfilefile PROTO((object *));
diff --git a/Include/floatobject.h b/Include/floatobject.h
index dad1fe1..1d0484f 100644
--- a/Include/floatobject.h
+++ b/Include/floatobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/frameobject.h b/Include/frameobject.h
index 5eeb2ad..2458881 100644
--- a/Include/frameobject.h
+++ b/Include/frameobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -52,6 +52,7 @@ typedef struct _frame {
int f_iblock; /* index in f_blockstack */
int f_lasti; /* Last instruction if called */
int f_lineno; /* Current line number */
+ object *f_trace; /* Trace function */
} frameobject;
@@ -70,11 +71,11 @@ frameobject * newframeobject PROTO(
/* List access macros */
#ifdef NDEBUG
-#define GETITEM(v, i) GETLISTITEM((listobject *)(v), (i))
+#define GETITEM(v, i) GETTUPLEITEM((tupleobject *)(v), (i))
#define GETITEMNAME(v, i) GETSTRINGVALUE((stringobject *)GETITEM((v), (i)))
#else
-#define GETITEM(v, i) getlistitem((v), (i))
-#define GETITEMNAME(v, i) getstringvalue(getlistitem((v), (i)))
+#define GETITEM(v, i) gettupleitem((v), (i))
+#define GETITEMNAME(v, i) getstringvalue(GETITEM(v, i))
#endif
#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s))
@@ -95,6 +96,11 @@ block *pop_block PROTO((frameobject *));
object **extend_stack PROTO((frameobject *, int, int));
+/* Conversions between "fast locals" and locals in dictionary */
+
+void locals_2_fast PROTO((frameobject *, int));
+void fast_2_locals PROTO((frameobject *));
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/funcobject.h b/Include/funcobject.h
index ffe2996..84b0dcf 100644
--- a/Include/funcobject.h
+++ b/Include/funcobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,6 +35,8 @@ typedef struct {
object *func_code;
object *func_globals;
object *func_name;
+ int func_argcount;
+ object *func_argdefs;
} funcobject;
extern typeobject Functype;
@@ -44,6 +46,8 @@ extern typeobject Functype;
extern object *newfuncobject PROTO((object *, object *));
extern object *getfunccode PROTO((object *));
extern object *getfuncglobals PROTO((object *));
+extern object *getfuncargstuff PROTO((object *, int *));
+extern int setfuncargstuff PROTO((object *, int, object *));
#ifdef __cplusplus
}
diff --git a/Include/grammar.h b/Include/grammar.h
index 506304f..f2e008f 100644
--- a/Include/grammar.h
+++ b/Include/grammar.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -34,7 +34,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* A label of an arc */
-typedef struct _label {
+typedef struct {
int lb_type;
char *lb_str;
} label;
@@ -43,21 +43,21 @@ typedef struct _label {
/* A list of labels */
-typedef struct _labellist {
+typedef struct {
int ll_nlabels;
label *ll_label;
} labellist;
/* An arc from one state to another */
-typedef struct _arc {
+typedef struct {
short a_lbl; /* Label of this arc */
short a_arrow; /* State where this arc goes to */
} arc;
/* A state in a DFA */
-typedef struct _state {
+typedef struct {
int s_narcs;
arc *s_arc; /* Array of arcs */
@@ -70,7 +70,7 @@ typedef struct _state {
/* A DFA */
-typedef struct _dfa {
+typedef struct {
int d_type; /* Non-terminal this represents */
char *d_name; /* For printing */
int d_initial; /* Initial state */
@@ -81,7 +81,7 @@ typedef struct _dfa {
/* A grammar */
-typedef struct _grammar {
+typedef struct {
int g_ndfas;
dfa *g_dfa; /* Array of DFAs */
labellist g_ll;
diff --git a/Include/import.h b/Include/import.h
index d960c9f..c335995 100644
--- a/Include/import.h
+++ b/Include/import.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/intobject.h b/Include/intobject.h
index 7b778e9..2ede41e 100644
--- a/Include/intobject.h
+++ b/Include/intobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/intrcheck.h b/Include/intrcheck.h
index 7f1b526..2914a6a 100644
--- a/Include/intrcheck.h
+++ b/Include/intrcheck.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/listobject.h b/Include/listobject.h
index 7af8058..610096b 100644
--- a/Include/listobject.h
+++ b/Include/listobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -62,6 +62,7 @@ extern int addlistitem PROTO((object *, object *));
extern object *getlistslice PROTO((object *, int, int));
extern int setlistslice PROTO((object *, int, int, object *));
extern int sortlist PROTO((object *));
+extern object *listtuple PROTO((object *));
/* Macro, trading safety for speed */
#define GETLISTITEM(op, i) ((op)->ob_item[i])
diff --git a/Include/longintrepr.h b/Include/longintrepr.h
index 2188153..b8d279d 100644
--- a/Include/longintrepr.h
+++ b/Include/longintrepr.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/longobject.h b/Include/longobject.h
index 1b048fd..ce2cd0b 100644
--- a/Include/longobject.h
+++ b/Include/longobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -42,6 +42,7 @@ extern long getlongvalue PROTO((object *));
extern double dgetlongvalue PROTO((object *));
object *long_scan PROTO((char *, int));
+object *long_escan PROTO((char *, char **, int));
#ifdef __cplusplus
}
diff --git a/Include/mappingobject.h b/Include/mappingobject.h
index 7d006dd..8844c77 100644
--- a/Include/mappingobject.h
+++ b/Include/mappingobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/marshal.h b/Include/marshal.h
index 7823f5c..e086e84 100644
--- a/Include/marshal.h
+++ b/Include/marshal.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/metagrammar.h b/Include/metagrammar.h
index d22f458..8248aed 100644
--- a/Include/metagrammar.h
+++ b/Include/metagrammar.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/methodobject.h b/Include/methodobject.h
index 0252334..1ef19aa 100644
--- a/Include/methodobject.h
+++ b/Include/methodobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/modsupport.h b/Include/modsupport.h
index f476f13..a1f3f1c 100644
--- a/Include/modsupport.h
+++ b/Include/modsupport.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -30,22 +30,29 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Module support interface */
-#ifdef HAVE_PROTOTYPES
-#define USE_STDARG
-#endif
+#ifdef HAVE_STDARG_PROTOTYPES
-#ifdef USE_STDARG
#include <stdarg.h>
+
+extern int getargs PROTO((object *, char *, ...));
+extern object *mkvalue PROTO((char *, ...));
+
#else
+
#include <varargs.h>
+
+/* Better to have no prototypes at all for varargs functions in this case */
+extern int getargs();
+extern object *mkvalue();
+
#endif
-extern object *initmodule PROTO((char *, struct methodlist *));
-extern int getargs PROTO((object *, char *, ...));
extern int vgetargs PROTO((object *, char *, va_list));
-extern object *mkvalue PROTO((char *, ...));
extern object *vmkvalue PROTO((char *, va_list));
+extern object *initmodule PROTO((char *, struct methodlist *));
+extern object *initmodule2 PROTO((char *, struct methodlist *, object *));
+
/* The following are obsolete -- use getargs directly! */
#define getnoarg(v) getargs(v, "")
#define getintarg(v, a) getargs(v, "i", a)
diff --git a/Include/moduleobject.h b/Include/moduleobject.h
index b4c0cdf..0605d31 100644
--- a/Include/moduleobject.h
+++ b/Include/moduleobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/mymalloc.h b/Include/mymalloc.h
index 24e2125..ea676c3 100644
--- a/Include/mymalloc.h
+++ b/Include/mymalloc.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -32,41 +32,35 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef macintosh
#define ANY void
-#ifndef THINK_C_3_0
-#define HAVE_STDLIB
-#endif
-#endif
-
-#ifdef sun
-/* Maybe not for very old versions of SunOS ? */
-#define HAVE_STDLIB
-#endif
-
-#ifdef sgi
-#define HAVE_STDLIB
#endif
#ifdef __STDC__
#define ANY void
-#define HAVE_STDLIB
#endif
#ifdef __TURBOC__
#define ANY void
-#define HAVE_STDLIB
#endif
#ifdef __GNUC__
#define ANY void
-#define HAVE_STDLIB
#endif
#ifndef ANY
#define ANY char
#endif
+#ifdef HAVE_STDLIB_H
+#include <stdlib.h>
+#else /* !HAVE_STDLIB */
+extern ANY *malloc PROTO((size_t));
+extern ANY *calloc PROTO((size_t, size_t));
+extern ANY *realloc PROTO((ANY *, size_t));
+extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
+#endif /* !HAVE_STDLIB */
+
#ifndef NULL
-#define NULL 0
+#define NULL ((ANY *)0)
#endif
/* XXX Always allocate one extra byte, since some malloc's return NULL
@@ -80,17 +74,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define DEL(p) free((ANY *)p)
#define XDEL(p) if ((p) == NULL) ; else DEL(p)
-#ifdef HAVE_STDLIB
-#include <stdlib.h>
-#define MALLARG size_t
-#else
-#define MALLARG size_t
-extern ANY *malloc PROTO((MALLARG));
-extern ANY *calloc PROTO((MALLARG, MALLARG));
-extern ANY *realloc PROTO((ANY *, MALLARG));
-extern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
-#endif
-
#ifdef __cplusplus
}
#endif
diff --git a/Include/myproto.h b/Include/myproto.h
index e6de60e..6862755 100644
--- a/Include/myproto.h
+++ b/Include/myproto.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/myselect.h b/Include/myselect.h
index 174da11..e4f2b28 100644
--- a/Include/myselect.h
+++ b/Include/myselect.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,38 +28,28 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
-/* Common definitions for files that use the BSD select system call.
- This is so complicated because every UNIX variant requires that
- you include a different set of headers. Customizing this one file
- should be easier than patching each of the files using select()... */
+/* Include file for users of select() */
+/* NB caller must include <sys/types.h> */
-/* XXX You may have to include some of these only if not already included */
-#include <sys/types.h>
-#include <sys/time.h> /* Implies <time.h> everywhere, as far as I know */
-#include <sys/param.h>
+#ifdef HAVE_SYS_SELECT_H
-
-/* Hacks for various systems that need hand-holding... */
-
-#ifdef _SEQUENT_
#include <sys/select.h>
-/* Sequent doesn't seem to define struct timezone anywhere?!?! */
-struct timezone {
- int tz_minuteswest;
- int tz_dsttime;
-};
-#endif
-#ifdef _AIX /* I *think* this works */
-/* AIX defines fd_set in a separate file. Sigh... */
-#include <sys/select.h>
-#endif
+#ifdef SYS_SELECT_WITH_SYS_TIME
+#include "mytime.h"
+#else /* !SYS_SELECT_WITH_SYS_TIME */
+#include <time.h>
+#endif /* !SYS_SELECT_WITH_SYS_TIME */
+
+#else /* !HAVE_SYS_SELECT_H */
+#include "mytime.h"
+#endif /* !HAVE_SYS_SELECT_H */
-/* (Very) old versions of BSD don't define the FD_* set of macros.
- The following will usually do... */
+/* If the fd manipulation macros aren't defined,
+ here is a set that should do the job */
#ifndef FD_SETSIZE
#define FD_SETSIZE 256
@@ -67,12 +57,12 @@ struct timezone {
#ifndef FD_SET
-typedef long fd_mask;
+typedef long fd_mask;
#define NFDBITS (sizeof(fd_mask) * NBBY) /* bits per mask */
#ifndef howmany
#define howmany(x, y) (((x)+((y)-1))/(y))
-#endif
+#endif /* howmany */
typedef struct fd_set {
fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)];
diff --git a/Include/mytime.h b/Include/mytime.h
index fd263d6..e175d5a 100644
--- a/Include/mytime.h
+++ b/Include/mytime.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/node.h b/Include/node.h
index 84238df..24019a6 100644
--- a/Include/node.h
+++ b/Include/node.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/object.h b/Include/object.h
index 24989bf..416ca77 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -133,48 +133,66 @@ NB: the methods for certain type groups are now contained in separate
method blocks.
*/
+typedef object * (*unaryfunc) PROTO((object *));
+typedef object * (*binaryfunc) PROTO((object *, object *));
+typedef int (*inquiry) PROTO((object *));
+typedef int (*coercion) PROTO((object **, object **));
+typedef object *(*intargfunc) PROTO((object *, int));
+typedef object *(*intintargfunc) PROTO((object *, int, int));
+typedef int(*intobjargproc) PROTO((object *, int, object *));
+typedef int(*intintobjargproc) PROTO((object *, int, int, object *));
+typedef int(*objobjargproc) PROTO((object *, object *, object *));
+
typedef struct {
- object *(*nb_add) FPROTO((object *, object *));
- object *(*nb_subtract) FPROTO((object *, object *));
- object *(*nb_multiply) FPROTO((object *, object *));
- object *(*nb_divide) FPROTO((object *, object *));
- object *(*nb_remainder) FPROTO((object *, object *));
- object *(*nb_divmod) FPROTO((object *, object *));
- object *(*nb_power) FPROTO((object *, object *));
- object *(*nb_negative) FPROTO((object *));
- object *(*nb_positive) FPROTO((object *));
- object *(*nb_absolute) FPROTO((object *));
- int (*nb_nonzero) FPROTO((object *));
- object *(*nb_invert) FPROTO((object *));
- object *(*nb_lshift) FPROTO((object *, object *));
- object *(*nb_rshift) FPROTO((object *, object *));
- object *(*nb_and) FPROTO((object *, object *));
- object *(*nb_xor) FPROTO((object *, object *));
- object *(*nb_or) FPROTO((object *, object *));
- int (*nb_coerce) FPROTO((object **, object **));
- object *(*nb_int) FPROTO((object *));
- object *(*nb_long) FPROTO((object *));
- object *(*nb_float) FPROTO((object *));
- object *(*nb_oct) FPROTO((object *));
- object *(*nb_hex) FPROTO((object *));
+ binaryfunc nb_add;
+ binaryfunc nb_subtract;
+ binaryfunc nb_multiply;
+ binaryfunc nb_divide;
+ binaryfunc nb_remainder;
+ binaryfunc nb_divmod;
+ binaryfunc nb_power;
+ unaryfunc nb_negative;
+ unaryfunc nb_positive;
+ unaryfunc nb_absolute;
+ inquiry nb_nonzero;
+ unaryfunc nb_invert;
+ binaryfunc nb_lshift;
+ binaryfunc nb_rshift;
+ binaryfunc nb_and;
+ binaryfunc nb_xor;
+ binaryfunc nb_or;
+ coercion nb_coerce;
+ unaryfunc nb_int;
+ unaryfunc nb_long;
+ unaryfunc nb_float;
+ unaryfunc nb_oct;
+ unaryfunc nb_hex;
} number_methods;
typedef struct {
- int (*sq_length) FPROTO((object *));
- object *(*sq_concat) FPROTO((object *, object *));
- object *(*sq_repeat) FPROTO((object *, int));
- object *(*sq_item) FPROTO((object *, int));
- object *(*sq_slice) FPROTO((object *, int, int));
- int (*sq_ass_item) FPROTO((object *, int, object *));
- int (*sq_ass_slice) FPROTO((object *, int, int, object *));
+ inquiry sq_length;
+ binaryfunc sq_concat;
+ intargfunc sq_repeat;
+ intargfunc sq_item;
+ intintargfunc sq_slice;
+ intobjargproc sq_ass_item;
+ intintobjargproc sq_ass_slice;
} sequence_methods;
typedef struct {
- int (*mp_length) FPROTO((object *));
- object *(*mp_subscript) FPROTO((object *, object *));
- int (*mp_ass_subscript) FPROTO((object *, object *, object *));
+ inquiry mp_length;
+ binaryfunc mp_subscript;
+ objobjargproc mp_ass_subscript;
} mapping_methods;
+typedef void (*destructor) PROTO((object *));
+typedef int (*printfunc) PROTO((object *, FILE *, int));
+typedef object *(*getattrfunc) PROTO((object *, char *));
+typedef int (*setattrfunc) PROTO((object *, char *, object *));
+typedef int (*cmpfunc) PROTO((object *, object *));
+typedef object *(*reprfunc) PROTO((object *));
+typedef long (*hashfunc) PROTO((object *));
+
typedef struct _typeobject {
OB_VARHEAD
char *tp_name; /* For printing */
@@ -182,12 +200,12 @@ typedef struct _typeobject {
/* Methods to implement standard operations */
- void (*tp_dealloc) FPROTO((object *));
- int (*tp_print) FPROTO((object *, FILE *, int));
- object *(*tp_getattr) FPROTO((object *, char *));
- int (*tp_setattr) FPROTO((object *, char *, object *));
- int (*tp_compare) FPROTO((object *, object *));
- object *(*tp_repr) FPROTO((object *));
+ destructor tp_dealloc;
+ printfunc tp_print;
+ getattrfunc tp_getattr;
+ setattrfunc tp_setattr;
+ cmpfunc tp_compare;
+ reprfunc tp_repr;
/* Method suites for standard classes */
@@ -197,7 +215,8 @@ typedef struct _typeobject {
/* More standard operations (at end for binary compatibility) */
- long (*tp_hash) FPROTO((object *));
+ hashfunc tp_hash;
+ binaryfunc tp_call;
#ifdef COUNT_ALLOCS
/* these must be last */
int tp_alloc;
@@ -327,6 +346,29 @@ extern object NoObject; /* Don't use this directly */
/*
+A common programming style in Python requires the forward declaration
+of static, initialized structures, e.g. for a typeobject that is used
+by the functions whose address must be used in the initializer.
+Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as
+well) botch this if you use the static keyword for both declarations
+(they allocate two objects, and use the first, uninitialized one until
+the second declaration is encountered). Therefore, the forward
+declaration should use the 'forwardstatic' keyword. This expands to
+static on most systems, but to extern on a few. The actual storage
+and name will still be static because the second declaration is
+static, so no linker visible symbols will be generated. (Standard C
+compilers take offense to the extern forward declaration of a static
+object, so I can't just put extern in all cases. :-( )
+*/
+
+#ifdef BAD_STATIC_FORWARD
+#define staticforward extern
+#else
+#define staticforward static
+#endif /* BAD_STATIC_FORWARD */
+
+
+/*
123456789-123456789-123456789-123456789-123456789-123456789-123456789-12
More conventions
diff --git a/Include/objimpl.h b/Include/objimpl.h
index 25f8b94..c904cf8 100644
--- a/Include/objimpl.h
+++ b/Include/objimpl.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/opcode.h b/Include/opcode.h
index 53ce333..b6a42cc 100644
--- a/Include/opcode.h
+++ b/Include/opcode.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -119,6 +119,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define LOAD_LOCAL 115 /* Index in name list */
#define LOAD_GLOBAL 116 /* Index in name list */
+#define SET_FUNC_ARGS 117 /* Argcount */
+
#define SETUP_LOOP 120 /* Target address (absolute) */
#define SETUP_EXCEPT 121 /* "" */
#define SETUP_FINALLY 122 /* "" */
diff --git a/Include/osdefs.h b/Include/osdefs.h
index 5ff75ba..c84043f 100644
--- a/Include/osdefs.h
+++ b/Include/osdefs.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -36,7 +36,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define DELIM ' '
#endif
-#ifdef MSDOS
+#if defined(MSDOS) || defined(NT)
#define SEP '\\'
#define MAXPATHLEN 256
#define DELIM ';'
diff --git a/Include/parsetok.h b/Include/parsetok.h
index 9150cd6..b27cf4e 100644
--- a/Include/parsetok.h
+++ b/Include/parsetok.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -30,9 +30,17 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Parser-tokenizer link interface */
-extern int parsestring PROTO((char *, grammar *, int, node **_ret));
-extern int parsefile PROTO((FILE *, char *, grammar *, int,
- char *, char *, node **));
+typedef struct {
+ int error;
+ char *filename;
+ int lineno;
+ int offset;
+ char *text;
+} perrdetail;
+
+extern node *parsestring PROTO((char *, grammar *, int, perrdetail *));
+extern node *parsefile PROTO((FILE *, char *, grammar *, int,
+ char *, char *, perrdetail *));
#ifdef __cplusplus
}
diff --git a/Include/pgenheaders.h b/Include/pgenheaders.h
index 8395960..8a0b079 100644
--- a/Include/pgenheaders.h
+++ b/Include/pgenheaders.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -31,9 +31,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Include files and extern declarations used by most of the parser.
This is a precompiled header for THINK C. */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#ifdef THINK_C
#define macintosh
-/* #define THINK_C_3_0 /*** TURN THIS ON FOR THINK C 3.0 ***/
#endif
#include <stdio.h>
@@ -44,17 +47,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#undef label
#endif
-#ifdef THINK_C_3_0
-#include <proto.h>
-#endif
-
-#ifdef macintosh
-#ifndef THINK_C_3_0
+#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
-#endif
-#include "PROTO.h"
+#include "myproto.h"
#include "mymalloc.h"
extern void fatal PROTO((char *));
diff --git a/Include/pyerrors.h b/Include/pyerrors.h
index 2444ee1..050ff19 100644
--- a/Include/pyerrors.h
+++ b/Include/pyerrors.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -33,7 +33,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
void err_set PROTO((object *));
void err_setval PROTO((object *, object *));
void err_setstr PROTO((object *, char *));
-int err_occurred PROTO((void));
+object *err_occurred PROTO((void));
void err_get PROTO((object **, object **));
void err_clear PROTO((void));
@@ -64,12 +64,13 @@ extern object *ZeroDivisionError;
extern int err_badarg PROTO((void));
extern object *err_nomem PROTO((void));
extern object *err_errno PROTO((object *));
-extern void err_input PROTO((int));
extern void err_badcall PROTO((void));
extern object *err_getexc PROTO((void));
+extern int sigcheck PROTO((void)); /* In sigcheck.c or signalmodule.c */
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/pythonrun.h b/Include/pythonrun.h
index e25a3de..1f357cd 100644
--- a/Include/pythonrun.h
+++ b/Include/pythonrun.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -39,8 +39,8 @@ int run_script PROTO((FILE *, char *));
int run_tty_1 PROTO((FILE *, char *));
int run_tty_loop PROTO((FILE *, char *));
-int parse_string PROTO((char *, int, struct _node **));
-int parse_file PROTO((FILE *, char *, int, struct _node **));
+struct _node *parse_string PROTO((char *, int));
+struct _node *parse_file PROTO((FILE *, char *, int));
object *run_string PROTO((char *, int, object *, object *));
object *run_file PROTO((FILE *, char *, int, object *, object *));
@@ -51,6 +51,8 @@ void print_error PROTO((void));
void goaway PROTO((int));
+void cleanup PROTO((void));
+
#ifdef __cplusplus
}
#endif
diff --git a/Include/pythread.h b/Include/pythread.h
index 806882f..680b7fb 100644
--- a/Include/pythread.h
+++ b/Include/pythread.h
@@ -1,6 +1,9 @@
#ifndef _THREAD_H_included
#define _THREAD_H_included
+#define NO_EXIT_PROG /* don't define exit_prog() */
+ /* (the result is no use of signals on SGI) */
+
#ifndef PROTO
#if defined(__STDC__) || defined(__cplusplus)
#define PROTO(args) args
@@ -20,6 +23,7 @@ void init_thread PROTO((void));
int start_new_thread PROTO((void (*)(void *), void *));
void exit_thread PROTO((void));
void _exit_thread PROTO((void));
+long get_thread_ident PROTO((void));
type_lock allocate_lock PROTO((void));
void free_lock PROTO((type_lock));
@@ -33,8 +37,10 @@ void free_sema PROTO((type_sema));
void down_sema PROTO((type_sema));
void up_sema PROTO((type_sema));
+#ifndef NO_EXIT_PROG
void exit_prog PROTO((int));
void _exit_prog PROTO((int));
+#endif
#ifdef __cplusplus
}
diff --git a/Include/rangeobject.h b/Include/rangeobject.h
index 39d20c6..9befd9b 100644
--- a/Include/rangeobject.h
+++ b/Include/rangeobject.h
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/rename1.h b/Include/rename1.h
index cfad02b..1e944a0 100755
--- a/Include/rename1.h
+++ b/Include/rename1.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/stringobject.h b/Include/stringobject.h
index fa2e8a1..6896a55 100644
--- a/Include/stringobject.h
+++ b/Include/stringobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -66,6 +66,7 @@ extern object *newstringobject PROTO((char *));
extern unsigned int getstringsize PROTO((object *));
extern char *getstringvalue PROTO((object *));
extern void joinstring PROTO((object **, object *));
+extern void joinstring_decref PROTO((object **, object *));
extern int resizestring PROTO((object **, int));
extern object *formatstring PROTO((object *, object *));
diff --git a/Include/structmember.h b/Include/structmember.h
index 2462aa7..6bd9e72 100644
--- a/Include/structmember.h
+++ b/Include/structmember.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/sysmodule.h b/Include/sysmodule.h
index f6e4d08..93e3a51 100644
--- a/Include/sysmodule.h
+++ b/Include/sysmodule.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/thread.h b/Include/thread.h
index 806882f..680b7fb 100644
--- a/Include/thread.h
+++ b/Include/thread.h
@@ -1,6 +1,9 @@
#ifndef _THREAD_H_included
#define _THREAD_H_included
+#define NO_EXIT_PROG /* don't define exit_prog() */
+ /* (the result is no use of signals on SGI) */
+
#ifndef PROTO
#if defined(__STDC__) || defined(__cplusplus)
#define PROTO(args) args
@@ -20,6 +23,7 @@ void init_thread PROTO((void));
int start_new_thread PROTO((void (*)(void *), void *));
void exit_thread PROTO((void));
void _exit_thread PROTO((void));
+long get_thread_ident PROTO((void));
type_lock allocate_lock PROTO((void));
void free_lock PROTO((type_lock));
@@ -33,8 +37,10 @@ void free_sema PROTO((type_sema));
void down_sema PROTO((type_sema));
void up_sema PROTO((type_sema));
+#ifndef NO_EXIT_PROG
void exit_prog PROTO((int));
void _exit_prog PROTO((int));
+#endif
#ifdef __cplusplus
}
diff --git a/Include/token.h b/Include/token.h
index 6939cc8..9281773 100644
--- a/Include/token.h
+++ b/Include/token.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/traceback.h b/Include/traceback.h
index 07c0c1e..f86306d 100644
--- a/Include/traceback.h
+++ b/Include/traceback.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Include/tupleobject.h b/Include/tupleobject.h
index 9897f6d..b422a40 100644
--- a/Include/tupleobject.h
+++ b/Include/tupleobject.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Lib/UserList.py b/Lib/UserList.py
index 9fbcc02..1c8a622 100644
--- a/Lib/UserList.py
+++ b/Lib/UserList.py
@@ -1,11 +1,9 @@
# A more or less complete user-defined wrapper around list objects
class UserList:
- def __init__(self, *args):
- if len(args) > 1: raise TypeError, 'too many args'
+ def __init__(self, list = None):
self.data = []
- if args:
- list = args[0]
+ if list is not None:
if type(list) == type(self.data):
self.data[:] = list
else:
diff --git a/Lib/aifc.py b/Lib/aifc.py
index aa1e56c..c1418be 100644
--- a/Lib/aifc.py
+++ b/Lib/aifc.py
@@ -179,7 +179,10 @@ def _read_short(file):
def _read_string(file):
length = ord(file.read(1))
- data = file.read(length)
+ if length == 0:
+ data = ''
+ else:
+ data = file.read(length)
if length & 1 == 0:
dummy = file.read(1)
return data
diff --git a/Lib/audiodev.py b/Lib/audiodev.py
index d0dcfed..02d63f7 100644
--- a/Lib/audiodev.py
+++ b/Lib/audiodev.py
@@ -1,28 +1,40 @@
-import AL, SUNAUDIODEV
-
error = 'audiodev.error'
class Play_Audio_sgi:
# Private instance variables
access frameratelist, nchannelslist, sampwidthlist, oldparams, \
params, config, inited_outrate, inited_width, \
- inited_nchannels, port, converter: private
-
- frameratelist = [(48000, AL.RATE_48000),
- (44100, AL.RATE_44100),
- (32000, AL.RATE_32000),
- (22050, AL.RATE_22050),
- (16000, AL.RATE_16000),
- (11025, AL.RATE_11025),
- ( 8000, AL.RATE_8000)]
- nchannelslist = [(1, AL.MONO),
- (2, AL.STEREO)]
- sampwidthlist = [(1, AL.SAMPLE_8),
- (2, AL.SAMPLE_16),
- (3, AL.SAMPLE_24)]
+ inited_nchannels, port, converter, classinited: private
+
+ classinited = 0
+ frameratelist = nchannelslist = sampwidthlist = None
+
+ def initclass(self):
+ import AL
+ Play_Audio_sgi.frameratelist = [
+ (48000, AL.RATE_48000),
+ (44100, AL.RATE_44100),
+ (32000, AL.RATE_32000),
+ (22050, AL.RATE_22050),
+ (16000, AL.RATE_16000),
+ (11025, AL.RATE_11025),
+ ( 8000, AL.RATE_8000),
+ ]
+ Play_Audio_sgi.nchannelslist = [
+ (1, AL.MONO),
+ (2, AL.STEREO),
+ ]
+ Play_Audio_sgi.sampwidthlist = [
+ (1, AL.SAMPLE_8),
+ (2, AL.SAMPLE_16),
+ (3, AL.SAMPLE_24),
+ ]
+ Play_Audio_sgi.classinited = 1
def __init__(self):
- import al
+ import al, AL
+ if not self.classinited:
+ self.initclass()
self.oldparams = []
self.params = [AL.OUTPUT_RATE, 0]
self.config = al.newconfig()
@@ -37,7 +49,7 @@ class Play_Audio_sgi:
if self.port:
self.stop()
if self.oldparams:
- import al
+ import al, AL
al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
self.oldparams = []
@@ -54,7 +66,7 @@ class Play_Audio_sgi:
self.port.closeport()
self.port = None
if self.oldparams:
- import al
+ import al, AL
al.setparams(AL.DEFAULT_DEVICE, self.oldparams)
self.oldparams = []
@@ -75,6 +87,7 @@ class Play_Audio_sgi:
break
else:
if width == 0:
+ import AL
self.inited_width = 0
self.config.setwidth(AL.SAMPLE_16)
self.converter = self.ulaw2lin
@@ -94,7 +107,7 @@ class Play_Audio_sgi:
if not (self.inited_outrate and self.inited_nchannels):
raise error, 'params not specified'
if not self.port:
- import al
+ import al, AL
self.port = al.openport('Python', 'w', self.config)
self.oldparams = self.params[:]
al.getparams(AL.DEFAULT_DEVICE, self.oldparams)
@@ -156,7 +169,7 @@ class Play_Audio_sun:
if not (self.inited_outrate and self.inited_width and self.inited_nchannels):
raise error, 'params not specified'
if not self.port:
- import sunaudiodev
+ import sunaudiodev, SUNAUDIODEV
self.port = sunaudiodev.open('w')
info = self.port.getinfo()
info.o_sample_rate = self.outrate
diff --git a/Lib/bdb.py b/Lib/bdb.py
index 6b3eab9..9b50767 100644
--- a/Lib/bdb.py
+++ b/Lib/bdb.py
@@ -17,6 +17,8 @@ class Bdb: # Basic Debugger
self.breaks = {}
def reset(self):
+ import linecache
+ linecache.checkcache()
self.botframe = None
self.stopframe = None
self.returnframe = None
@@ -134,11 +136,35 @@ class Bdb: # Basic Debugger
self.returnframe = frame
self.quitting = 0
+ def set_trace(self):
+ # Start debugging from here
+ try:
+ 1 + ''
+ except:
+ frame = sys.exc_traceback.tb_frame.f_back
+ self.reset()
+ while frame:
+ frame.f_trace = self.trace_dispatch
+ self.botframe = frame
+ frame = frame.f_back
+ self.set_step()
+ sys.settrace(self.trace_dispatch)
+
def set_continue(self):
# Don't stop except at breakpoints or when finished
self.stopframe = self.botframe
self.returnframe = None
self.quitting = 0
+ if not self.breaks:
+ # no breakpoints; run without debugger overhead
+ sys.settrace(None)
+ try:
+ 1 + '' # raise an exception
+ except:
+ frame = sys.exc_traceback.tb_frame.f_back
+ while frame and frame is not self.botframe:
+ del frame.f_trace
+ frame = frame.f_back
def set_quit(self):
self.stopframe = self.botframe
@@ -177,7 +203,7 @@ class Bdb: # Basic Debugger
return 'There are no breakpoints in that file!'
del self.breaks[filename]
- def clear_all_breaks(self, filename, lineno):
+ def clear_all_breaks(self):
if not self.breaks:
return 'There are no breakpoints!'
self.breaks = {}
@@ -217,11 +243,14 @@ class Bdb: # Basic Debugger
#
def format_stack_entry(self, frame_lineno):
- import codehack, linecache, repr, string
+ import linecache, repr, string
frame, lineno = frame_lineno
filename = frame.f_code.co_filename
s = filename + '(' + `lineno` + ')'
- s = s + codehack.getcodename(frame.f_code)
+ if frame.f_code.co_name:
+ s = s + frame.f_code.co_name
+ else:
+ s = s + "<lambda>"
if frame.f_locals.has_key('__args__'):
args = frame.f_locals['__args__']
if args is not None:
@@ -269,17 +298,19 @@ class Bdb: # Basic Debugger
sys.settrace(None)
+def set_trace():
+ Bdb().set_trace()
+
# -------------------- testing --------------------
class Tdb(Bdb):
def user_call(self, frame, args):
- import codehack
- name = codehack.getcodename(frame.f_code)
+ name = frame.f_code.co_name
if not name: name = '???'
print '+++ call', name, args
def user_line(self, frame):
- import linecache, string, codehack
- name = codehack.getcodename(frame.f_code)
+ import linecache, string
+ name = frame.f_code.co_name
if not name: name = '???'
fn = frame.f_code.co_filename
line = linecache.getline(fn, frame.f_lineno)
@@ -300,7 +331,5 @@ def bar(a):
return a/2
def test():
- import linecache
- linecache.checkcache()
t = Tdb()
t.run('import bdb; bdb.foo(10)')
diff --git a/Lib/calendar.py b/Lib/calendar.py
index 4dfcf0c8..e9b1644 100644
--- a/Lib/calendar.py
+++ b/Lib/calendar.py
@@ -106,12 +106,7 @@ def weekheader(width):
return str
# Print a month's calendar
-def prmonth(year, month, *rest):
- if rest[2:]: raise TypeError, 'too many args'
- w = 0
- l = 0
- if rest[0:]: w = rest[0]
- if rest[1:]: l = rest[1]
+def prmonth(year, month, w = 0, l = 0):
w = max(2, w)
l = max(1, l)
print _center(month_name[month] + ' ' + `year`, 7*(w+1) - 1),
diff --git a/Lib/cmd.py b/Lib/cmd.py
index 87ddcfa..85115bb 100644
--- a/Lib/cmd.py
+++ b/Lib/cmd.py
@@ -56,8 +56,36 @@ class Cmd:
else:
import newdir
names = newdir.dir(self.__class__)
- cmds = []
+ cmds_doc = []
+ cmds_undoc = []
+ help = {}
+ for name in names:
+ if name[:5] == 'help_':
+ help[name[5:]]=1
for name in names:
if name[:3] == 'do_':
- cmds.append(name[3:])
- print cmds
+ cmd=name[3:]
+ if help.has_key(cmd):
+ cmds_doc.append(cmd)
+ del help[cmd]
+ else:
+ cmds_undoc.append(cmd)
+ print
+ self.print_topics("Documented commands (type help " \
+ "<topic>):",cmds_doc, 15, 80)
+ self.print_topics("Miscellaneous help topics:",
+ help.keys(), 15, 80)
+ self.print_topics("Undocumented commands:",
+ cmds_undoc, 15, 80)
+
+ def print_topics(self, header, cmds, cmdlen, maxcol):
+ if cmds:
+ print header;
+ print "="*len(header)
+ (cmds_per_line,junk)=divmod(maxcol,cmdlen)
+ col=cmds_per_line
+ for cmd in cmds:
+ if col==0: print
+ print (("%-"+`cmdlen`+"s") % cmd),
+ col = (col+1) % cmds_per_line
+ print "\n"
diff --git a/Lib/codehack.py b/Lib/codehack.py
index d00d2bf..1f16814 100644
--- a/Lib/codehack.py
+++ b/Lib/codehack.py
@@ -7,6 +7,10 @@ import string
import os
import linecache
+# XXX The functions getcodename() and getfuncname() are now obsolete
+# XXX as code and function objects now have a name attribute --
+# XXX co.co_name and f.func_name.
+
# Extract the function or class name from a code object.
# This is a bit of a hack, since a code object doesn't contain
# the name directly. So what do we do:
diff --git a/Lib/dis.py b/Lib/dis.py
index cd62500..846dc32 100644
--- a/Lib/dis.py
+++ b/Lib/dis.py
@@ -135,7 +135,8 @@ def_op('BREAK_LOOP', 80)
def_op('RAISE_EXCEPTION', 81)
def_op('LOAD_LOCALS', 82)
def_op('RETURN_VALUE', 83)
-
+def_op('LOAD_GLOBALS', 84)
+def_op('EXEC_STMT', 85)
def_op('BUILD_FUNCTION', 86)
def_op('POP_BLOCK', 87)
def_op('END_FINALLY', 88)
@@ -173,6 +174,7 @@ jrel_op('FOR_LOOP', 114) # Number of bytes to skip
name_op('LOAD_LOCAL', 115) # Index in name list
name_op('LOAD_GLOBAL', 116) # Index in name list
+def_op('SET_FUNC_ARGS', 117) # Argcount
jrel_op('SETUP_LOOP', 120) # Distance to target address
jrel_op('SETUP_EXCEPT', 121) # ""
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index c441f1f..d160303 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -9,10 +9,7 @@
# >>> from ftplib import FTP
# >>> ftp = FTP('ftp.cwi.nl') # connect to host, default port
# >>> ftp.login() # default, i.e.: user anonymous, passwd user@hostname
-# >>> def handle_one_line(line): # callback for ftp.retrlines
-# ... print line
-# ...
-# >>> ftp.retrlines('LIST', handle_one_line) # list directory contents
+# >>> ftp.retrlines('LIST') # list directory contents
# total 43
# d--x--x--x 2 root root 512 Jul 1 16:50 bin
# d--x--x--x 2 root root 512 Sep 16 1991 etc
@@ -20,7 +17,7 @@
# drwxr-srwt 15 root ftp 10240 Nov 5 20:43 pub
# >>> ftp.quit()
#
-# To download a file, use ftp.retrlines('RETR ' + filename, handle_one_line),
+# To download a file, use ftp.retrlines('RETR ' + filename),
# or ftp.retrbinary() with slightly different arguments.
# To upload a file, use ftp.storlines() or ftp.storbinary(), which have
# an open file as argument.
@@ -30,9 +27,14 @@
import os
import sys
-import socket
import string
+# Import SOCKS module if it exists, else standard socket module socket
+try:
+ import SOCKS; socket = SOCKS
+except ImportError:
+ import socket
+
# Magic number from <socket.h>
MSG_OOB = 0x1 # Process data out of band
@@ -59,14 +61,6 @@ all_errors = (error_reply, error_temp, error_perm, error_proto, \
CRLF = '\r\n'
-# Next port to be used by makeport(), with PORT_OFFSET added
-# (This is now only used when the python interpreter doesn't support
-# the getsockname() method yet)
-nextport = 0
-PORT_OFFSET = 40000
-PORT_CYCLE = 1000
-
-
# The class itself
class FTP:
@@ -74,7 +68,7 @@ class FTP:
# Initialize host to localhost, port to standard ftp port
# Optional arguments are host (for connect()),
# and user, passwd, acct (for login())
- def __init__(self, *args):
+ def __init__(self, host = '', user = '', passwd = '', acct = ''):
# Initialize the instance to something mostly harmless
self.debugging = 0
self.host = ''
@@ -82,18 +76,16 @@ class FTP:
self.sock = None
self.file = None
self.welcome = None
- if args:
- self.connect(args[0])
- if args[1:]:
- apply(self.login, args[1:])
+ if host:
+ self.connect(host)
+ if user: self.login(user, passwd, acct)
# Connect to host. Arguments:
# - host: hostname to connect to (default previous host)
# - port: port to connect to (default previous port)
- def connect(self, *args):
- if args: self.host = args[0]
- if args[1:]: self.port = args[1]
- if args[2:]: raise TypeError, 'too many args'
+ def connect(self, host = '', port = 0):
+ if host: self.host = host
+ if port: self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.sock.connect(self.host, self.port)
self.file = self.sock.makefile('r')
@@ -208,19 +200,8 @@ class FTP:
def makeport(self):
global nextport
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- try:
- getsockname = sock.getsockname
- except AttributeError:
- if self.debugging > 1:
- print '*** getsockname not supported',
- print '-- using manual port assignment ***'
- port = nextport + PORT_OFFSET
- nextport = (nextport + 1) % PORT_CYCLE
- sock.bind('', port)
- getsockname = None
- sock.listen(0) # Assigns the port if not explicitly bound
- if getsockname:
- host, port = getsockname()
+ sock.listen(1)
+ host, port = sock.getsockname()
resp = self.sendport(port)
return sock
@@ -235,13 +216,7 @@ class FTP:
return conn
# Login, default anonymous
- def login(self, *args):
- user = passwd = acct = ''
- n = len(args)
- if n > 3: raise TypeError, 'too many arguments'
- if n > 0: user = args[0]
- if n > 1: passwd = args[1]
- if n > 2: acct = args[2]
+ def login(self, user = '', passwd = '', acct = ''):
if not user: user = 'anonymous'
if user == 'anonymous' and passwd in ('', '-'):
thishost = socket.gethostname()
@@ -278,11 +253,7 @@ class FTP:
# The callback function is called for each line, with trailing
# CRLF stripped. This creates a new port for you.
# print_lines is the default callback
- def retrlines(self, cmd, *args):
- callback = None
- if args:
- callback = args[0]
- if args[1:]: raise TypeError, 'too many args'
+ def retrlines(self, cmd, callback = None):
if not callback: callback = print_line
resp = self.sendcmd('TYPE A')
conn = self.transfercmd(cmd)
@@ -423,30 +394,22 @@ def print_line(line):
# Usage: ftp [-d] host [-l[dir]] [-d[dir]] [file] ...
def test():
import marshal
- global nextport
- try:
- nextport = marshal.load(open('.@nextport', 'r'))
- except IOError:
- pass
- try:
- debugging = 0
- while sys.argv[1] == '-d':
- debugging = debugging+1
- del sys.argv[1]
- host = sys.argv[1]
- ftp = FTP(host)
- ftp.set_debuglevel(debugging)
- ftp.login()
- for file in sys.argv[2:]:
- if file[:2] == '-l':
- ftp.dir(file[2:])
- elif file[:2] == '-d':
- cmd = 'CWD'
- if file[2:]: cmd = cmd + ' ' + file[2:]
- resp = ftp.sendcmd(cmd)
- else:
- ftp.retrbinary('RETR ' + file, \
- sys.stdout.write, 1024)
- ftp.quit()
- finally:
- marshal.dump(nextport, open('.@nextport', 'w'))
+ debugging = 0
+ while sys.argv[1] == '-d':
+ debugging = debugging+1
+ del sys.argv[1]
+ host = sys.argv[1]
+ ftp = FTP(host)
+ ftp.set_debuglevel(debugging)
+ ftp.login()
+ for file in sys.argv[2:]:
+ if file[:2] == '-l':
+ ftp.dir(file[2:])
+ elif file[:2] == '-d':
+ cmd = 'CWD'
+ if file[2:]: cmd = cmd + ' ' + file[2:]
+ resp = ftp.sendcmd(cmd)
+ else:
+ ftp.retrbinary('RETR ' + file, \
+ sys.stdout.write, 1024)
+ ftp.quit()
diff --git a/Lib/irix5/FCNTL.py b/Lib/irix5/FCNTL.py
index 1271b9e..12c60fa 100755
--- a/Lib/irix5/FCNTL.py
+++ b/Lib/irix5/FCNTL.py
@@ -1,35 +1,35 @@
-# These lines were generated by h2py.py (see demo/scripts)
-# from <sys/fcntl.h> on Irix 4.0.2.
-# The applicability on other systems is not clear.
-
+# Generated by h2py from /usr/include/sys/fcntl.h
FNDELAY = 0x04
FAPPEND = 0x08
FSYNC = 0x10
-FRCACH = 0x20
-FASYNC = 0x40
-FNONBLK = 0x80
-FCREAT = 0x100
-FTRUNC = 0x200
-FEXCL = 0x400
-FNOCTTY = 0x800
+FNONBLOCK = 0x80
+FASYNC = 0x1000
+FNONBLK = FNONBLOCK
+FDIRECT = 0x8000
+FCREAT = 0x0100
+FTRUNC = 0x0200
+FEXCL = 0x0400
+FNOCTTY = 0x0800
O_RDONLY = 0
O_WRONLY = 1
O_RDWR = 2
-O_ACCMODE = 0x3
-O_NDELAY = FNDELAY
-O_APPEND = FAPPEND
-O_SYNC = FSYNC
-O_NONBLOCK = FNONBLK
-O_CREAT = FCREAT
-O_TRUNC = FTRUNC
-O_EXCL = FEXCL
-O_NOCTTY = FNOCTTY
+O_NDELAY = 0x04
+O_APPEND = 0x08
+O_SYNC = 0x10
+O_NONBLOCK = 0x80
+O_DIRECT = 0x8000
+O_CREAT = 0x100
+O_TRUNC = 0x200
+O_EXCL = 0x400
+O_NOCTTY = 0x800
F_DUPFD = 0
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
-F_GETLK = 5
+F_GETLK = 14
+F_O_GETLK = 5
+F_GETLK = 14
F_SETLK = 6
F_SETLKW = 7
F_CHKFL = 8
@@ -37,13 +37,17 @@ F_ALLOCSP = 10
F_FREESP = 11
F_SETBSDLK = 12
F_SETBSDLKW = 13
-F_RGETLK = 20
-F_RSETLK = 21
+F_DIOINFO = 30
+F_RSETLK = 20
+F_RGETLK = 21
F_RSETLKW = 22
-F_GETOWN = 10
-F_SETOWN = 11
+F_GETOWN = 23
+F_SETOWN = 24
+F_O_GETOWN = 10
+F_O_SETOWN = 11
F_RDLCK = 01
F_WRLCK = 02
F_UNLCK = 03
-FD_CLOEXEC = 0x1
-FD_NODUP_FORK = 0x2
+O_ACCMODE = 3
+FD_CLOEXEC = 1
+FD_NODUP_FORK = 4
diff --git a/Lib/irix5/IN.py b/Lib/irix5/IN.py
index 78be3ef..325a021 100755
--- a/Lib/irix5/IN.py
+++ b/Lib/irix5/IN.py
@@ -1,8 +1,4 @@
-# Symbolic constants from <netinet/in.h>.
-# These constants are SGI specific!
-# See demo/scripts/h2py.py for a tool to help generate a version for
-# your system.
-
+# Generated by h2py from /usr/include/netinet/in.h
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_IGMP = 2
@@ -14,6 +10,8 @@ IPPROTO_UDP = 17
IPPROTO_IDP = 22
IPPROTO_TP = 29
IPPROTO_XTP = 36
+IPPROTO_HELLO = 63
+IPPROTO_ND = 77
IPPROTO_EON = 80
IPPROTO_RAW = 255
IPPROTO_MAX = 256
@@ -42,6 +40,11 @@ INADDR_MAX_LOCAL_GROUP = 0xe00000ff
INADDR_NONE = 0xffffffff
IN_LOOPBACKNET = 127
IP_OPTIONS = 1
+IP_MULTICAST_IF = 2
+IP_MULTICAST_TTL = 3
+IP_MULTICAST_LOOP = 4
+IP_ADD_MEMBERSHIP = 5
+IP_DROP_MEMBERSHIP = 6
IP_HDRINCL = 7
IP_TOS = 8
IP_TTL = 9
@@ -49,11 +52,32 @@ IP_RECVOPTS = 10
IP_RECVRETOPTS = 11
IP_RECVDSTADDR = 12
IP_RETOPTS = 13
-IP_MULTICAST_IF = 2
-IP_MULTICAST_TTL = 3
-IP_MULTICAST_LOOP = 4
-IP_ADD_MEMBERSHIP = 5
-IP_DROP_MEMBERSHIP = 6
+IP_OPTIONS = 1
+IP_HDRINCL = 2
+IP_TOS = 3
+IP_TTL = 4
+IP_RECVOPTS = 5
+IP_RECVRETOPTS = 6
+IP_RECVDSTADDR = 7
+IP_RETOPTS = 8
+IP_MULTICAST_IF = 20
+IP_MULTICAST_TTL = 21
+IP_MULTICAST_LOOP = 22
+IP_ADD_MEMBERSHIP = 23
+IP_DROP_MEMBERSHIP = 24
+IRIX4_IP_OPTIONS = 1
+IRIX4_IP_MULTICAST_IF = 2
+IRIX4_IP_MULTICAST_TTL = 3
+IRIX4_IP_MULTICAST_LOOP = 4
+IRIX4_IP_ADD_MEMBERSHIP = 5
+IRIX4_IP_DROP_MEMBERSHIP = 6
+IRIX4_IP_HDRINCL = 7
+IRIX4_IP_TOS = 8
+IRIX4_IP_TTL = 9
+IRIX4_IP_RECVOPTS = 10
+IRIX4_IP_RECVRETOPTS = 11
+IRIX4_IP_RECVDSTADDR = 12
+IRIX4_IP_RETOPTS = 13
IP_DEFAULT_MULTICAST_TTL = 1
IP_DEFAULT_MULTICAST_LOOP = 1
IP_MAX_MEMBERSHIPS = 20
diff --git a/Lib/irix5/SOCKET.py b/Lib/irix5/SOCKET.py
index 8a15ef9..0ba0742 100755
--- a/Lib/irix5/SOCKET.py
+++ b/Lib/irix5/SOCKET.py
@@ -1,8 +1,23 @@
+# Generated by h2py from /usr/include/sys/socket.h
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
SOCK_RDM = 4
SOCK_SEQPACKET = 5
+NC_TPI_CLTS = 1
+NC_TPI_COTS = 2
+NC_TPI_COTS_ORD = 3
+NC_TPI_RAW = 4
+SOCK_DGRAM = NC_TPI_CLTS
+SOCK_STREAM = NC_TPI_COTS
+SOCK_RAW = NC_TPI_RAW
+SOCK_RDM = 5
+SOCK_SEQPACKET = 6
+IRIX4_SOCK_STREAM = 1
+IRIX4_SOCK_DGRAM = 2
+IRIX4_SOCK_RAW = 3
+IRIX4_SOCK_RDM = 4
+IRIX4_SOCK_SEQPACKET = 5
SO_DEBUG = 0x0001
SO_ACCEPTCONN = 0x0002
SO_REUSEADDR = 0x0004
@@ -13,6 +28,9 @@ SO_USELOOPBACK = 0x0040
SO_LINGER = 0x0080
SO_OOBINLINE = 0x0100
SO_REUSEPORT = 0x0200
+SO_ORDREL = 0x0200
+SO_IMASOCKET = 0x0400
+SO_CHAMELEON = 0x1000
SO_SNDBUF = 0x1001
SO_RCVBUF = 0x1002
SO_SNDLOWAT = 0x1003
@@ -21,6 +39,7 @@ SO_SNDTIMEO = 0x1005
SO_RCVTIMEO = 0x1006
SO_ERROR = 0x1007
SO_TYPE = 0x1008
+SO_PROTOTYPE = 0x1009
SOL_SOCKET = 0xffff
AF_UNSPEC = 0
AF_UNIX = 1
@@ -30,7 +49,6 @@ AF_PUP = 4
AF_CHAOS = 5
AF_NS = 6
AF_ISO = 7
-AF_OSI = AF_ISO
AF_ECMA = 8
AF_DATAKIT = 9
AF_CCITT = 10
@@ -44,7 +62,14 @@ AF_ROUTE = 17
AF_RAW = 18
AF_LINK = 18
pseudo_AF_XTP = 19
-AF_MAX = 20
+AF_NIT = 17
+AF_802 = 18
+AF_OSI = 19
+AF_X25 = 20
+AF_OSINET = 21
+AF_GOSIP = 22
+AF_SDL = 23
+AF_MAX = (AF_SDL+1)
PF_UNSPEC = AF_UNSPEC
PF_UNIX = AF_UNIX
PF_INET = AF_INET
@@ -53,7 +78,6 @@ PF_PUP = AF_PUP
PF_CHAOS = AF_CHAOS
PF_NS = AF_NS
PF_ISO = AF_ISO
-PF_OSI = AF_ISO
PF_ECMA = AF_ECMA
PF_DATAKIT = AF_DATAKIT
PF_CCITT = AF_CCITT
@@ -67,11 +91,18 @@ PF_ROUTE = AF_ROUTE
PF_LINK = AF_LINK
PF_XTP = pseudo_AF_XTP
PF_RAW = AF_RAW
+PF_NIT = AF_NIT
+PF_802 = AF_802
+PF_OSI = AF_OSI
+PF_X25 = AF_X25
+PF_OSINET = AF_OSINET
+PF_GOSIP = AF_GOSIP
PF_MAX = AF_MAX
SOMAXCONN = 5
MSG_OOB = 0x1
MSG_PEEK = 0x2
MSG_DONTROUTE = 0x4
+MSG_EOR = 0x8
MSG_BTAG = 0x40
MSG_ETAG = 0x80
MSG_MAXIOVLEN = 16
diff --git a/Lib/irix5/cddb.py b/Lib/irix5/cddb.py
index d7fdc96..0dee709 100755
--- a/Lib/irix5/cddb.py
+++ b/Lib/irix5/cddb.py
@@ -138,6 +138,19 @@ class Cddb:
continue
self.track[trackno] = value
f.close()
+ for i in range(2, len(self.track)):
+ track = self.track[i]
+ # if track title starts with `,', use initial part
+ # of previous track's title
+ if track[0] == ',':
+ try:
+ off = string.index(self.track[i - 1],
+ ',')
+ except string.index_error:
+ pass
+ else:
+ self.track[i] = self.track[i-1][:off] \
+ + track
def write(self):
import posixpath
@@ -153,6 +166,17 @@ class Cddb:
f.write('album.title:\t' + self.title + '\n')
f.write('album.artist:\t' + self.artist + '\n')
f.write('album.toc:\t' + self.toc + '\n')
+ prevpref = None
for i in range(1, len(self.track)):
- f.write('track' + `i` + '.title:\t' + self.track[i] + '\n')
+ track = self.track[i]
+ try:
+ off = string.index(track, ',')
+ except string.index_error:
+ prevpref = None
+ else:
+ if prevpref and track[:off] == prevpref:
+ track = track[off:]
+ else:
+ prevpref = track[:off]
+ f.write('track' + `i` + '.title:\t' + track + '\n')
f.close()
diff --git a/Lib/irix5/flp.py b/Lib/irix5/flp.py
index c3f6f3b..bc4a8ab 100755
--- a/Lib/irix5/flp.py
+++ b/Lib/irix5/flp.py
@@ -432,10 +432,10 @@ def _select_crfunc(fm, cl):
def test():
import time
- t0 = time.millitimer()
+ t0 = time.time()
if len(sys.argv) == 2:
forms = parse_forms(sys.argv[1])
- t1 = time.millitimer()
+ t1 = time.time()
print 'parse time:', 0.001*(t1-t0), 'sec.'
keys = forms.keys()
keys.sort()
@@ -443,8 +443,8 @@ def test():
_printform(forms[i])
elif len(sys.argv) == 3:
form = parse_form(sys.argv[1], sys.argv[2])
- t1 = time.millitimer()
- print 'parse time:', 0.001*(t1-t0), 'sec.'
+ t1 = time.time()
+ print 'parse time:', round(t1-t0, 3), 'sec.'
_printform(form)
else:
print 'Usage: test fdfile [form]'
diff --git a/Lib/lib-old/codehack.py b/Lib/lib-old/codehack.py
index d00d2bf..1f16814 100644
--- a/Lib/lib-old/codehack.py
+++ b/Lib/lib-old/codehack.py
@@ -7,6 +7,10 @@ import string
import os
import linecache
+# XXX The functions getcodename() and getfuncname() are now obsolete
+# XXX as code and function objects now have a name attribute --
+# XXX co.co_name and f.func_name.
+
# Extract the function or class name from a code object.
# This is a bit of a hack, since a code object doesn't contain
# the name directly. So what do we do:
diff --git a/Lib/lib-old/newdir.py b/Lib/lib-old/newdir.py
index 26a7df0..937c49e 100644
--- a/Lib/lib-old/newdir.py
+++ b/Lib/lib-old/newdir.py
@@ -65,11 +65,9 @@ def is_function(x):
# Approximation of builtin dir(); but note that this lists the user's
# variables by default, not the current local name space.
-def dir(*args):
- if len(args) > 0:
- if len(args) == 1:
- args = args[0]
- return listattrs(args)
+def dir(x = None):
+ if x is not None:
+ return listattrs(x)
else:
import __main__
return listattrs(__main__)
diff --git a/Lib/lib-old/packmail.py b/Lib/lib-old/packmail.py
index d612c88..13b1bdc 100644
--- a/Lib/lib-old/packmail.py
+++ b/Lib/lib-old/packmail.py
@@ -41,12 +41,28 @@ def packsome(outfp, dirname, names):
# Pack all files from a directory
def packall(outfp, dirname):
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
names.sort()
packsome(outfp, dirname, names)
# Pack all files from a directory that are not older than a give one
def packnotolder(outfp, dirname, oldest):
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
oldest = os.path.join(dirname, oldest)
st = os.stat(oldest)
mtime = st[ST_MTIME]
@@ -67,6 +83,14 @@ def packtree(outfp, dirname):
print 'packtree', dirname
outfp.write('mkdir ' + unixfix(dirname) + '\n')
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
subdirs = []
for name in names:
fullname = os.path.join(dirname, name)
diff --git a/Lib/lib-stdwin/WindowSched.py b/Lib/lib-stdwin/WindowSched.py
index 56ca6f8..b2fbe76 100644
--- a/Lib/lib-stdwin/WindowSched.py
+++ b/Lib/lib-stdwin/WindowSched.py
@@ -1,5 +1,5 @@
# Combine a real-time scheduling queue and stdwin event handling.
-# Uses the millisecond timer.
+# Keeps times in milliseconds.
import stdwin, stdwinq
from stdwinevents import WE_TIMER
@@ -19,11 +19,11 @@ def delayfunc(msecs):
mainloop.dispatch(event)
return
#
- # Use millisleep for very short delays or if there are no windows
+ # Use sleep for very short delays or if there are no windows
#
if msecs < 100 or mainloop.countwindows() == 0:
if msecs > 0:
- time.millisleep(msecs)
+ time.sleep(msecs * 0.001)
return
#
# Post a timer event on an arbitrary window and wait for it
@@ -35,7 +35,10 @@ def delayfunc(msecs):
if event[0] <> WE_TIMER:
mainloop.dispatch(event)
-q = sched.scheduler(time.millitimer, delayfunc)
+def millitimer():
+ return int(1000 * time.time())
+
+q = sched.scheduler(millitimer, delayfunc)
# Export functions enter, enterabs and cancel just like a scheduler
#
diff --git a/Lib/lib-stdwin/filewin.py b/Lib/lib-stdwin/filewin.py
index a03c3f7..df6aa7d 100644
--- a/Lib/lib-stdwin/filewin.py
+++ b/Lib/lib-stdwin/filewin.py
@@ -2,19 +2,19 @@
# File windows, a subclass of textwin (which is a subclass of gwin)
import textwin
-import builtin
+import __builtin__
# FILE WINDOW
def open_readonly(fn): # Open a file window
- fp = builtin.open(fn, 'r')
+ fp = __builtin__.open(fn, 'r')
w = textwin.open_readonly(fn, fp.read())
w.fn = fn
return w
def open(fn): # Open a file window
- fp = builtin.open(fn, 'r')
+ fp = __builtin__.open(fn, 'r')
w = textwin.open(fn, fp.read())
w.fn = fn
return w
diff --git a/Lib/lib-stdwin/wdb.py b/Lib/lib-stdwin/wdb.py
index d5c28bb..4018ab1 100644
--- a/Lib/lib-stdwin/wdb.py
+++ b/Lib/lib-stdwin/wdb.py
@@ -241,7 +241,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
stdwin.fleep()
def draw(self, detail):
- import linecache, codehack, string
+ import linecache, string
d = self.win.begindrawing()
try:
h, v = 0, 0
@@ -252,7 +252,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else:
s = ' '
s = s + fn + '(' + `lineno` + ')'
- s = s + codehack.getcodename(f.f_code)
+ s = s + f.f_code.co_name
if f.f_locals.has_key('__args__'):
args = f.f_locals['__args__']
if args is not None:
@@ -286,6 +286,8 @@ def runcall(*args):
try: apply(x.runcall, args)
finally: x.close()
+def set_trace():
+ Wdb().set_trace()
# Post-Mortem interface
@@ -304,6 +306,4 @@ def pm():
TESTCMD = 'import x; x.main()'
def test():
- import linecache
- linecache.checkcache()
run(TESTCMD)
diff --git a/Lib/mimetools.py b/Lib/mimetools.py
index 2a076f0..2844fa4 100644
--- a/Lib/mimetools.py
+++ b/Lib/mimetools.py
@@ -1,8 +1,10 @@
# Various tools used by MIME-reading or MIME-writing programs.
-import string
+import os
import rfc822
+import string
+import tempfile
# A derived class of rfc822.Message that knows about MIME headers and
@@ -67,7 +69,7 @@ class Message(rfc822.Message):
def getencoding(self):
if self.encodingheader == None:
return '7bit'
- return self.encodingheader
+ return string.lower(self.encodingheader)
def gettype(self):
return self.type
@@ -110,3 +112,75 @@ def choose_boundary():
timestamp = `int(time.time())`
seed = `rand.rand()`
return _prefix + '.' + timestamp + '.' + seed
+
+
+# Subroutines for decoding some common content-transfer-types
+
+# XXX This requires that uudecode and mmencode are in $PATH
+
+def decode(input, output, encoding):
+ if decodetab.has_key(encoding):
+ pipethrough(input, decodetab[encoding], output)
+ else:
+ raise ValueError, \
+ 'unknown Content-Transfer-Encoding: %s' % encoding
+
+def encode(input, output, encoding):
+ if encodetab.has_key(encoding):
+ pipethrough(input, encodetab[encoding], output)
+ else:
+ raise ValueError, \
+ 'unknown Content-Transfer-Encoding: %s' % encoding
+
+uudecode_pipe = '''(
+TEMP=/tmp/@uu.$$
+sed "s%^begin [0-7][0-7]* .*%begin 600 $TEMP%" | uudecode
+cat $TEMP
+rm $TEMP
+)'''
+
+decodetab = {
+ 'uuencode': uudecode_pipe,
+ 'x-uuencode': uudecode_pipe,
+ 'quoted-printable': 'mmencode -u -q',
+ 'base64': 'mmencode -u -b',
+}
+
+encodetab = {
+ 'x-uuencode': 'uuencode tempfile',
+ 'uuencode': 'uuencode tempfile',
+ 'quoted-printable': 'mmencode -q',
+ 'base64': 'mmencode -b',
+}
+
+def pipeto(input, command):
+ pipe = os.popen(command, 'w')
+ copyliteral(input, pipe)
+ pipe.close()
+
+def pipethrough(input, command, output):
+ tempname = tempfile.mktemp()
+ try:
+ temp = open(tempname, 'w')
+ except IOError:
+ print '*** Cannot create temp file', `tempname`
+ return
+ copyliteral(input, temp)
+ temp.close()
+ pipe = os.popen(command + ' <' + tempname, 'r')
+ copybinary(pipe, output)
+ pipe.close()
+ os.unlink(tempname)
+
+def copyliteral(input, output):
+ while 1:
+ line = input.readline()
+ if not line: break
+ output.write(line)
+
+def copybinary(input, output):
+ BUFSIZE = 8192
+ while 1:
+ line = input.read(BUFSIZE)
+ if not line: break
+ output.write(line)
diff --git a/Lib/multifile.py b/Lib/multifile.py
index 7a52ab6..71e0dd0 100644
--- a/Lib/multifile.py
+++ b/Lib/multifile.py
@@ -85,6 +85,17 @@ class MultiFile:
err('*** Missing endmarker in MultiFile.readline()\n')
return ''
#
+ def readlines(self):
+ list = []
+ while 1:
+ line = self.readline()
+ if not line: break
+ list.append(line)
+ return list
+ #
+ def read(self): # Note: no size argument -- read until EOF only!
+ return string.joinfields(self.readlines(), '')
+ #
def next(self):
while self.readline(): pass
if self.level > 1 or self.last:
diff --git a/Lib/newdir.py b/Lib/newdir.py
index 26a7df0..937c49e 100644
--- a/Lib/newdir.py
+++ b/Lib/newdir.py
@@ -65,11 +65,9 @@ def is_function(x):
# Approximation of builtin dir(); but note that this lists the user's
# variables by default, not the current local name space.
-def dir(*args):
- if len(args) > 0:
- if len(args) == 1:
- args = args[0]
- return listattrs(args)
+def dir(x = None):
+ if x is not None:
+ return listattrs(x)
else:
import __main__
return listattrs(__main__)
diff --git a/Lib/nntplib.py b/Lib/nntplib.py
index e7f0627..fb08b0c 100644
--- a/Lib/nntplib.py
+++ b/Lib/nntplib.py
@@ -60,10 +60,7 @@ class NNTP:
# - host: hostname to connect to
# - port: port to connect to (default the standard NNTP port)
- def __init__(self, host, *args):
- if len(args) > 1: raise TypeError, 'too many args'
- if args: port = args[0]
- else: port = NNTP_PORT
+ def __init__(self, host, port = NNTP_PORT):
self.host = host
self.port = port
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
diff --git a/Lib/ospath.py b/Lib/ospath.py
index 866d02e..1e66759 100644
--- a/Lib/ospath.py
+++ b/Lib/ospath.py
@@ -1,15 +1,3 @@
-# ospath.py is to {posix,mac}path.py what os.py is to modules {posix,mac}
-
-try:
- import posix
- name = 'posix'
- del posix
-except ImportError:
- import mac
- name = 'mac'
- del mac
-
-if name == 'posix':
- from posixpath import *
-elif name == 'mac':
- from macpath import *
+# ospath.py is obsolete
+import os
+exec 'from %s import *' % os.name
diff --git a/Lib/packmail.py b/Lib/packmail.py
index d612c88..13b1bdc 100644
--- a/Lib/packmail.py
+++ b/Lib/packmail.py
@@ -41,12 +41,28 @@ def packsome(outfp, dirname, names):
# Pack all files from a directory
def packall(outfp, dirname):
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
names.sort()
packsome(outfp, dirname, names)
# Pack all files from a directory that are not older than a give one
def packnotolder(outfp, dirname, oldest):
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
oldest = os.path.join(dirname, oldest)
st = os.stat(oldest)
mtime = st[ST_MTIME]
@@ -67,6 +83,14 @@ def packtree(outfp, dirname):
print 'packtree', dirname
outfp.write('mkdir ' + unixfix(dirname) + '\n')
names = os.listdir(dirname)
+ try:
+ names.remove('.')
+ except:
+ pass
+ try:
+ names.remove('..')
+ except:
+ pass
subdirs = []
for name in names:
fullname = os.path.join(dirname, name)
diff --git a/Lib/pdb.doc b/Lib/pdb.doc
index c92b572..43a91c2 100644
--- a/Lib/pdb.doc
+++ b/Lib/pdb.doc
@@ -61,9 +61,10 @@ u(p)
Move the current frame one level up in the stack trace
(to a newer frame).
-b(reak) [lineno]
- With a line number argument, set a break there in the current file.
- Without argument, list all breaks.
+b(reak) [lineno | function]
+ With a line number argument, set a break there in the current
+ file. With a function name, set a break at the entry of that
+ function. Without argument, list all breaks.
cl(ear) [lineno]
With a line number argument, clear that break in the current file.
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 64451d5..a77dd29 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -74,17 +74,31 @@ class Pdb(bdb.Bdb, cmd.Cmd):
# Return true to exit from the command loop
do_h = cmd.Cmd.do_help
-
+
def do_break(self, arg):
if not arg:
print self.get_all_breaks() # XXX
return
- try:
+ # Try line number as argument
+ try:
lineno = int(eval(arg))
+ filename = self.curframe.f_code.co_filename
except:
- print '*** Error in argument:', `arg`
- return
- filename = self.curframe.f_code.co_filename
+ # Try function name as the argument
+ import codehack
+ try:
+ func = eval(arg, self.curframe.f_globals,
+ self.curframe.f_locals)
+ if hasattr(func, 'im_func'):
+ func = func.im_func
+ code = func.func_code
+ except:
+ print '*** Could not eval argument:', arg
+ return
+ lineno = codehack.getlineno(code)
+ filename = code.co_filename
+
+ # now set the break point
err = self.set_break(filename, lineno)
if err: print '***', err
do_b = do_break
@@ -159,10 +173,10 @@ class Pdb(bdb.Bdb, cmd.Cmd):
do_q = do_quit
def do_args(self, arg):
- if self.curframe.f_locals.has_key('__return__'):
- print `self.curframe.f_locals['__return__']`
+ if self.curframe.f_locals.has_key('__args__'):
+ print `self.curframe.f_locals['__args__']`
else:
- print '*** Not arguments?!'
+ print '*** No arguments?!'
do_a = do_args
def do_retval(self, arg):
@@ -229,7 +243,6 @@ class Pdb(bdb.Bdb, cmd.Cmd):
do_l = do_list
def do_whatis(self, arg):
- import codehack
try:
value = eval(arg, self.curframe.f_globals, \
self.curframe.f_locals)
@@ -241,13 +254,13 @@ class Pdb(bdb.Bdb, cmd.Cmd):
try: code = value.func_code
except: pass
if code:
- print 'Function', codehack.getcodename(code)
+ print 'Function', code.co_name
return
# Is it an instance method?
try: code = value.im_func.func_code
except: pass
if code:
- print 'Method', codehack.getcodename(code)
+ print 'Method', code.co_name
return
# None of the above...
print type(value)
@@ -276,6 +289,137 @@ class Pdb(bdb.Bdb, cmd.Cmd):
print self.format_stack_entry(frame_lineno)
+ # Help methods (derived from pdb.doc)
+
+ def help_help(self):
+ self.help_h()
+
+ def help_h(self):
+ print """h(elp)
+ Without argument, print the list of available commands.
+ With a command name as argument, print help about that command
+ "help pdb" pipes the full documentation file to the $PAGER
+ "help exec" gives help on the ! command"""
+
+ def help_where(self):
+ self.help_w()
+
+ def help_w(self):
+ print """w(here)
+ Print a stack trace, with the most recent frame at the bottom.
+ An arrow indicates the "current frame", which determines the
+ context of most commands."""
+
+ def help_down(self):
+ self.help_d()
+
+ def help_d(self):
+ print """d(own)
+ Move the current frame one level down in the stack trace
+ (to an older frame)."""
+
+ def help_up(self):
+ self.help_u()
+
+ def help_u(self):
+ print """u(p)
+ Move the current frame one level up in the stack trace
+ (to a newer frame)."""
+
+ def help_break(self):
+ self.help_b()
+
+ def help_b(self):
+ print """b(reak) [lineno | function]
+ With a line number argument, set a break there in the current
+ file. With a function name, set a break at the entry of that
+ function. Without argument, list all breaks."""
+
+ def help_clear(self):
+ self.help_cl()
+
+ def help_cl(self):
+ print """cl(ear) [lineno]
+ With a line number argument, clear that break in the current file.
+ Without argument, clear all breaks (but first ask confirmation)."""
+
+ def help_step(self):
+ self.help_s()
+
+ def help_s(self):
+ print """s(tep)
+ Execute the current line, stop at the first possible occasion
+ (either in a function that is called or in the current function)."""
+
+ def help_next(self):
+ self.help_n()
+
+ def help_n(self):
+ print """n(ext)
+ Continue execution until the next line in the current function
+ is reached or it returns."""
+
+ def help_return(self):
+ self.help_r()
+
+ def help_r(self):
+ print """r(eturn)
+ Continue execution until the current function returns."""
+
+ def help_continue(self):
+ self.help_c()
+
+ def help_cont(self):
+ self.help_c()
+
+ def help_c(self):
+ print """c(ont(inue))
+ Continue execution, only stop when a breakpoint is encountered."""
+
+ def help_list(self):
+ self.help_l()
+
+ def help_l(self):
+ print """l(ist) [first [,last]]
+ List source code for the current file.
+ Without arguments, list 11 lines around the current line
+ or continue the previous listing.
+ With one argument, list 11 lines starting at that line.
+ With two arguments, list the given range;
+ if the second argument is less than the first, it is a count."""
+
+ def help_args(self):
+ self.help_a()
+
+ def help_a(self):
+ print """a(rgs)
+ Print the argument list of the current function."""
+
+ def help_p(self):
+ print """p expression
+ Print the value of the expression."""
+
+ def help_exec(self):
+ print """(!) statement
+ Execute the (one-line) statement in the context of
+ the current stack frame.
+ The exclamation point can be omitted unless the first word
+ of the statement resembles a debugger command.
+ To assign to a global variable you must always prefix the
+ command with a 'global' command, e.g.:
+ (Pdb) global list_options; list_options = ['-l']
+ (Pdb)"""
+
+ def help_quit(self):
+ self.help_q()
+
+ def help_q(self):
+ print """q(uit) Quit from the debugger.
+ The program being executed is aborted."""
+
+ def help_pdb(self):
+ help()
+
# Simplified interface
def run(statement):
@@ -287,6 +431,8 @@ def runctx(statement, globals, locals):
def runcall(*args):
apply(Pdb().runcall, args)
+def set_trace():
+ Pdb().set_trace()
# Post-Mortem interface
@@ -306,8 +452,6 @@ def pm():
TESTCMD = 'import x; x.main()'
def test():
- import linecache
- linecache.checkcache()
run(TESTCMD)
# print help
diff --git a/Lib/plat-irix5/FCNTL.py b/Lib/plat-irix5/FCNTL.py
index 1271b9e..12c60fa 100755
--- a/Lib/plat-irix5/FCNTL.py
+++ b/Lib/plat-irix5/FCNTL.py
@@ -1,35 +1,35 @@
-# These lines were generated by h2py.py (see demo/scripts)
-# from <sys/fcntl.h> on Irix 4.0.2.
-# The applicability on other systems is not clear.
-
+# Generated by h2py from /usr/include/sys/fcntl.h
FNDELAY = 0x04
FAPPEND = 0x08
FSYNC = 0x10
-FRCACH = 0x20
-FASYNC = 0x40
-FNONBLK = 0x80
-FCREAT = 0x100
-FTRUNC = 0x200
-FEXCL = 0x400
-FNOCTTY = 0x800
+FNONBLOCK = 0x80
+FASYNC = 0x1000
+FNONBLK = FNONBLOCK
+FDIRECT = 0x8000
+FCREAT = 0x0100
+FTRUNC = 0x0200
+FEXCL = 0x0400
+FNOCTTY = 0x0800
O_RDONLY = 0
O_WRONLY = 1
O_RDWR = 2
-O_ACCMODE = 0x3
-O_NDELAY = FNDELAY
-O_APPEND = FAPPEND
-O_SYNC = FSYNC
-O_NONBLOCK = FNONBLK
-O_CREAT = FCREAT
-O_TRUNC = FTRUNC
-O_EXCL = FEXCL
-O_NOCTTY = FNOCTTY
+O_NDELAY = 0x04
+O_APPEND = 0x08
+O_SYNC = 0x10
+O_NONBLOCK = 0x80
+O_DIRECT = 0x8000
+O_CREAT = 0x100
+O_TRUNC = 0x200
+O_EXCL = 0x400
+O_NOCTTY = 0x800
F_DUPFD = 0
F_GETFD = 1
F_SETFD = 2
F_GETFL = 3
F_SETFL = 4
-F_GETLK = 5
+F_GETLK = 14
+F_O_GETLK = 5
+F_GETLK = 14
F_SETLK = 6
F_SETLKW = 7
F_CHKFL = 8
@@ -37,13 +37,17 @@ F_ALLOCSP = 10
F_FREESP = 11
F_SETBSDLK = 12
F_SETBSDLKW = 13
-F_RGETLK = 20
-F_RSETLK = 21
+F_DIOINFO = 30
+F_RSETLK = 20
+F_RGETLK = 21
F_RSETLKW = 22
-F_GETOWN = 10
-F_SETOWN = 11
+F_GETOWN = 23
+F_SETOWN = 24
+F_O_GETOWN = 10
+F_O_SETOWN = 11
F_RDLCK = 01
F_WRLCK = 02
F_UNLCK = 03
-FD_CLOEXEC = 0x1
-FD_NODUP_FORK = 0x2
+O_ACCMODE = 3
+FD_CLOEXEC = 1
+FD_NODUP_FORK = 4
diff --git a/Lib/plat-irix5/IN.py b/Lib/plat-irix5/IN.py
index 78be3ef..325a021 100755
--- a/Lib/plat-irix5/IN.py
+++ b/Lib/plat-irix5/IN.py
@@ -1,8 +1,4 @@
-# Symbolic constants from <netinet/in.h>.
-# These constants are SGI specific!
-# See demo/scripts/h2py.py for a tool to help generate a version for
-# your system.
-
+# Generated by h2py from /usr/include/netinet/in.h
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_IGMP = 2
@@ -14,6 +10,8 @@ IPPROTO_UDP = 17
IPPROTO_IDP = 22
IPPROTO_TP = 29
IPPROTO_XTP = 36
+IPPROTO_HELLO = 63
+IPPROTO_ND = 77
IPPROTO_EON = 80
IPPROTO_RAW = 255
IPPROTO_MAX = 256
@@ -42,6 +40,11 @@ INADDR_MAX_LOCAL_GROUP = 0xe00000ff
INADDR_NONE = 0xffffffff
IN_LOOPBACKNET = 127
IP_OPTIONS = 1
+IP_MULTICAST_IF = 2
+IP_MULTICAST_TTL = 3
+IP_MULTICAST_LOOP = 4
+IP_ADD_MEMBERSHIP = 5
+IP_DROP_MEMBERSHIP = 6
IP_HDRINCL = 7
IP_TOS = 8
IP_TTL = 9
@@ -49,11 +52,32 @@ IP_RECVOPTS = 10
IP_RECVRETOPTS = 11
IP_RECVDSTADDR = 12
IP_RETOPTS = 13
-IP_MULTICAST_IF = 2
-IP_MULTICAST_TTL = 3
-IP_MULTICAST_LOOP = 4
-IP_ADD_MEMBERSHIP = 5
-IP_DROP_MEMBERSHIP = 6
+IP_OPTIONS = 1
+IP_HDRINCL = 2
+IP_TOS = 3
+IP_TTL = 4
+IP_RECVOPTS = 5
+IP_RECVRETOPTS = 6
+IP_RECVDSTADDR = 7
+IP_RETOPTS = 8
+IP_MULTICAST_IF = 20
+IP_MULTICAST_TTL = 21
+IP_MULTICAST_LOOP = 22
+IP_ADD_MEMBERSHIP = 23
+IP_DROP_MEMBERSHIP = 24
+IRIX4_IP_OPTIONS = 1
+IRIX4_IP_MULTICAST_IF = 2
+IRIX4_IP_MULTICAST_TTL = 3
+IRIX4_IP_MULTICAST_LOOP = 4
+IRIX4_IP_ADD_MEMBERSHIP = 5
+IRIX4_IP_DROP_MEMBERSHIP = 6
+IRIX4_IP_HDRINCL = 7
+IRIX4_IP_TOS = 8
+IRIX4_IP_TTL = 9
+IRIX4_IP_RECVOPTS = 10
+IRIX4_IP_RECVRETOPTS = 11
+IRIX4_IP_RECVDSTADDR = 12
+IRIX4_IP_RETOPTS = 13
IP_DEFAULT_MULTICAST_TTL = 1
IP_DEFAULT_MULTICAST_LOOP = 1
IP_MAX_MEMBERSHIPS = 20
diff --git a/Lib/plat-irix5/SOCKET.py b/Lib/plat-irix5/SOCKET.py
index 8a15ef9..0ba0742 100755
--- a/Lib/plat-irix5/SOCKET.py
+++ b/Lib/plat-irix5/SOCKET.py
@@ -1,8 +1,23 @@
+# Generated by h2py from /usr/include/sys/socket.h
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
SOCK_RDM = 4
SOCK_SEQPACKET = 5
+NC_TPI_CLTS = 1
+NC_TPI_COTS = 2
+NC_TPI_COTS_ORD = 3
+NC_TPI_RAW = 4
+SOCK_DGRAM = NC_TPI_CLTS
+SOCK_STREAM = NC_TPI_COTS
+SOCK_RAW = NC_TPI_RAW
+SOCK_RDM = 5
+SOCK_SEQPACKET = 6
+IRIX4_SOCK_STREAM = 1
+IRIX4_SOCK_DGRAM = 2
+IRIX4_SOCK_RAW = 3
+IRIX4_SOCK_RDM = 4
+IRIX4_SOCK_SEQPACKET = 5
SO_DEBUG = 0x0001
SO_ACCEPTCONN = 0x0002
SO_REUSEADDR = 0x0004
@@ -13,6 +28,9 @@ SO_USELOOPBACK = 0x0040
SO_LINGER = 0x0080
SO_OOBINLINE = 0x0100
SO_REUSEPORT = 0x0200
+SO_ORDREL = 0x0200
+SO_IMASOCKET = 0x0400
+SO_CHAMELEON = 0x1000
SO_SNDBUF = 0x1001
SO_RCVBUF = 0x1002
SO_SNDLOWAT = 0x1003
@@ -21,6 +39,7 @@ SO_SNDTIMEO = 0x1005
SO_RCVTIMEO = 0x1006
SO_ERROR = 0x1007
SO_TYPE = 0x1008
+SO_PROTOTYPE = 0x1009
SOL_SOCKET = 0xffff
AF_UNSPEC = 0
AF_UNIX = 1
@@ -30,7 +49,6 @@ AF_PUP = 4
AF_CHAOS = 5
AF_NS = 6
AF_ISO = 7
-AF_OSI = AF_ISO
AF_ECMA = 8
AF_DATAKIT = 9
AF_CCITT = 10
@@ -44,7 +62,14 @@ AF_ROUTE = 17
AF_RAW = 18
AF_LINK = 18
pseudo_AF_XTP = 19
-AF_MAX = 20
+AF_NIT = 17
+AF_802 = 18
+AF_OSI = 19
+AF_X25 = 20
+AF_OSINET = 21
+AF_GOSIP = 22
+AF_SDL = 23
+AF_MAX = (AF_SDL+1)
PF_UNSPEC = AF_UNSPEC
PF_UNIX = AF_UNIX
PF_INET = AF_INET
@@ -53,7 +78,6 @@ PF_PUP = AF_PUP
PF_CHAOS = AF_CHAOS
PF_NS = AF_NS
PF_ISO = AF_ISO
-PF_OSI = AF_ISO
PF_ECMA = AF_ECMA
PF_DATAKIT = AF_DATAKIT
PF_CCITT = AF_CCITT
@@ -67,11 +91,18 @@ PF_ROUTE = AF_ROUTE
PF_LINK = AF_LINK
PF_XTP = pseudo_AF_XTP
PF_RAW = AF_RAW
+PF_NIT = AF_NIT
+PF_802 = AF_802
+PF_OSI = AF_OSI
+PF_X25 = AF_X25
+PF_OSINET = AF_OSINET
+PF_GOSIP = AF_GOSIP
PF_MAX = AF_MAX
SOMAXCONN = 5
MSG_OOB = 0x1
MSG_PEEK = 0x2
MSG_DONTROUTE = 0x4
+MSG_EOR = 0x8
MSG_BTAG = 0x40
MSG_ETAG = 0x80
MSG_MAXIOVLEN = 16
diff --git a/Lib/plat-irix5/cddb.py b/Lib/plat-irix5/cddb.py
index d7fdc96..0dee709 100755
--- a/Lib/plat-irix5/cddb.py
+++ b/Lib/plat-irix5/cddb.py
@@ -138,6 +138,19 @@ class Cddb:
continue
self.track[trackno] = value
f.close()
+ for i in range(2, len(self.track)):
+ track = self.track[i]
+ # if track title starts with `,', use initial part
+ # of previous track's title
+ if track[0] == ',':
+ try:
+ off = string.index(self.track[i - 1],
+ ',')
+ except string.index_error:
+ pass
+ else:
+ self.track[i] = self.track[i-1][:off] \
+ + track
def write(self):
import posixpath
@@ -153,6 +166,17 @@ class Cddb:
f.write('album.title:\t' + self.title + '\n')
f.write('album.artist:\t' + self.artist + '\n')
f.write('album.toc:\t' + self.toc + '\n')
+ prevpref = None
for i in range(1, len(self.track)):
- f.write('track' + `i` + '.title:\t' + self.track[i] + '\n')
+ track = self.track[i]
+ try:
+ off = string.index(track, ',')
+ except string.index_error:
+ prevpref = None
+ else:
+ if prevpref and track[:off] == prevpref:
+ track = track[off:]
+ else:
+ prevpref = track[:off]
+ f.write('track' + `i` + '.title:\t' + track + '\n')
f.close()
diff --git a/Lib/plat-irix5/flp.py b/Lib/plat-irix5/flp.py
index c3f6f3b..bc4a8ab 100755
--- a/Lib/plat-irix5/flp.py
+++ b/Lib/plat-irix5/flp.py
@@ -432,10 +432,10 @@ def _select_crfunc(fm, cl):
def test():
import time
- t0 = time.millitimer()
+ t0 = time.time()
if len(sys.argv) == 2:
forms = parse_forms(sys.argv[1])
- t1 = time.millitimer()
+ t1 = time.time()
print 'parse time:', 0.001*(t1-t0), 'sec.'
keys = forms.keys()
keys.sort()
@@ -443,8 +443,8 @@ def test():
_printform(forms[i])
elif len(sys.argv) == 3:
form = parse_form(sys.argv[1], sys.argv[2])
- t1 = time.millitimer()
- print 'parse time:', 0.001*(t1-t0), 'sec.'
+ t1 = time.time()
+ print 'parse time:', round(t1-t0, 3), 'sec.'
_printform(form)
else:
print 'Usage: test fdfile [form]'
diff --git a/Lib/plat-sunos4/FCNTL.py b/Lib/plat-sunos4/FCNTL.py
index 0ba5e67..1256d81 100755
--- a/Lib/plat-sunos4/FCNTL.py
+++ b/Lib/plat-sunos4/FCNTL.py
@@ -1,10 +1,10 @@
+# Generated by h2py from stdin
_FOPEN = (-1)
_FREAD = 0x0001
_FWRITE = 0x0002
_FNDELAY = 0x0004
_FAPPEND = 0x0008
-_FMARK = 0x0010
-_FDEFER = 0x0020
+_FSETBLK = 0x0010
_FASYNC = 0x0040
_FSHLOCK = 0x0080
_FEXLOCK = 0x0100
@@ -15,6 +15,8 @@ _FNBIO = 0x1000
_FSYNC = 0x2000
_FNONBLOCK = 0x4000
_FNOCTTY = 0x8000
+_FMARK = 0x10000
+_FDEFER = 0x20000
O_RDONLY = 0
O_WRONLY = 1
O_RDWR = 2
@@ -25,7 +27,6 @@ O_EXCL = _FEXCL
O_NONBLOCK = _FNONBLOCK
O_NOCTTY = _FNOCTTY
O_SYNC = _FSYNC
-O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)
FAPPEND = _FAPPEND
FSYNC = _FSYNC
FASYNC = _FASYNC
@@ -36,6 +37,7 @@ FREAD = _FREAD
FWRITE = _FWRITE
FMARK = _FMARK
FDEFER = _FDEFER
+FSETBLK = _FSETBLK
FSHLOCK = _FSHLOCK
FEXLOCK = _FEXLOCK
FOPEN = _FOPEN
@@ -62,3 +64,4 @@ F_RDLCK = 1
F_WRLCK = 2
F_UNLCK = 3
F_UNLKSYS = 4
+O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)
diff --git a/Lib/plat-sunos4/IN.py b/Lib/plat-sunos4/IN.py
index 05188af..a05a944 100755
--- a/Lib/plat-sunos4/IN.py
+++ b/Lib/plat-sunos4/IN.py
@@ -1,8 +1,4 @@
-# Symbolic constants from <netinet/in.h>.
-# These constants are SunOS specific! (Possibly even SunOS 4.1.1)
-# See demo/scripts/h2py.py for a tool to help generate a version for
-# your system.
-
+# Generated by h2py from /usr/include/netinet/in.h
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_IGMP = 2
diff --git a/Lib/plat-sunos4/SOCKET.py b/Lib/plat-sunos4/SOCKET.py
index c1b8542..65ce4bc 100755
--- a/Lib/plat-sunos4/SOCKET.py
+++ b/Lib/plat-sunos4/SOCKET.py
@@ -1,3 +1,4 @@
+# Generated by h2py from /usr/include/sys/socket.h
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
diff --git a/Lib/plat-sunos4/WAIT.py b/Lib/plat-sunos4/WAIT.py
new file mode 100755
index 0000000..43612f0
--- /dev/null
+++ b/Lib/plat-sunos4/WAIT.py
@@ -0,0 +1,13 @@
+# Generated by h2py from /usr/include/sys/wait.h
+WUNTRACED = 0004
+WNOHANG = 0100
+WEXITED = 0001
+WTRAPPED = 0002
+WSTOPPED = WUNTRACED
+WCONTINUED = 0010
+WNOWAIT = 0200
+WOPTMASK = (WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG|WNOWAIT)
+WSTOPFLG = 0177
+WCONTFLG = 0177777
+WCOREFLG = 0200
+WSIGMASK = 0177
diff --git a/Lib/plat-sunos4/regen b/Lib/plat-sunos4/regen
index f1482db..8b52d74 100755
--- a/Lib/plat-sunos4/regen
+++ b/Lib/plat-sunos4/regen
@@ -8,4 +8,5 @@ set -v
h2py </usr/include/sys/fcntlcom.h >FCNTL.py
echo "O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)" >>FCNTL.py
h2py /usr/include/sys/socket.h
+h2py /usr/include/sys/wait.h
h2py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/posixpath.py b/Lib/posixpath.py
index 96116d1..6110f8e 100644
--- a/Lib/posixpath.py
+++ b/Lib/posixpath.py
@@ -130,7 +130,7 @@ def isdir(path):
# Is a path a regular file?
-# This follows symbolic links, so both islink() and isdir() can be true
+# This follows symbolic links, so both islink() and isfile() can be true
# for the same path.
def isfile(path):
@@ -205,7 +205,7 @@ def walk(top, func, arg):
for name in names:
if name not in exceptions:
name = join(top, name)
- if isdir(name):
+ if isdir(name) and not islink(name):
walk(name, func, arg)
@@ -239,29 +239,35 @@ def expanduser(path):
# Expand paths containing shell variable substitutions.
-# This is done by piping it through the shell.
-# Shell quoting characters (\ " ' `) are protected by a backslash.
-# NB: a future version may avoid starting a subprocess and do the
-# substitutions internally. This may slightly change the syntax
-# for variables.
+# This expands the forms $variable and ${variable} only.
+# Non-existant variables are left unchanged.
+
+_varprog = None
def expandvars(path):
+ global _varprog
if '$' not in path:
return path
- q = ''
- for c in path:
- if c in ('\\', '"', '\'', '`'):
- c = '\\' + c
- q = q + c
- d = '!'
- if q == d:
- d = '+'
- p = posix.popen('cat <<' + d + '\n' + q + '\n' + d + '\n', 'r')
- res = p.read()
- del p
- if res[-1:] == '\n':
- res = res[:-1]
- return res
+ if not _varprog:
+ import regex
+ _varprog = regex.compile('$\([a-zA-Z0-9_]+\|{[^}]*}\)')
+ i = 0
+ while 1:
+ i = _varprog.search(path, i)
+ if i < 0:
+ break
+ name = _varprog.group(1)
+ j = i + len(_varprog.group(0))
+ if name[:1] == '{' and name[-1:] == '}':
+ name = name[1:-1]
+ if posix.environ.has_key(name):
+ tail = path[j:]
+ path = path[:i] + posix.environ[name]
+ i = len(path)
+ path = path + tail
+ else:
+ i = j
+ return path
# Normalize a path, e.g. A//B, A/./B and A/foo/../B all become A/B.
diff --git a/Lib/profile.doc b/Lib/profile.doc
index 753d159..bf5d8e3 100644
--- a/Lib/profile.doc
+++ b/Lib/profile.doc
@@ -1,74 +1,702 @@
-The Python Profiler
-
-To use the profiler in its simplest form:
-
- >>> import profile
- >>> profile.run(statement)
-
-This will execute the statement and print statistics. To get more
-information out of the profiler, use:
-
- >>> import profile
- >>> profile.run(statement, dump_file)
-
-where dump_file is a string naming a file to which the (binary)
-profile statistics is to be dumped. The binary format is a dump of a
-dictionary. The key is the function name in the format described
-above; the value is a tuple consisting of, in order, number of calls,
-total time spent in the function, total time spent in the function and
-all functions called from it, a list of functions called by this
-function, and a list of functions that called this function. The dump
-can be read back using the following code:
-
- >>> import marshal
- >>> f = open(dump_file, 'r')
- >>> dict = marshal.load(f)
- >>> f.close()
-
-An easier way of doing this is by using the class `Stats' which is
-also defined in profile:
-
- >>> import profile
- >>> s = profile.Stats().init(dump_file)
-
-The following methods are defined for instances of `Stats':
-
- print_stats() -- Print the statistics in a format similar to
- the format profile.run() uses.
- print_callers() -- For each function, print all functions
- which it calls.
- print_callees() -- For each function, print all functions from
- which it is called.
- sort_stats(n) -- Sort the statistics for subsequent
- printing. The argument determines on which
- field the output should be sorted.
- Possibilities are
- -1 function name
- 0 number of calls
- 1 total time spent in a function
- 2 total time spent in a function
- plus all functions it called
- strip_dirs() -- Strip the directory names off of the file
- names which are part of the function names.
- This undoes the effect of sort_stats(), but
- a subsequent sort_stats() does work.
-
-The methods sort_stats and strip_dirs may change in the future.
-
-Output of profile.run(statement) and of the print_stats() method of
-the `Stats' class consists of the following fields.
-
- Number of times the function was called.
- Total time spent in the function.
- Mean time per function call (second field divided by first).
- Total time spent in the function and all functions it called,
- recursively.
- Mean time time spent in the function and all functions it
- called (fourth field divided by first).
- Name of the function in the format
- <file name>:<line number>(<function name>)
-
-The output of the print_callers and print_callees methods consists of
-the name of the function and the names of all function it called or
-was called from. The latter names are followed by a parenthesised
-number which is the number of calls for this function.
+profile.doc last updated 6/23/94 [by Guido]
+
+ PROFILER DOCUMENTATION and (mini) USER'S MANUAL
+
+Copyright 1994, by InfoSeek Corporation, all rights reserved.
+Written by James Roskind
+
+Permission to use, copy, modify, and distribute this Python software
+and its associated documentation for any purpose (subject to the
+restriction in the following sentence) without fee is hereby granted,
+provided that the above copyright notice appears in all copies, and
+that both that copyright notice and this permission notice appear in
+supporting documentation, and that the name of InfoSeek not be used in
+advertising or publicity pertaining to distribution of the software
+without specific, written prior permission. This permission is
+explicitly restricted to the copying and modification of the software
+to remain in Python, compiled Python, or other languages (such as C)
+wherein the modified or derived code is exclusively imported into a
+Python module.
+
+INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION 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.
+
+
+The profiler was written after only programming in Python for 3 weeks.
+As a result, it is probably clumsy code, but I don't know for sure yet
+'cause I'm a beginner :-). I did work hard to make the code run fast,
+so that profiling would be a reasonable thing to do. I tried not to
+repeat code fragments, but I'm sure I did some stuff in really awkward
+ways at times. Please send suggestions for improvements to:
+jar@infoseek.com. I won't promise *any* support. ...but I'd
+appreciate the feedback.
+
+
+SECTION HEADING LIST:
+ INTRODUCTION
+ HOW IS THIS profile DIFFERENT FROM THE OLD profile MODULE?
+ INSTANT USERS MANUAL
+ WHAT IS DETERMINISTIC PROFILING?
+ REFERENCE MANUAL
+ FUNCTION profile.run(string, filename_opt)
+ CLASS Stats(filename, ...)
+ METHOD strip_dirs()
+ METHOD add(filename, ...)
+ METHOD sort_stats(key, ...)
+ METHOD reverse_order()
+ METHOD print_stats(restriction, ...)
+ METHOD print_callers(restrictions, ...)
+ METHOD print_callees(restrictions, ...)
+ METHOD ignore()
+ LIMITATIONS
+ CALIBRATION
+ EXTENSIONS: Deriving Better Profilers
+
+
+
+INTRODUCTION
+
+A "profiler" is a program that describes the run time performance of a
+program, providing a variety of statistics. This documentation
+describes the profiler functionality provided in the modules
+"profile" and "pstats." This profiler provides "deterministic
+profiling" of any Python programs. It also provides a series of
+report generation tools to allow users to rapidly examine the results
+of a profile operation.
+
+
+HOW IS THIS profile DIFFERENT FROM THE OLD profile MODULE?
+
+The big changes from standard profiling module are that you get more
+information, and you pay less CPU time. It's not a trade-off, it's a
+trade-up.
+
+To be specific:
+
+ bugs removed: local stack frame is no longer molested, execution time
+ is now charged to correct functions, ....
+
+ accuracy increased: profiler execution time is no longer charged to
+ user's code, calibration for platform is supported, file reads
+ are not done *by* profiler *during* profiling (and charged to
+ user's code!), ...
+
+ speed increased: Overhead CPU cost was reduced by more than a factor of
+ two (perhaps a factor of five), lightweight profiler module is
+ all that must be loaded, and the report generating module
+ (pstats) is not needed during profiling.
+
+ recursive functions support: cumulative times in recursive functions
+ are correctly calculated; recursive entries are counted; ...
+
+ large growth in report generating UI: distinct profiles runs can be added
+ together forming a comprehensive report; functions that import
+ statistics take arbitrary lists of files; sorting criteria is now
+ based on keywords (instead of 4 integer options); reports shows
+ what functions were profiled as well as what profile file was
+ referenced; output format has been improved, ...
+
+
+INSTANT USERS MANUAL
+
+This section is provided for users that "don't want to read the
+manual." It provides a very brief overview, and allows a user to
+rapidly perform profiling on an existing application.
+
+To profile an application with a main entry point of "foo()", you
+would add the following to your module:
+
+ import profile
+ profile.run("foo()")
+
+The above action would cause "foo()" to be run, and a series of
+informative lines (the profile) to be printed. The above approach is
+most useful when working with the interpreter. If you would like to
+save the results of a profile into a file for later examination, you
+can supply a file name as the second argument to the run() function:
+
+ import profile
+ profile.run("foo()", 'fooprof')
+
+When you wish to review the profile, you should use the methods in the
+pstats module. Typically you would load the statistics data as
+follows:
+
+ import pstats
+ p = pstats.Stats('fooprof')
+
+The class "Stats" (the above code just created an instance of this
+class) has a variety of methods for manipulating and printing the data
+that was just read into "p". When you ran profile.run() above, what
+was printed was the result of three method calls:
+
+ p.strip_dirs().sort_stats(-1).print_stats()
+
+The first method removed the extraneous path from all the module
+names. The second method sorted all the entries according to the
+standard module/line/name string that is printed (this is to comply
+with the semantics of the old profiler). The third method printed out
+all the statistics. You might try the following sort calls:
+
+ p.sort_stats('name')
+ p.print_stats()
+
+The first call will actually sort the list by function name, and the
+second call will print out the statistics. The following are some
+interesting calls to experiment with:
+
+ p.sort_stats('cumulative').print_stats(10)
+
+This sorts the profile by cumulative time in a function, and then only
+prints the ten most significant lines. If you want to understand what
+algorithms are taking time, the above line is what you would use.
+
+If you were looking to see what functions were looping a lot, and
+taking a lot of time, you would do:
+
+ p.sort_stats('time').print_stats(10)
+
+to sort according to time spent within each function, and then print
+the statistics for the top ten functions.
+
+You might also try:
+
+ p.sort_stats('file').print_stats('__init__')
+
+This will sort all the statistics by file name, and then print out
+statistics for only the class init methods ('cause they are spelled
+with "__init__" in them). As one final example, you could try:
+
+ p.sort_stats('time', 'cum').print_stats(.5, 'init')
+
+This line sorts stats with a primary key of time, and a secondary key
+of cumulative time, and then prints out some of the statistics. To be
+specific, the list is first culled down to 50% (re: .5) of its
+original size, then only lines containing "init" are maintained, and
+that sub-sub-list is printed.
+
+If you wondered what functions called the above functions, you could
+now (p is still sorted according to the last criteria) do:
+
+ p.print_callers(.5, 'init')
+
+and you would get a list of callers for each of the listed functions.
+
+If you want more functionality, you're going to have to read the
+manual (or guess) what the following functions do:
+
+ p.print_callees()
+ p.add('fooprof')
+
+
+WHAT IS DETERMINISTIC PROFILING?
+
+"Deterministic profiling" is meant to reflect the fact that all
+"function call", "function return", and "exception" events are
+monitored, and precise timings are made for the intervals between
+these events (during which time the user's code is executing). In
+contrast, "statistical profiling" (which is not done by this module)
+randomly samples the effective instruction pointer, and deduces where
+time is being spent. The latter technique traditionally involves less
+overhead (as the code does not need to be instrumented), but provides
+only relative indications of where time is being spent.
+
+In Python, since there is an interpreter active during execution, the
+presence of instrumented code is not required to do deterministic
+profiling. Python automatically provides a hook (optional callback)
+for each event. In addition, the interpreted nature of Python tends
+to add so much overhead to execution, that deterministic profiling
+tends to only add small processing overhead, in typical applications.
+The result is that deterministic profiling is not that expensive, but
+yet provides extensive run time statistics about the execution of a
+Python program.
+
+Call count statistics can be used to identify bugs in code (surprising
+counts), and to identify possible inline-expansion points (high call
+counts). Internal time statistics can be used to identify hot loops
+that should be carefully optimized. Cumulative time statistics should
+be used to identify high level errors in the selection of algorithms.
+Note that the unusual handling of cumulative times in this profiler
+allows statistics for recursive implementations of algorithms to be
+directly compared to iterative implementations.
+
+
+REFERENCE MANUAL
+
+The primary entry point for the profiler is the global function
+profile.run(). It is typically used to create any profile
+information. The reports are formatted and printed using methods for
+the class pstats.Stats. The following is a description of all of
+these standard entry points and functions. For a more in-depth view
+of some of the code, consider reading the later section on "Profiler
+Extensions," which includes discussion of how to derive "better"
+profilers from the classes presented, or reading the source code for
+these modules.
+
+
+FUNCTION profile.run(string, filename_opt)
+
+This function takes a single argument that has can be passed to the
+"exec" statement, and an optional file name. In all cases this
+routine attempts to "exec" its first argument, and gather profiling
+statistics from the execution. If no file name is present, then this
+function automatically prints a simple profiling report, sorted by the
+standard name string (file/line/function-name) that is presented in
+each line. The following is a typical output from such a call:
+
+cut here----
+
+ main()
+ 2706 function calls (2004 primitive calls) in 4.504 CPU seconds
+
+ Ordered by: standard name
+
+ ncalls tottime percall cumtime percall filename:lineno(function)
+ 2 0.006 0.003 0.953 0.477 pobject.py:75(save_objects)
+ 43/3 0.533 0.012 0.749 0.250 pobject.py:99(evaluate)
+ ...
+
+cut here----
+
+The first line indicates that this profile was generated by the call:
+profile.run('main()'), and hence the exec'ed string is 'main()'. The
+second line indicates that 2706 calls were monitored. Of those calls,
+2004 were "primitive." We define "primitive" to mean that the call
+was not induced via recursion. The next line: "Ordered by: standard
+name", indicates that the text string in the far right column was used
+to sort the output. The column headings include:
+
+ "ncalls" for the number of calls,
+ "tottime" for the total time spent in the given function
+ (and excluding time made in calls to sub-functions),
+ "percall" is the quotient of "tottime" divided by "ncalls"
+ "cumtime" is the total time spent in this and all subfunctions
+ (i.e., from invocation till exit). This figure is
+ accurate *even* for recursive functions.
+ "percall" is the quotient of "cumtime" divided by primitive
+ calls
+ "filename:lineno(function)" provides the respective data of
+ each function
+
+When there are two numbers in the first column (e.g.: 43/3), then the
+latter is the number of primitive calls, and the former is the actual
+number of calls. Note that when the function does not recurse, these
+two values are the same, and only the single figure is printed.
+
+
+CLASS Stats(filename, ...)
+
+This class constructor creates an instance of a statistics object from
+a filename (or set of filenames). Stats objects are manipulated by
+methods, in order to print useful reports.
+
+The file selected by the above constructor must have been created by
+the corresponding version of profile. To be specific, there is *NO*
+file compatibility guaranteed with future versions of this profiler,
+and there is no compatibility with files produced by other profilers
+(e.g., the standard system profiler).
+
+If several files are provided, all the statistics for identical
+functions will be coalesced, so that an overall view of several
+processes can be considered in a single report. If additional files
+need to be combined with data in an existing Stats object, the add()
+method can be used.
+
+
+METHOD strip_dirs()
+
+This method for the Stats class removes all leading path information
+from file names. It is very useful in reducing the size of the
+printout to fit within (close to) 80 columns. This method modifies
+the object, and the striped information is lost. After performing a
+strip operation, the object is considered to have its entries in a
+"random" order, as it was just after object initialization and
+loading. If strip_dir() causes two function names to be
+indistinguishable (i.e., they are on the same line of the same
+filename, and have the same function name), then the statistics for
+these two entries are accumulated into a single entry.
+
+
+METHOD add(filename, ...)
+
+This methods of the Stats class accumulates additional profiling
+information into the current profiling object. Its arguments should
+refer to filenames created my the corresponding version of
+profile.run(). Statistics for identically named (re: file, line,
+name) functions are automatically accumulated into single function
+statistics.
+
+
+METHOD sort_stats(key, ...)
+
+This method modifies the Stats object by sorting it according to the
+supplied criteria. The argument is typically a string identifying the
+basis of a sort (example: "time" or "name").
+
+When more than one key is provided, then additional keys are used as
+secondary criteria when the there is equality in all keys selected
+before them. For example, sort_stats('name', 'file') will sort all
+the entries according to their function name, and resolve all ties
+(identical function names) by sorting by file name.
+
+Abbreviations can be used for any key names, as long as the
+abbreviation is unambiguous. The following are the keys currently
+defined:
+
+ Valid Arg Meaning
+ "calls" call count
+ "cumulative" cumulative time
+ "file" file name
+ "module" file name
+ "pcalls" primitive call count
+ "line" line number
+ "name" function name
+ "nfl" name/file/line
+ "stdname" standard name
+ "time" internal time
+
+Note that all sorts on statistics are in descending order (placing most
+time consuming items first), where as name, file, and line number
+searches are in ascending order (i.e., alphabetical). The subtle
+distinction between "nfl" and "stdname" is that the standard name is a
+sort of the name as printed, which means that the embedded line
+numbers get compared in an odd way. For example, lines 3, 20, and 40
+would (if the file names were the same) appear in the string order
+"20" "3" and "40". In contrast, "nfl" does a numeric compare of the
+line numbers. In fact, sort_stats("nfl") is the same as
+sort_stats("name", "file", "line").
+
+For compatibility with the standard profiler, the numeric argument -1,
+0, 1, and 2 are permitted. They are interpreted as "stdname",
+"calls", "time", and "cumulative" respectively. If this old style
+format (numeric) is used, only one sort key (the numeric key) will be
+used, and additionally arguments will be silently ignored.
+
+
+METHOD reverse_order()
+
+This method for the Stats class reverses the ordering of the basic
+list within the object. This method is provided primarily for
+compatibility with the standard profiler. Its utility is questionable
+now that ascending vs descending order is properly selected based on
+the sort key of choice.
+
+
+METHOD print_stats(restriction, ...)
+
+This method for the Stats class prints out a report as described in
+the profile.run() definition.
+
+The order of the printing is based on the last sort_stats() operation
+done on the object (subject to caveats in add() and strip_dirs()).
+
+The arguments provided (if any) can be used to limit the list down to
+the significant entries. Initially, the list is taken to be the
+complete set of profiled functions. Each restriction is either an
+integer (to select a count of lines), or a decimal fraction between
+0.0 and 1.0 inclusive (to select a percentage of lines), or a regular
+expression (to pattern match the standard name that is printed). If
+several restrictions are provided, then they are applied sequentially.
+For example:
+
+ print_stats(.1, "foo:")
+
+would first limit the printing to first 10% of list, and then only
+print functions that were part of filename ".*foo:". In contrast, the
+command:
+
+ print_stats("foo:", .1)
+
+would limit the list to all functions having file names ".*foo:", and
+then proceed to only print the first 10% of them.
+
+
+METHOD print_callers(restrictions, ...)
+
+This method for the Stats class prints a list of all functions that
+called each function in the profiled database. The ordering is
+identical to that provided by print_stats(), and the definition of the
+restricting argument is also identical. For convenience, a number is
+shown in parentheses after each caller to show how many times this
+specific call was made. A second non-parenthesized number is the
+cumulative time spent in the function at the right.
+
+
+METHOD print_callees(restrictions, ...)
+
+This method for the Stats class prints a list of all function that
+were called by the indicated function. Aside from this reversal of
+direction of calls (re: called vs was called by), the arguments and
+ordering are identical to the print_callers() method.
+
+
+METHOD ignore()
+
+This method of the Stats class is used to dispose of the value
+returned by earlier methods. All standard methods in this class
+return the instance that is being processed, so that the commands can
+be strung together. For example:
+
+pstats.Stats('foofile').strip_dirs().sort_stats('cum').print_stats().ignore()
+
+would perform all the indicated functions, but it would not return
+the final reference to the Stats instance.
+
+
+
+
+LIMITATIONS
+
+There are two fundamental limitations on this profiler. The first is
+that it relies on the Python interpreter to dispatch "call", "return",
+and "exception" events. Compiled C code does not get interpreted,
+and hence is "invisible" to the profiler. All time spent in C code
+(including builtin functions) will be charged to the Python function
+that was invoked the C code. IF the C code calls out to some native
+Python code, then those calls will be profiled properly.
+
+The second limitation has to do with accuracy of timing information.
+There is a fundamental problem with deterministic profilers involving
+accuracy. The most obvious restriction is that the underlying "clock"
+is only ticking at a rate (typically) of about .001 seconds. Hence no
+measurements will be more accurate that that underlying clock. If
+enough measurements are taken, then the "error" will tend to average
+out. Unfortunately, removing this first error induces a second source
+of error...
+
+The second problem is that it "takes a while" from when an event is
+dispatched until the profiler's call to get the time actually *gets*
+the state of the clock. Similarly, there is a certain lag when
+exiting the profiler event handler from the time that the clock's
+value was obtained (and then squirreled away), until the user's code
+is once again executing. As a result, functions that are called many
+times, or call many functions, will typically accumulate this error.
+The error that accumulates in this fashion is typically less than the
+accuracy of the clock (i.e., less than one clock tick), but it *can*
+accumulate and become very significant. This profiler provides a
+means of calibrating itself for a give platform so that this error can
+be probabilistically (i.e., on the average) removed. After the
+profiler is calibrated, it will be more accurate (in a least square
+sense), but it will sometimes produce negative numbers (when call
+counts are exceptionally low, and the gods of probability work against
+you :-). ) Do *NOT* be alarmed by negative numbers in the profile.
+They should *only* appear if you have calibrated your profiler, and
+the results are actually better than without calibration.
+
+
+CALIBRATION
+
+The profiler class has a hard coded constant that is added to each
+event handling time to compensate for the overhead of calling the time
+function, and socking away the results. The following procedure can
+be used to obtain this constant for a given platform (see discussion
+in LIMITATIONS above).
+
+ import profile
+ pr = profile.Profile()
+ pr.calibrate(100)
+ pr.calibrate(100)
+ pr.calibrate(100)
+
+The argument to calibrate() is the number of times to try to do the
+sample calls to get the CPU times. If your computer is *very* fast,
+you might have to do:
+
+ pr.calibrate(1000)
+
+or even:
+
+ pr.calibrate(10000)
+
+The object of this exercise is to get a fairly consistent result.
+When you have a consistent answer, you are ready to use that number in
+the source code. For a Sun Sparcstation 1000 running Solaris 2.3, the
+magical number is about .00053. If you have a choice, you are better
+off with a smaller constant, and your results will "less often" show
+up as negative in profile statistics.
+
+The following shows how the trace_dispatch() method in the Profile
+class should be modified to install the calibration constant on a Sun
+Sparcstation 1000:
+
+ def trace_dispatch(self, frame, event, arg):
+ t = self.timer()
+ t = t[0] + t[1] - self.t - .00053 # Calibration constant
+
+ if self.dispatch[event](frame,t):
+ t = self.timer()
+ self.t = t[0] + t[1]
+ else:
+ r = self.timer()
+ self.t = r[0] + r[1] - t # put back unrecorded delta
+ return
+
+Note that if there is no calibration constant, then the line
+containing the callibration constant should simply say:
+
+ t = t[0] + t[1] - self.t # no calibration constant
+
+You can also achieve the same results using a derived class (and the
+profiler will actually run equally fast!!), but the above method is
+the simplest to use. I could have made the profiler "self
+calibrating", but it would have made the initialization of the
+profiler class slower, and would have required some *very* fancy
+coding, or else the use of a variable where the constant .00053 was
+placed in the code shown. This is a ****VERY**** critical performance
+section, and there is no reason to use a variable lookup at this
+point, when a constant can be used.
+
+
+EXTENSIONS: Deriving Better Profilers
+
+The Profile class of profile was written so that derived classes
+could be developed to extend the profiler. Rather than describing all
+the details of such an effort, I'll just present the following two
+examples of derived classes that can be used to do profiling. If the
+reader is an avid Python programmer, then it should be possible to use
+these as a model and create similar (and perchance better) profile
+classes.
+
+If all you want to do is change how the timer is called, or which
+timer function is used, then the basic class has an option for that in
+the constructor for the class. Consider passing the name of a
+function to call into the constructor:
+
+ pr = profile.Profile(your_time_func)
+
+The resulting profiler will call your time function instead of
+os.times(). The function should return either a single number, or a
+list of numbers (like what os.times() returns). If the function
+returns a single time number, or the list of returned numbers has
+length 2, then you will get an especially fast version of the dispatch
+routine.
+
+Be warned that you *should* calibrate the profiler class for the
+timer function that you choose. For most machines, a timer that
+returns a lone integer value will provide the best results in terms of
+low overhead during profiling. (os.times is *pretty* bad, 'cause it
+returns a tuple of floating point values, so all arithmetic is
+floating point in the profiler!). If you want to be substitute a
+better timer in the cleanest fashion, you should derive a class, and
+simply put in the replacement dispatch method that better handles your timer
+call, along with the appropriate calibration constant :-).
+
+
+cut here------------------------------------------------------------------
+#****************************************************************************
+# OldProfile class documentation
+#****************************************************************************
+#
+# The following derived profiler simulates the old style profile, providing
+# errant results on recursive functions. The reason for the usefulness of this
+# profiler is that it runs faster (i.e., less overhead) than the old
+# profiler. It still creates all the caller stats, and is quite
+# useful when there is *no* recursion in the user's code. It is also
+# a lot more accurate than the old profiler, as it does not charge all
+# its overhead time to the user's code.
+#****************************************************************************
+class OldProfile(Profile):
+ def trace_dispatch_exception(self, frame, t):
+ rt, rtt, rct, rfn, rframe, rcur = self.cur
+ if rcur and not rframe is frame:
+ return self.trace_dispatch_return(rframe, t)
+ return 0
+
+ def trace_dispatch_call(self, frame, t):
+ fn = `frame.f_code`
+
+ self.cur = (t, 0, 0, fn, frame, self.cur)
+ if self.timings.has_key(fn):
+ tt, ct, callers = self.timings[fn]
+ self.timings[fn] = tt, ct, callers
+ else:
+ self.timings[fn] = 0, 0, {}
+ return 1
+
+ def trace_dispatch_return(self, frame, t):
+ rt, rtt, rct, rfn, frame, rcur = self.cur
+ rtt = rtt + t
+ sft = rtt + rct
+
+ pt, ptt, pct, pfn, pframe, pcur = rcur
+ self.cur = pt, ptt+rt, pct+sft, pfn, pframe, pcur
+
+ tt, ct, callers = self.timings[rfn]
+ if callers.has_key(pfn):
+ callers[pfn] = callers[pfn] + 1
+ else:
+ callers[pfn] = 1
+ self.timings[rfn] = tt+rtt, ct + sft, callers
+
+ return 1
+
+
+ def snapshot_stats(self):
+ self.stats = {}
+ for func in self.timings.keys():
+ tt, ct, callers = self.timings[func]
+ nor_func = self.func_normalize(func)
+ nor_callers = {}
+ nc = 0
+ for func_caller in callers.keys():
+ nor_callers[self.func_normalize(func_caller)]=\
+ callers[func_caller]
+ nc = nc + callers[func_caller]
+ self.stats[nor_func] = nc, nc, tt, ct, nor_callers
+
+
+
+#****************************************************************************
+# HotProfile class documentation
+#****************************************************************************
+#
+# This profiler is the fastest derived profile example. It does not
+# calculate caller-callee relationships, and does not calculate cumulative
+# time under a function. It only calculates time spent in a function, so
+# it runs very quickly (re: very low overhead). In truth, the basic
+# profiler is so fast, that is probably not worth the savings to give
+# up the data, but this class still provides a nice example.
+#****************************************************************************
+class HotProfile(Profile):
+ def trace_dispatch_exception(self, frame, t):
+ rt, rtt, rfn, rframe, rcur = self.cur
+ if rcur and not rframe is frame:
+ return self.trace_dispatch_return(rframe, t)
+ return 0
+
+ def trace_dispatch_call(self, frame, t):
+ self.cur = (t, 0, frame, self.cur)
+ return 1
+
+ def trace_dispatch_return(self, frame, t):
+ rt, rtt, frame, rcur = self.cur
+
+ rfn = `frame.f_code`
+
+ pt, ptt, pframe, pcur = rcur
+ self.cur = pt, ptt+rt, pframe, pcur
+
+ if self.timings.has_key(rfn):
+ nc, tt = self.timings[rfn]
+ self.timings[rfn] = nc + 1, rt + rtt + tt
+ else:
+ self.timings[rfn] = 1, rt + rtt
+
+ return 1
+
+
+ def snapshot_stats(self):
+ self.stats = {}
+ for func in self.timings.keys():
+ nc, tt = self.timings[func]
+ nor_func = self.func_normalize(func)
+ self.stats[nor_func] = nc, nc, tt, 0, {}
+
+
+
+cut here------------------------------------------------------------------
diff --git a/Lib/profile.py b/Lib/profile.py
index 502a4db..35ed63e 100755
--- a/Lib/profile.py
+++ b/Lib/profile.py
@@ -1,201 +1,392 @@
#
-# Class for profiling python code.
-# Author: Sjoerd Mullender
-# Hacked somewhat by: Guido van Rossum
+# Class for profiling python code. rev 1.0 6/2/94
#
-# See the accompanying document profile.doc for more information.
+# Based on prior profile module by Sjoerd Mullender...
+# which was hacked somewhat by: Guido van Rossum
+#
+# See profile.doc for more information
+
+
+# Copyright 1994, by InfoSeek Corporation, all rights reserved.
+# Written by James Roskind
+#
+# Permission to use, copy, modify, and distribute this Python software
+# and its associated documentation for any purpose (subject to the
+# restriction in the following sentence) without fee is hereby granted,
+# provided that the above copyright notice appears in all copies, and
+# that both that copyright notice and this permission notice appear in
+# supporting documentation, and that the name of InfoSeek not be used in
+# advertising or publicity pertaining to distribution of the software
+# without specific, written prior permission. This permission is
+# explicitly restricted to the copying and modification of the software
+# to remain in Python, compiled Python, or other languages (such as C)
+# wherein the modified or derived code is exclusively imported into a
+# Python module.
+#
+# INFOSEEK CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+# FITNESS. IN NO EVENT SHALL INFOSEEK CORPORATION 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.
+
+
import sys
-import codehack
import os
+import time
import string
-import fpformat
import marshal
+
+# Global variables
+func_norm_dict = {}
+func_norm_counter = 0
+pid_string = `os.getpid()`
+
+
+# Optimized intermodule references
+ostimes = os.times
+
+
+# Sample timer for use with
+#i_count = 0
+#def integer_timer():
+# global i_count
+# i_count = i_count + 1
+# return i_count
+#itimes = integer_timer # replace with C coded timer returning integers
+
+#**************************************************************************
+# The following are the static member functions for the profiler class
+# Note that an instance of Profile() is *not* needed to call them.
+#**************************************************************************
+
+
+# simplified user interface
+def run(statement, *args):
+ prof = Profile()
+ try:
+ prof = prof.run(statement)
+ except SystemExit:
+ pass
+ if args:
+ prof.dump_stats(args[0])
+ else:
+ return prof.print_stats()
+
+# print help
+def help():
+ for dirname in sys.path:
+ fullname = os.path.join(dirname, 'profile.doc')
+ if os.path.exists(fullname):
+ sts = os.system('${PAGER-more} '+fullname)
+ if sts: print '*** Pager exit status:', sts
+ break
+ else:
+ print 'Sorry, can\'t find the help file "profile.doc"',
+ print 'along the Python search path'
+
+
+#**************************************************************************
+# class Profile documentation:
+#**************************************************************************
+# self.cur is always a tuple. Each such tuple corresponds to a stack
+# frame that is currently active (self.cur[-2]). The following are the
+# definitions of its members. We use this external "parallel stack" to
+# avoid contaminating the program that we are profiling. (old profiler
+# used to write into the frames local dictionary!!) Derived classes
+# can change the definition of some entries, as long as they leave
+# [-2:] intact.
+#
+# [ 0] = Time that needs to be charged to the parent frame's function. It is
+# used so that a function call will not have to access the timing data
+# for the parents frame.
+# [ 1] = Total time spent in this frame's function, excluding time in
+# subfunctions
+# [ 2] = Cumulative time spent in this frame's function, including time in
+# all subfunctions to this frame.
+# [-3] = Name of the function that corresonds to this frame.
+# [-2] = Actual frame that we correspond to (used to sync exception handling)
+# [-1] = Our parent 6-tuple (corresonds to frame.f_back)
+#**************************************************************************
+# Timing data for each function is stored as a 5-tuple in the dictionary
+# self.timings[]. The index is always the name stored in self.cur[4].
+# The following are the definitions of the members:
+#
+# [0] = The number of times this function was called, not counting direct
+# or indirect recursion,
+# [1] = Number of times this function appears on the stack, minus one
+# [2] = Total time spent internal to this function
+# [3] = Cumulative time that this function was present on the stack. In
+# non-recursive functions, this is the total execution time from start
+# to finish of each invocation of a function, including time spent in
+# all subfunctions.
+# [5] = A dictionary indicating for each function name, the number of times
+# it was called by us.
+#**************************************************************************
+# We produce function names via a repr() call on the f_code object during
+# profiling. This save a *lot* of CPU time. This results in a string that
+# always looks like:
+# <code object main at 87090, file "/a/lib/python-local/myfib.py", line 76>
+# After we "normalize it, it is a tuple of filename, line, function-name.
+# We wait till we are done profiling to do the normalization.
+# *IF* this repr format changes, then only the normalization routine should
+# need to be fixed.
+#**************************************************************************
class Profile:
- def __init__(self):
+ def __init__(self, *arg):
self.timings = {}
- self.debug = None
- self.call_level = 0
- self.profile_func = None
- self.profiling = 0
+ self.cur = None
+ self.cmd = ""
- def profile(self, funcname):
- if not self.profile_func:
- self.profile_func = {}
- self.profile_func[funcname] = 1
+ self.dispatch = { \
+ 'call' : self.trace_dispatch_call, \
+ 'return' : self.trace_dispatch_return, \
+ 'exception': self.trace_dispatch_exception, \
+ }
- def trace_dispatch(self, frame, event, arg):
- if event == 'call':
- funcname = codehack.getcodename(frame.f_code)
- if self.profile_func and not self.profiling:
- if self.profile_func.has_key(funcname):
- return
- self.profiling = 1
- t = os.times()
- t = t[0] + t[1]
- if frame.f_locals.has_key('__key'):
- key = frame.f_locals['__key']
- else:
- lineno = codehack.getlineno(frame.f_code)
- filename = frame.f_code.co_filename
- key = filename + ':' + `lineno` + '(' + funcname + ')'
- frame.f_locals['__key'] = key
- self.call_level = depth(frame)
- self.cur_frame = frame
- pframe = frame.f_back
- if self.debug:
- s0 = 'call: ' + key + ' depth: ' + `self.call_level` + ' time: ' + `t`
- if pframe:
- if pframe.f_locals.has_key('__key'):
- pkey = pframe.f_locals['__key']
- else:
- pkey = pframe.f_code.co_filename + \
- ':' + \
- `codehack.getlineno(pframe.f_code)` \
- + '(' + \
- codehack.getcodename(pframe.f_code) \
- + ')'
- pframe.f_locals['__key'] = pkey
- if self.debug:
- s1 = 'parent: ' + pkey
- if pframe.f_locals.has_key('__start_time'):
- st = pframe.f_locals['__start_time']
- nc, tt, ct, callers, callees = \
- self.timings[pkey]
- if self.debug:
- s1 = s1+' before: st='+`st`+' nc='+`nc`+' tt='+`tt`+' ct='+`ct`
- if callers.has_key(key):
- callers[key] = callers[key] + 1
- else:
- callers[key] = 1
- if self.debug:
- s1 = s1+' after: st='+`st`+' nc='+`nc`+' tt='+`tt+(t-st)`+' ct='+`ct`
- self.timings[pkey] = nc, tt + (t - st), ct, callers, callees
- if self.timings.has_key(key):
- nc, tt, ct, callers, callees = self.timings[key]
- else:
- nc, tt, ct, callers, callees = 0, 0, 0, {}, {}
- if self.debug:
- s0 = s0+' before: nc='+`nc`+' tt='+`tt`+' ct='+`ct`
- s0 = s0+' after: nc='+`nc+1`+' tt='+`tt`+' ct='+`ct`
- if pframe:
- if callees.has_key(pkey):
- callees[pkey] = callees[pkey] + 1
- else:
- callees[pkey] = 1
- self.timings[key] = nc + 1, tt, ct, callers, callees
- frame.f_locals['__start_time'] = t
- if self.debug:
- print s0
- print s1
- return
- if event == 'return':
- if self.profile_func:
- if not self.profiling:
- return
- if self.profile_func.has_key( \
- codehack.getcodename(frame.f_code)):
- self.profiling = 0
- self.call_level = depth(frame)
- self.cur_frame = frame
- pframe = frame.f_back
- if self.debug:
- s0 = 'return: '
- else:
- s0 = None
- self.handle_return(pframe, frame, s0)
- return
- if event == 'exception':
- if self.profile_func and not self.profiling:
- return
- call_level = depth(frame)
- if call_level < self.call_level:
- if call_level <> self.call_level - 1:
- print 'heh!',call_level,self.call_level
- if self.debug:
- s0 = 'exception: '
+ if not arg:
+ self.timer = os.times
+ self.dispatcher = self.trace_dispatch
+ else:
+ self.timer = arg[0]
+ t = self.timer() # test out timer function
+ try:
+ if len(t) == 2:
+ self.dispatcher = self.trace_dispatch
else:
- s0 = None
- self.handle_return(self.cur_frame, frame, s0)
- self.call_level = call_level
- self.cur_frame = frame
- return
- print 'profile.Profile.dispatch: unknown debugging event:',
- print `event`
+ self.dispatcher = self.trace_dispatch_r
+ except:
+ self.dispatcher = self.trace_dispatch_i
+ self.t = self.get_time()
+ self.simulate_call('profiler')
+
+
+ def get_time(self): # slow simulation of method to acquire time
+ t = self.timer()
+ if type(t) == type(()) or type(t) == type([]):
+ t = reduce(lambda x,y: x+y, t, 0)
+ return t
+
+
+ # Heavily optimized dispatch routine for os.times() timer
+
+ def trace_dispatch(self, frame, event, arg):
+ t = self.timer()
+ t = t[0] + t[1] - self.t # No Calibration constant
+ # t = t[0] + t[1] - self.t - .00053 # Calibration constant
+
+ if self.dispatch[event](frame,t):
+ t = self.timer()
+ self.t = t[0] + t[1]
+ else:
+ r = self.timer()
+ self.t = r[0] + r[1] - t # put back unrecorded delta
return
- def handle_return(self, pframe, frame, s0):
- t = os.times()
- t = t[0] + t[1]
- if frame.f_locals.has_key('__key'):
- key = frame.f_locals['__key']
+
+
+ # Dispatch routine for best timer program (return = scalar integer)
+
+ def trace_dispatch_i(self, frame, event, arg):
+ t = self.timer() - self.t # - 1 # Integer calibration constant
+ if self.dispatch[event](frame,t):
+ self.t = self.timer()
+ else:
+ self.t = self.timer() - t # put back unrecorded delta
+ return
+
+
+ # SLOW generic dispatch rountine for timer returning lists of numbers
+
+ def trace_dispatch_l(self, frame, event, arg):
+ t = self.get_time() - self.t
+
+ if self.dispatch[event](frame,t):
+ self.t = self.get_time()
+ else:
+ self.t = self.get_time()-t # put back unrecorded delta
+ return
+
+
+ def trace_dispatch_exception(self, frame, t):
+ rt, rtt, rct, rfn, rframe, rcur = self.cur
+ if (not rframe is frame) and rcur:
+ return self.trace_dispatch_return(rframe, t)
+ return 0
+
+
+ def trace_dispatch_call(self, frame, t):
+ fn = `frame.f_code`
+
+ # The following should be about the best approach, but
+ # we would need a function that maps from id() back to
+ # the actual code object.
+ # fn = id(frame.f_code)
+ # Note we would really use our own function, which would
+ # return the code address, *and* bump the ref count. We
+ # would then fix up the normalize function to do the
+ # actualy repr(fn) call.
+
+ # The following is an interesting alternative
+ # It doesn't do as good a job, and it doesn't run as
+ # fast 'cause repr() is written in C, and this is Python.
+ #fcode = frame.f_code
+ #code = fcode.co_code
+ #if ord(code[0]) == 127: # == SET_LINENO
+ # # see "opcode.h" in the Python source
+ # fn = (fcode.co_filename, ord(code[1]) | \
+ # ord(code[2]) << 8, fcode.co_name)
+ #else:
+ # fn = (fcode.co_filename, 0, fcode.co_name)
+
+ self.cur = (t, 0, 0, fn, frame, self.cur)
+ if self.timings.has_key(fn):
+ cc, ns, tt, ct, callers = self.timings[fn]
+ self.timings[fn] = cc, ns + 1, tt, ct, callers
else:
- funcname = codehack.getcodename(frame.f_code)
- lineno = codehack.getlineno(frame.f_code)
- filename = frame.f_code.co_filename
- key = filename + ':' + `lineno` + '(' + funcname + ')'
- frame.f_locals['__key'] = key
- if self.debug:
- s0 = s0 + key + ' depth: ' + `self.call_level` + ' time: ' + `t`
- if pframe:
- if pframe.f_locals.has_key('__key'):
- pkey = pframe.f_locals['__key']
- else:
- funcname = codehack.getcodename(frame.f_code)
- lineno = codehack.getlineno(frame.f_code)
- filename = frame.f_code.co_filename
- pkey = filename + ':' + `lineno` + '(' + funcname + ')'
- pframe.f_locals['__key'] = pkey
- if self.debug:
- s1 = 'parent: '+pkey
- if pframe.f_locals.has_key('__start_time') and \
- self.timings.has_key(pkey):
- st = pframe.f_locals['__start_time']
- nc, tt, ct, callers, callees = \
- self.timings[pkey]
- if self.debug:
- s1 = s1+' before: st='+`st`+' nc='+`nc`+' tt='+`tt`+' ct='+`ct`
- s1 = s1+' after: st='+`t`+' nc='+`nc`+' tt='+`tt`+' ct='+`ct+(t-st)`
- self.timings[pkey] = \
- nc, tt, ct + (t - st), callers, callees
- pframe.f_locals['__start_time'] = t
- if self.timings.has_key(key):
- nc, tt, ct, callers, callees = self.timings[key]
+ self.timings[fn] = 0, 0, 0, 0, {}
+ return 1
+
+ def trace_dispatch_return(self, frame, t):
+ # if not frame is self.cur[-2]: raise "Bad return", self.cur[3]
+
+ # Prefix "r" means part of the Returning or exiting frame
+ # Prefix "p" means part of the Previous or older frame
+
+ rt, rtt, rct, rfn, frame, rcur = self.cur
+ rtt = rtt + t
+ sft = rtt + rct
+
+ pt, ptt, pct, pfn, pframe, pcur = rcur
+ self.cur = pt, ptt+rt, pct+sft, pfn, pframe, pcur
+
+ cc, ns, tt, ct, callers = self.timings[rfn]
+ if not ns:
+ ct = ct + sft
+ cc = cc + 1
+ if callers.has_key(pfn):
+ callers[pfn] = callers[pfn] + 1 # hack: gather more
+ # stats such as the amount of time added to ct courtesy
+ # of this specific call, and the contribution to cc
+ # courtesy of this call.
else:
- nc, tt, ct, callers, callees = 0, 0, 0, {}, {}
- if frame.f_locals.has_key('__start_time'):
- st = frame.f_locals['__start_time']
+ callers[pfn] = 1
+ self.timings[rfn] = cc, ns - 1, tt+rtt, ct, callers
+
+ return 1
+
+ # The next few function play with self.cmd. By carefully preloading
+ # our paralell stack, we can force the profiled result to include
+ # an arbitrary string as the name of the calling function.
+ # We use self.cmd as that string, and the resulting stats look
+ # very nice :-).
+
+ def set_cmd(self, cmd):
+ if self.cur[-1]: return # already set
+ self.cmd = cmd
+ self.simulate_call(cmd)
+
+ class fake_code:
+ def __init__(self, filename, line, name):
+ self.co_filename = filename
+ self.co_line = line
+ self.co_name = name
+ self.co_code = '\0' # anything but 127
+
+ def __repr__(self):
+ return (self.co_filename, self.co_line, self.co_name)
+
+ class fake_frame:
+ def __init__(self, code, prior):
+ self.f_code = code
+ self.f_back = prior
+
+ def simulate_call(self, name):
+ code = self.fake_code('profile', 0, name)
+ if self.cur:
+ pframe = self.cur[-2]
else:
- st = t
- if self.debug:
- s0 = s0+' before: st='+`st`+' nc='+`nc`+' tt='+`tt`+' ct='+`ct`
- s0 = s0+' after: nc='+`nc`+' tt='+`tt+(t-st)`+' ct='+`ct+(t-st)`
- print s0
- print s1
- self.timings[key] = \
- nc, tt + (t - st), ct + (t - st), callers, callees
+ pframe = None
+ frame = self.fake_frame(code, pframe)
+ a = self.dispatch['call'](frame, 0)
+ return
+
+ # collect stats from pending stack, including getting final
+ # timings for self.cmd frame.
+
+ def simulate_cmd_complete(self):
+ t = self.get_time() - self.t
+ while self.cur[-1]:
+ # We *can* cause assertion errors here if
+ # dispatch_trace_return checks for a frame match!
+ a = self.dispatch['return'](self.cur[-2], t)
+ t = 0
+ self.t = self.get_time() - t
+
def print_stats(self):
- # Print in reverse order by ct
- print_title()
- list = []
- for key in self.timings.keys():
- nc, tt, ct, callers, callees = self.timings[key]
- if nc == 0:
- continue
- list.append(ct, tt, nc, key)
- list.sort()
- list.reverse()
- for ct, tt, nc, key in list:
- print_line(nc, tt, ct, os.path.basename(key))
+ import pstats
+ pstats.Stats(self).strip_dirs().sort_stats(-1). \
+ print_stats()
def dump_stats(self, file):
f = open(file, 'w')
- marshal.dump(self.timings, f)
+ self.create_stats()
+ marshal.dump(self.stats, f)
f.close()
+ def create_stats(self):
+ self.simulate_cmd_complete()
+ self.snapshot_stats()
+
+ def snapshot_stats(self):
+ self.stats = {}
+ for func in self.timings.keys():
+ cc, ns, tt, ct, callers = self.timings[func]
+ nor_func = self.func_normalize(func)
+ nor_callers = {}
+ nc = 0
+ for func_caller in callers.keys():
+ nor_callers[self.func_normalize(func_caller)]=\
+ callers[func_caller]
+ nc = nc + callers[func_caller]
+ self.stats[nor_func] = cc, nc, tt, ct, nor_callers
+
+
+ # Override the following function if you can figure out
+ # a better name for the binary f_code entries. I just normalize
+ # them sequentially in a dictionary. It would be nice if we could
+ # *really* see the name of the underlying C code :-). Sometimes
+ # you can figure out what-is-what by looking at caller and callee
+ # lists (and knowing what your python code does).
+
+ def func_normalize(self, func_name):
+ global func_norm_dict
+ global func_norm_counter
+ global func_sequence_num
+
+ if func_norm_dict.has_key(func_name):
+ return func_norm_dict[func_name]
+ if type(func_name) == type(""):
+ long_name = string.split(func_name)
+ file_name = long_name[6][1:-2]
+ func = long_name[2]
+ lineno = long_name[8][:-1]
+ if '?' == func: # Until I find out how to may 'em...
+ file_name = 'python'
+ func_norm_counter = func_norm_counter + 1
+ func = pid_string + ".C." + `func_norm_counter`
+ result = file_name , string.atoi(lineno) , func
+ else:
+ result = func_name
+ func_norm_dict[func_name] = result
+ return result
+
+
# The following two methods can be called by clients to use
# a profiler to profile a statement, given as a string.
@@ -203,187 +394,219 @@ class Profile:
import __main__
dict = __main__.__dict__
self.runctx(cmd, dict, dict)
+ return self
def runctx(self, cmd, globals, locals):
+ self.set_cmd(cmd)
sys.setprofile(self.trace_dispatch)
try:
- exec(cmd + '\n', globals, locals)
+ exec(cmd, globals, locals)
finally:
sys.setprofile(None)
# This method is more useful to profile a single function call.
-
def runcall(self, func, *args):
+ self.set_cmd(func.__name__)
sys.setprofile(self.trace_dispatch)
try:
apply(func, args)
finally:
sys.setprofile(None)
+ return self
-def depth(frame):
- d = 0
- while frame:
- d = d + 1
- frame = frame.f_back
- return d
+ #******************************************************************
+ # The following calculates the overhead for using a profiler. The
+ # problem is that it takes a fair amount of time for the profiler
+ # to stop the stopwatch (from the time it recieves an event).
+ # Similarly, there is a delay from the time that the profiler
+ # re-starts the stopwatch before the user's code really gets to
+ # continue. The following code tries to measure the difference on
+ # a per-event basis. The result can the be placed in the
+ # Profile.dispatch_event() routine for the given platform. Note
+ # that this difference is only significant if there are a lot of
+ # events, and relatively little user code per event. For example,
+ # code with small functions will typically benefit from having the
+ # profiler calibrated for the current platform. This *could* be
+ # done on the fly during init() time, but it is not worth the
+ # effort. Also note that if too large a value specified, then
+ # execution time on some functions will actually appear as a
+ # negative number. It is *normal* for some functions (with very
+ # low call counts) to have such negative stats, even if the
+ # calibration figure is "correct."
+ #
+ # One alternative to profile-time calibration adjustments (i.e.,
+ # adding in the magic little delta during each event) is to track
+ # more carefully the number of events (and cumulatively, the number
+ # of events during sub functions) that are seen. If this were
+ # done, then the arithmetic could be done after the fact (i.e., at
+ # display time). Currintly, we track only call/return events.
+ # These values can be deduced by examining the callees and callers
+ # vectors for each functions. Hence we *can* almost correct the
+ # internal time figure at print time (note that we currently don't
+ # track exception event processing counts). Unfortunately, there
+ # is currently no similar information for cumulative sub-function
+ # time. It would not be hard to "get all this info" at profiler
+ # time. Specifically, we would have to extend the tuples to keep
+ # counts of this in each frame, and then extend the defs of timing
+ # tuples to include the significant two figures. I'm a bit fearful
+ # that this additional feature will slow the heavily optimized
+ # event/time ratio (i.e., the profiler would run slower, fur a very
+ # low "value added" feature.)
+ #
+ # Plugging in the calibration constant doesn't slow down the
+ # profiler very much, and the accuracy goes way up.
+ #**************************************************************
+
+ def calibrate(self, m):
+ n = m
+ s = self.timer()
+ while n:
+ self.simple()
+ n = n - 1
+ f = self.timer()
+ my_simple = f[0]+f[1]-s[0]-s[1]
+ #print "Simple =", my_simple,
-class Stats:
- def __init__(self, file):
- f = open(file, 'r')
- self.stats = marshal.load(f)
- f.close()
- self.stats_list = None
+ n = m
+ s = self.timer()
+ while n:
+ self.instrumented()
+ n = n - 1
+ f = self.timer()
+ my_inst = f[0]+f[1]-s[0]-s[1]
+ # print "Instrumented =", my_inst
+ avg_cost = (my_inst - my_simple)/m
+ #print "Delta/call =", avg_cost, "(profiler fixup constant)"
+ return avg_cost
- def print_stats(self):
- print_title()
- if self.stats_list:
- for i in range(len(self.stats_list)):
- nc, tt, ct, callers, callees, key = \
- self.stats_list[i]
- print_line(nc, tt, ct, key)
+ # simulate a program with no profiler activity
+ def simple(self):
+ a = 1
+ pass
+
+ # simulate a program with call/return event processing
+ def instrumented(self):
+ a = 1
+ self.profiler_simulation(a, a, a)
+
+ # simulate an event processing activity (from user's perspective)
+ def profiler_simulation(self, x, y, z):
+ t = self.timer()
+ t = t[0] + t[1]
+ self.ut = t
+
+
+
+#****************************************************************************
+# OldProfile class documentation
+#****************************************************************************
+#
+# The following derived profiler simulates the old style profile, providing
+# errant results on recursive functions. The reason for the usefulnes of this
+# profiler is that it runs faster (i.e., less overhead). It still creates
+# all the caller stats, and is quite useful when there is *no* recursion
+# in the user's code.
+#
+# This code also shows how easy it is to create a modified profiler.
+#****************************************************************************
+class OldProfile(Profile):
+ def trace_dispatch_exception(self, frame, t):
+ rt, rtt, rct, rfn, rframe, rcur = self.cur
+ if rcur and not rframe is frame:
+ return self.trace_dispatch_return(rframe, t)
+ return 0
+
+ def trace_dispatch_call(self, frame, t):
+ fn = `frame.f_code`
+
+ self.cur = (t, 0, 0, fn, frame, self.cur)
+ if self.timings.has_key(fn):
+ tt, ct, callers = self.timings[fn]
+ self.timings[fn] = tt, ct, callers
else:
- for key in self.stats.keys():
- nc, tt, ct, callers, callees = self.stats[key]
- print_line(nc, tt, ct, key)
-
- def print_callers(self):
- if self.stats_list:
- for i in range(len(self.stats_list)):
- nc, tt, ct, callers, callees, key = \
- self.stats_list[i]
- print key,
- for func in callers.keys():
- print func+'('+`callers[func]`+')',
- print
+ self.timings[fn] = 0, 0, {}
+ return 1
+
+ def trace_dispatch_return(self, frame, t):
+ rt, rtt, rct, rfn, frame, rcur = self.cur
+ rtt = rtt + t
+ sft = rtt + rct
+
+ pt, ptt, pct, pfn, pframe, pcur = rcur
+ self.cur = pt, ptt+rt, pct+sft, pfn, pframe, pcur
+
+ tt, ct, callers = self.timings[rfn]
+ if callers.has_key(pfn):
+ callers[pfn] = callers[pfn] + 1
else:
- for key in self.stats.keys():
- nc, tt, ct, callers, callees = self.stats[key]
- print key,
- for func in callers.keys():
- print func+'('+`callers[func]`+')',
- print
-
- def print_callees(self):
- if self.stats_list:
- for i in range(len(self.stats_list)):
- nc, tt, ct, callers, callees, key = \
- self.stats_list[i]
- print key,
- for func in callees.keys():
- print func+'('+`callees[func]`+')',
- print
+ callers[pfn] = 1
+ self.timings[rfn] = tt+rtt, ct + sft, callers
+
+ return 1
+
+
+ def snapshot_stats(self):
+ self.stats = {}
+ for func in self.timings.keys():
+ tt, ct, callers = self.timings[func]
+ nor_func = self.func_normalize(func)
+ nor_callers = {}
+ nc = 0
+ for func_caller in callers.keys():
+ nor_callers[self.func_normalize(func_caller)]=\
+ callers[func_caller]
+ nc = nc + callers[func_caller]
+ self.stats[nor_func] = nc, nc, tt, ct, nor_callers
+
+
+
+#****************************************************************************
+# HotProfile class documentation
+#****************************************************************************
+#
+# This profiler is the fastest derived profile example. It does not
+# calculate caller-callee relationships, and does not calculate cumulative
+# time under a function. It only calculates time spent in a function, so
+# it runs very quickly (re: very low overhead)
+#****************************************************************************
+class HotProfile(Profile):
+ def trace_dispatch_exception(self, frame, t):
+ rt, rtt, rfn, rframe, rcur = self.cur
+ if rcur and not rframe is frame:
+ return self.trace_dispatch_return(rframe, t)
+ return 0
+
+ def trace_dispatch_call(self, frame, t):
+ self.cur = (t, 0, frame, self.cur)
+ return 1
+
+ def trace_dispatch_return(self, frame, t):
+ rt, rtt, frame, rcur = self.cur
+
+ rfn = `frame.f_code`
+
+ pt, ptt, pframe, pcur = rcur
+ self.cur = pt, ptt+rt, pframe, pcur
+
+ if self.timings.has_key(rfn):
+ nc, tt = self.timings[rfn]
+ self.timings[rfn] = nc + 1, rt + rtt + tt
else:
- for key in self.stats.keys():
- nc, tt, ct, callers, callees = self.stats[key]
- print key,
- for func in callees.keys():
- print func+'('+`callees[func]`+')',
- print
-
- def sort_stats(self, field):
- stats_list = []
- for key in self.stats.keys():
- t = self.stats[key]
- nt = ()
- for i in range(len(t)):
- if i == field:
- nt = (t[i],) + nt[:]
- else:
- nt = nt[:] + (t[i],)
- if field == -1:
- nt = (key,) + nt
- else:
- nt = nt + (key,)
- stats_list.append(nt)
- stats_list.sort()
- self.stats_list = []
- for i in range(len(stats_list)):
- t = stats_list[i]
- if field == -1:
- nt = t[1:] + t[0:1]
- else:
- nt = t[1:]
- nt = nt[:field] + t[0:1] + nt[field:]
- self.stats_list.append(nt)
-
- def reverse_order(self):
- self.stats_list.reverse()
-
- def strip_dirs(self):
- newstats = {}
- for key in self.stats.keys():
- nc, tt, ct, callers, callees = self.stats[key]
- newkey = os.path.basename(key)
- newcallers = {}
- for c in callers.keys():
- newcallers[os.path.basename(c)] = callers[c]
- newcallees = {}
- for c in callees.keys():
- newcallees[os.path.basename(c)] = callees[c]
- newstats[newkey] = nc, tt, ct, newcallers, newcallees
- self.stats = newstats
- self.stats_list = None
-
-def print_title():
- print string.rjust('ncalls', 8),
- print string.rjust('tottime', 8),
- print string.rjust('percall', 8),
- print string.rjust('cumtime', 8),
- print string.rjust('percall', 8),
- print 'filename:lineno(function)'
-
-def print_line(nc, tt, ct, key):
- print string.rjust(`nc`, 8),
- print f8(tt),
- if nc == 0:
- print ' '*8,
- else:
- print f8(tt/nc),
- print f8(ct),
- if nc == 0:
- print ' '*8,
- else:
- print f8(ct/nc),
- print key
+ self.timings[rfn] = 1, rt + rtt
-def f8(x):
- return string.rjust(fpformat.fix(x, 3), 8)
+ return 1
-# simplified user interface
-def run(statement, *args):
- prof = Profile()
- try:
- prof.run(statement)
- except SystemExit:
- pass
- if len(args) == 0:
- prof.print_stats()
- else:
- prof.dump_stats(args[0])
-# test command with debugging
-def debug():
- prof = Profile()
- prof.debug = 1
- try:
- prof.run('import x; x.main()')
- except SystemExit:
- pass
- prof.print_stats()
+ def snapshot_stats(self):
+ self.stats = {}
+ for func in self.timings.keys():
+ nc, tt = self.timings[func]
+ nor_func = self.func_normalize(func)
+ self.stats[nor_func] = nc, nc, tt, 0, {}
-# test command
-def test():
- run('import x; x.main()')
+
-# print help
-def help():
- for dirname in sys.path:
- fullname = os.path.join(dirname, 'profile.doc')
- if os.path.exists(fullname):
- sts = os.system('${PAGER-more} '+fullname)
- if sts: print '*** Pager exit status:', sts
- break
- else:
- print 'Sorry, can\'t find the help file "profile.doc"',
- print 'along the Python search path'
+#****************************************************************************
+def Stats(*args):
+ print 'Report generating functions are in the "pstats" module\a'
diff --git a/Lib/regexp.py b/Lib/regexp.py
index 6136814..4b5db73 100644
--- a/Lib/regexp.py
+++ b/Lib/regexp.py
@@ -10,13 +10,7 @@ class Prog:
self.prog = regex.compile(pat)
finally:
xxx = regex.set_syntax(save_syntax)
- def match(self, *args):
- if len(args) == 2:
- str, offset = args
- elif len(args) == 1:
- str, offset = args[0], 0
- else:
- raise TypeError, 'wrong argument count'
+ def match(self, str, offset = 0):
if self.prog.search(str, offset) < 0:
return ()
regs = self.prog.regs
diff --git a/Lib/repr.py b/Lib/repr.py
index 50ee6c9..2f4a0bf 100644
--- a/Lib/repr.py
+++ b/Lib/repr.py
@@ -77,6 +77,19 @@ class Repr:
j = max(0, self.maxlong-3-i)
s = s[:i] + '...' + s[len(s)-j:]
return s
+ def repr_instance(self, x, level):
+ try:
+ s = `x`
+ # Bugs in x.__repr__() can cause arbitrary
+ # exceptions -- then make up something
+ except:
+ return '<' + x.__class__.__name__ + ' instance at ' + \
+ hex(id(x))[2:] + '>'
+ if len(s) > self.maxstring:
+ i = max(0, (self.maxstring-3)/2)
+ j = max(0, self.maxstring-3-i)
+ s = s[:i] + '...' + s[len(s)-j:]
+ return s
aRepr = Repr()
repr = aRepr.repr
diff --git a/Lib/rfc822.py b/Lib/rfc822.py
index 39ab6a6..580102c 100644
--- a/Lib/rfc822.py
+++ b/Lib/rfc822.py
@@ -1,8 +1,8 @@
# RFC-822 message manipulation class.
#
# XXX This is only a very rough sketch of a full RFC-822 parser;
-# additional methods are needed to parse addresses and dates, and to
-# tokenize lines according to various other syntax rules.
+# in particular the tokenizing of addresses does not adhere to all the
+# quoting rules.
#
# Directions for use:
#
@@ -22,6 +22,17 @@
# embedded whitespace (including newlines) exactly as they are
# specified in the header, and leave the case of the text unchanged.
#
+# For addresses and address lists there are functions
+# realname, mailaddress = m.getaddr(name) and
+# list = m.getaddrlist(name)
+# where the latter returns a list of (realname, mailaddr) tuples.
+#
+# There is also a method
+# time = m.getdate(name)
+# which parses a Date-like field and returns a time-compatible tuple,
+# i.e. a tuple such as returned by time.localtime() or accepted by
+# time.mktime().
+#
# See the class definition for lower level access methods.
#
# There are also some utility functions here.
@@ -29,6 +40,7 @@
import regex
import string
+import time
class Message:
@@ -105,12 +117,13 @@ class Message:
# Method to determine whether a line is a legal end of
# RFC-822 headers. You may override this method if your
- # application wants to bend the rules, e.g. to accept lines
- # ending in '\r\n', to strip trailing whitespace, or to
- # recognise MH template separators ('--------').
+ # application wants to bend the rules, e.g. to strip trailing
+ # whitespace, or to recognise MH template separators
+ # ('--------'). For convenience (e.g. for code reading from
+ # sockets) a line consisting of \r\n also matches.
def islast(self, line):
- return line == '\n'
+ return line == '\n' or line == '\r\n'
# Look through the list of headers and find all lines matching
@@ -178,27 +191,94 @@ class Message:
return string.strip(text)
- # XXX The next step would be to define self.getaddr(name)
- # and self.getaddrlist(name) which would parse a header
- # consisting of a single mail address and a number of mail
- # addresses, respectively. Lower level functions would be
- # parseaddr(string) and parseaddrlist(string).
+ # Retrieve a single address from a header as a tuple, e.g.
+ # ('Guido van Rossum', 'guido@cwi.nl').
+
+ def getaddr(self, name):
+ data = self.getheader(name)
+ if not data:
+ return None, None
+ return parseaddr(data)
+
+ # Retrieve a list of addresses from a header, where each
+ # address is a tuple as returned by getaddr().
+
+ def getaddrlist(self, name):
+ # XXX This function is not really correct. The split
+ # on ',' might fail in the case of commas within
+ # quoted strings.
+ data = self.getheader(name)
+ if not data:
+ return []
+ data = string.splitfields(data, ',')
+ for i in range(len(data)):
+ data[i] = parseaddr(data[i])
+ return data
+
+ # Retrieve a date field from a header as a tuple compatible
+ # with time.mktime().
+
+ def getdate(self, name):
+ data = self.getheader(name)
+ if not data:
+ return None
+ return parsedate(data)
+
- # XXX Similar, there would be a function self.getdate(name) to
- # return a date in canonical form (perhaps a number compatible
- # to time.time()) and a function parsedate(string).
+ # Access as a dictionary (only finds first header of each type):
- # XXX The inverses of the parse functions may also be useful.
+ def __len__(self):
+ types = {}
+ for line in self.headers:
+ if line[0] in string.whitespace: continue
+ i = string.find(line, ':')
+ if i > 0:
+ name = string.lower(line[:i])
+ types[name] = None
+ return len(types)
+
+ def __getitem__(self, name):
+ value = self.getheader(name)
+ if value is None: raise KeyError, name
+ return value
+
+ def has_key(self, name):
+ value = self.getheader(name)
+ return value is not None
+
+ def keys(self):
+ types = {}
+ for line in self.headers:
+ if line[0] in string.whitespace: continue
+ i = string.find(line, ':')
+ if i > 0:
+ name = line[:i]
+ key = string.lower(name)
+ types[key] = name
+ return types.values()
+ def values(self):
+ values = []
+ for name in self.keys():
+ values.append(self[name])
+ return values
+
+ def items(self):
+ items = []
+ for name in self.keys():
+ items.append(name, self[name])
+ return items
# Utility functions
# -----------------
+# XXX Should fix these to be really conformant.
+# XXX The inverses of the parse functions may also be useful.
+
# Remove quotes from a string.
-# XXX Should fix this to be really conformant.
def unquote(str):
if len(str) > 1:
@@ -207,3 +287,107 @@ def unquote(str):
if str[0] == '<' and str[-1:] == '>':
return str[1:-1]
return str
+
+
+# Parse an address into (name, address) tuple
+
+def parseaddr(address):
+ # This is probably not perfect
+ address = string.strip(address)
+ # Case 1: part of the address is in <xx@xx> form.
+ pos = regex.search('<.*>', address)
+ if pos >= 0:
+ name = address[:pos]
+ address = address[pos:]
+ length = regex.match('<.*>', address)
+ name = name + address[length:]
+ address = address[:length]
+ else:
+ # Case 2: part of the address is in (comment) form
+ pos = regex.search('(.*)', address)
+ if pos >= 0:
+ name = address[pos:]
+ address = address[:pos]
+ length = regex.match('(.*)', name)
+ address = address + name[length:]
+ name = name[:length]
+ else:
+ # Case 3: neither. Only an address
+ name = ''
+ name = string.strip(name)
+ address = string.strip(address)
+ if address and address[0] == '<' and address[-1] == '>':
+ address = address[1:-1]
+ if name and name[0] == '(' and name[-1] == ')':
+ name = name[1:-1]
+ return name, address
+
+
+# Parse a date field
+
+_monthnames = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
+ 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
+
+def parsedate(data):
+ # XXX This completely ignores timezone matters at the moment...
+ data = string.split(data)
+ if data[0][-1] == ',':
+ # There's a dayname here. Skip it
+ del data[0]
+ if len(data) < 5:
+ return None
+ data = data[:5]
+ [dd, mm, yy, tm, tz] = data
+ if not mm in _monthnames:
+ return None
+ mm = _monthnames.index(mm)+1
+ tm = string.splitfields(tm, ':')
+ if len(tm) == 2:
+ [thh, tmm] = tm
+ tss = '0'
+ else:
+ [thh, tmm, tss] = tm
+ try:
+ yy = string.atoi(yy)
+ dd = string.atoi(dd)
+ thh = string.atoi(thh)
+ tmm = string.atoi(tmm)
+ tss = string.atoi(tss)
+ except string.atoi_error:
+ return None
+ tuple = (yy, mm, dd, thh, tmm, tss, 0, 0, 0)
+ return tuple
+
+
+# When used as script, run a small test program.
+# The first command line argument must be a filename containing one
+# message in RFC-822 format.
+
+if __name__ == '__main__':
+ import sys
+ file = '/ufs/guido/Mail/drafts/,1'
+ if sys.argv[1:]: file = sys.argv[1]
+ f = open(file, 'r')
+ m = Message(f)
+ print 'From:', m.getaddr('from')
+ print 'To:', m.getaddrlist('to')
+ print 'Subject:', m.getheader('subject')
+ print 'Date:', m.getheader('date')
+ date = m.getdate('date')
+ if date:
+ print 'ParsedDate:', time.asctime(date)
+ else:
+ print 'ParsedDate:', None
+ m.rewindbody()
+ n = 0
+ while f.readline():
+ n = n + 1
+ print 'Lines:', n
+ print '-'*70
+ print 'len =', len(m)
+ if m.has_key('Date'): print 'Date =', m['Date']
+ if m.has_key('X-Nonsense'): pass
+ print 'keys =', m.keys()
+ print 'values =', m.values()
+ print 'items =', m.items()
+
diff --git a/Lib/sched.py b/Lib/sched.py
index c838bad..60b0a1b 100644
--- a/Lib/sched.py
+++ b/Lib/sched.py
@@ -6,12 +6,11 @@
#
# Each instance is parametrized with two functions, one that is
# supposed to return the current time, one that is supposed to
-# implement a delay. You can implement fine- or course-grained
-# real-time scheduling by substituting time and sleep or millitimer
-# and millisleep from the built-in module time, or you can implement
-# simulated time by writing your own functions. This can also be
-# used to integrate scheduling with STDWIN events; the delay function
-# is allowed to modify the queue. Time can be expressed as
+# implement a delay. You can implement real-time scheduling by
+# substituting time and sleep from built-in module time, or you can
+# implement simulated time by writing your own functions. This can
+# also be used to integrate scheduling with STDWIN events; the delay
+# function is allowed to modify the queue. Time can be expressed as
# integers or floating point numbers, as long as it is consistent.
# Events are specified by tuples (time, priority, action, argument).
diff --git a/Lib/stdwin/WindowSched.py b/Lib/stdwin/WindowSched.py
index 56ca6f8..b2fbe76 100755
--- a/Lib/stdwin/WindowSched.py
+++ b/Lib/stdwin/WindowSched.py
@@ -1,5 +1,5 @@
# Combine a real-time scheduling queue and stdwin event handling.
-# Uses the millisecond timer.
+# Keeps times in milliseconds.
import stdwin, stdwinq
from stdwinevents import WE_TIMER
@@ -19,11 +19,11 @@ def delayfunc(msecs):
mainloop.dispatch(event)
return
#
- # Use millisleep for very short delays or if there are no windows
+ # Use sleep for very short delays or if there are no windows
#
if msecs < 100 or mainloop.countwindows() == 0:
if msecs > 0:
- time.millisleep(msecs)
+ time.sleep(msecs * 0.001)
return
#
# Post a timer event on an arbitrary window and wait for it
@@ -35,7 +35,10 @@ def delayfunc(msecs):
if event[0] <> WE_TIMER:
mainloop.dispatch(event)
-q = sched.scheduler(time.millitimer, delayfunc)
+def millitimer():
+ return int(1000 * time.time())
+
+q = sched.scheduler(millitimer, delayfunc)
# Export functions enter, enterabs and cancel just like a scheduler
#
diff --git a/Lib/stdwin/filewin.py b/Lib/stdwin/filewin.py
index a03c3f7..df6aa7d 100755
--- a/Lib/stdwin/filewin.py
+++ b/Lib/stdwin/filewin.py
@@ -2,19 +2,19 @@
# File windows, a subclass of textwin (which is a subclass of gwin)
import textwin
-import builtin
+import __builtin__
# FILE WINDOW
def open_readonly(fn): # Open a file window
- fp = builtin.open(fn, 'r')
+ fp = __builtin__.open(fn, 'r')
w = textwin.open_readonly(fn, fp.read())
w.fn = fn
return w
def open(fn): # Open a file window
- fp = builtin.open(fn, 'r')
+ fp = __builtin__.open(fn, 'r')
w = textwin.open(fn, fp.read())
w.fn = fn
return w
diff --git a/Lib/stdwin/wdb.py b/Lib/stdwin/wdb.py
index d5c28bb..4018ab1 100755
--- a/Lib/stdwin/wdb.py
+++ b/Lib/stdwin/wdb.py
@@ -241,7 +241,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
stdwin.fleep()
def draw(self, detail):
- import linecache, codehack, string
+ import linecache, string
d = self.win.begindrawing()
try:
h, v = 0, 0
@@ -252,7 +252,7 @@ class Wdb(bdb.Bdb, basewin.BaseWindow): # Window debugger
else:
s = ' '
s = s + fn + '(' + `lineno` + ')'
- s = s + codehack.getcodename(f.f_code)
+ s = s + f.f_code.co_name
if f.f_locals.has_key('__args__'):
args = f.f_locals['__args__']
if args is not None:
@@ -286,6 +286,8 @@ def runcall(*args):
try: apply(x.runcall, args)
finally: x.close()
+def set_trace():
+ Wdb().set_trace()
# Post-Mortem interface
@@ -304,6 +306,4 @@ def pm():
TESTCMD = 'import x; x.main()'
def test():
- import linecache
- linecache.checkcache()
run(TESTCMD)
diff --git a/Lib/string.py b/Lib/string.py
index afe5bec..a37cbf0 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -95,30 +95,18 @@ def joinfields(words, sep):
# Find substring, raise exception if not found
index_error = 'substring not found in string.index'
-def index(s, sub, *args):
- if args:
- if len(args) > 1:
- raise TypeError, 'string.index(): too many args'
- i = args[0]
- if i < 0: i = i + len(s)
- else:
- i = 0
+def index(s, sub, i = 0):
+ if i < 0: i = i + len(s)
n = len(sub)
m = len(s) + 1 - n
while i < m:
if sub == s[i:i+n]: return i
i = i+1
- raise index_error, (s, sub) + args
+ raise index_error, (s, sub, i)
# Find last substring, raise exception if not found
-def rindex(s, sub, *args):
- if args:
- if len(args) > 1:
- raise TypeError, 'string.rindex(): too many args'
- i = args[0]
- if i < 0: i = i + len(s)
- else:
- i = 0
+def rindex(s, sub, i = 0):
+ if i < 0: i = i + len(s)
n = len(sub)
m = len(s) + 1 - n
r = None
@@ -126,20 +114,35 @@ def rindex(s, sub, *args):
if sub == s[i:i+n]: r = i
i = i+1
if r is None:
- raise index_error, (s, sub) + args
+ raise index_error, (s, sub, i)
+ return r
+
+# Count non-overlapping occurrences of substring
+def count(s, sub, i = 0):
+ if i < 0: i = i + len(s)
+ n = len(sub)
+ m = len(s) + 1 - n
+ if n == 0: return m-i
+ r = 0
+ while i < m:
+ if sub == s[i:i+n]:
+ r = r+1
+ i = i+n
+ else:
+ i = i+1
return r
# Find substring, return -1 if not found
-def find(*args):
+def find(s, sub, i = 0):
try:
- return apply(index, args)
+ return index(s, sub, i)
except index_error:
return -1
# Find last substring, return -1 if not found
-def rfind(*args):
+def rfind(s, sub, i = 0):
try:
- return apply(rindex, args)
+ return rindex(s, sub, i)
except index_error:
return -1
@@ -157,7 +160,7 @@ def atof(str):
if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
raise atof_error, str
try:
- return eval(sign + s)
+ return float(eval(sign + s))
except SyntaxError:
raise atof_error, str
@@ -242,12 +245,36 @@ def expandtabs(s, tabsize):
# it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase
# that match <ctype.h>'s definitions.
-# The manipulation with index_error is needed for compatibility.
try:
from strop import *
letters = lowercase + uppercase
+except ImportError:
+ pass # Use the original, slow versions
+
+# If certain functions are found, redefine the corresponding exceptions
+# as ValueError
+
+try:
from strop import index
index_error = ValueError
except ImportError:
pass # Use the original, slow versions
+
+try:
+ from strop import atoi
+ atoi_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
+
+try:
+ from strop import atof
+ atof_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
+
+try:
+ from strop import atol
+ atol_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
diff --git a/Lib/stringold.py b/Lib/stringold.py
index afe5bec..a37cbf0 100644
--- a/Lib/stringold.py
+++ b/Lib/stringold.py
@@ -95,30 +95,18 @@ def joinfields(words, sep):
# Find substring, raise exception if not found
index_error = 'substring not found in string.index'
-def index(s, sub, *args):
- if args:
- if len(args) > 1:
- raise TypeError, 'string.index(): too many args'
- i = args[0]
- if i < 0: i = i + len(s)
- else:
- i = 0
+def index(s, sub, i = 0):
+ if i < 0: i = i + len(s)
n = len(sub)
m = len(s) + 1 - n
while i < m:
if sub == s[i:i+n]: return i
i = i+1
- raise index_error, (s, sub) + args
+ raise index_error, (s, sub, i)
# Find last substring, raise exception if not found
-def rindex(s, sub, *args):
- if args:
- if len(args) > 1:
- raise TypeError, 'string.rindex(): too many args'
- i = args[0]
- if i < 0: i = i + len(s)
- else:
- i = 0
+def rindex(s, sub, i = 0):
+ if i < 0: i = i + len(s)
n = len(sub)
m = len(s) + 1 - n
r = None
@@ -126,20 +114,35 @@ def rindex(s, sub, *args):
if sub == s[i:i+n]: r = i
i = i+1
if r is None:
- raise index_error, (s, sub) + args
+ raise index_error, (s, sub, i)
+ return r
+
+# Count non-overlapping occurrences of substring
+def count(s, sub, i = 0):
+ if i < 0: i = i + len(s)
+ n = len(sub)
+ m = len(s) + 1 - n
+ if n == 0: return m-i
+ r = 0
+ while i < m:
+ if sub == s[i:i+n]:
+ r = r+1
+ i = i+n
+ else:
+ i = i+1
return r
# Find substring, return -1 if not found
-def find(*args):
+def find(s, sub, i = 0):
try:
- return apply(index, args)
+ return index(s, sub, i)
except index_error:
return -1
# Find last substring, return -1 if not found
-def rfind(*args):
+def rfind(s, sub, i = 0):
try:
- return apply(rindex, args)
+ return rindex(s, sub, i)
except index_error:
return -1
@@ -157,7 +160,7 @@ def atof(str):
if regex.match('[0-9]*\(\.[0-9]*\)?\([eE][-+]?[0-9]+\)?', s) != len(s):
raise atof_error, str
try:
- return eval(sign + s)
+ return float(eval(sign + s))
except SyntaxError:
raise atof_error, str
@@ -242,12 +245,36 @@ def expandtabs(s, tabsize):
# it redefines some string operations that are 100-1000 times faster.
# It also defines values for whitespace, lowercase and uppercase
# that match <ctype.h>'s definitions.
-# The manipulation with index_error is needed for compatibility.
try:
from strop import *
letters = lowercase + uppercase
+except ImportError:
+ pass # Use the original, slow versions
+
+# If certain functions are found, redefine the corresponding exceptions
+# as ValueError
+
+try:
from strop import index
index_error = ValueError
except ImportError:
pass # Use the original, slow versions
+
+try:
+ from strop import atoi
+ atoi_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
+
+try:
+ from strop import atof
+ atof_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
+
+try:
+ from strop import atol
+ atol_error = ValueError
+except ImportError:
+ pass # Use the original, slow versions
diff --git a/Lib/sunos4/FCNTL.py b/Lib/sunos4/FCNTL.py
index 0ba5e67..1256d81 100755
--- a/Lib/sunos4/FCNTL.py
+++ b/Lib/sunos4/FCNTL.py
@@ -1,10 +1,10 @@
+# Generated by h2py from stdin
_FOPEN = (-1)
_FREAD = 0x0001
_FWRITE = 0x0002
_FNDELAY = 0x0004
_FAPPEND = 0x0008
-_FMARK = 0x0010
-_FDEFER = 0x0020
+_FSETBLK = 0x0010
_FASYNC = 0x0040
_FSHLOCK = 0x0080
_FEXLOCK = 0x0100
@@ -15,6 +15,8 @@ _FNBIO = 0x1000
_FSYNC = 0x2000
_FNONBLOCK = 0x4000
_FNOCTTY = 0x8000
+_FMARK = 0x10000
+_FDEFER = 0x20000
O_RDONLY = 0
O_WRONLY = 1
O_RDWR = 2
@@ -25,7 +27,6 @@ O_EXCL = _FEXCL
O_NONBLOCK = _FNONBLOCK
O_NOCTTY = _FNOCTTY
O_SYNC = _FSYNC
-O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)
FAPPEND = _FAPPEND
FSYNC = _FSYNC
FASYNC = _FASYNC
@@ -36,6 +37,7 @@ FREAD = _FREAD
FWRITE = _FWRITE
FMARK = _FMARK
FDEFER = _FDEFER
+FSETBLK = _FSETBLK
FSHLOCK = _FSHLOCK
FEXLOCK = _FEXLOCK
FOPEN = _FOPEN
@@ -62,3 +64,4 @@ F_RDLCK = 1
F_WRLCK = 2
F_UNLCK = 3
F_UNLKSYS = 4
+O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)
diff --git a/Lib/sunos4/IN.py b/Lib/sunos4/IN.py
index 05188af..a05a944 100755
--- a/Lib/sunos4/IN.py
+++ b/Lib/sunos4/IN.py
@@ -1,8 +1,4 @@
-# Symbolic constants from <netinet/in.h>.
-# These constants are SunOS specific! (Possibly even SunOS 4.1.1)
-# See demo/scripts/h2py.py for a tool to help generate a version for
-# your system.
-
+# Generated by h2py from /usr/include/netinet/in.h
IPPROTO_IP = 0
IPPROTO_ICMP = 1
IPPROTO_IGMP = 2
diff --git a/Lib/sunos4/SOCKET.py b/Lib/sunos4/SOCKET.py
index c1b8542..65ce4bc 100755
--- a/Lib/sunos4/SOCKET.py
+++ b/Lib/sunos4/SOCKET.py
@@ -1,3 +1,4 @@
+# Generated by h2py from /usr/include/sys/socket.h
SOCK_STREAM = 1
SOCK_DGRAM = 2
SOCK_RAW = 3
diff --git a/Lib/sunos4/WAIT.py b/Lib/sunos4/WAIT.py
new file mode 100755
index 0000000..43612f0
--- /dev/null
+++ b/Lib/sunos4/WAIT.py
@@ -0,0 +1,13 @@
+# Generated by h2py from /usr/include/sys/wait.h
+WUNTRACED = 0004
+WNOHANG = 0100
+WEXITED = 0001
+WTRAPPED = 0002
+WSTOPPED = WUNTRACED
+WCONTINUED = 0010
+WNOWAIT = 0200
+WOPTMASK = (WEXITED|WTRAPPED|WSTOPPED|WCONTINUED|WNOHANG|WNOWAIT)
+WSTOPFLG = 0177
+WCONTFLG = 0177777
+WCOREFLG = 0200
+WSIGMASK = 0177
diff --git a/Lib/sunos4/regen b/Lib/sunos4/regen
index f1482db..8b52d74 100755
--- a/Lib/sunos4/regen
+++ b/Lib/sunos4/regen
@@ -8,4 +8,5 @@ set -v
h2py </usr/include/sys/fcntlcom.h >FCNTL.py
echo "O_ACCMODE = (O_RDONLY|O_WRONLY|O_RDWR)" >>FCNTL.py
h2py /usr/include/sys/socket.h
+h2py /usr/include/sys/wait.h
h2py -i '(u_long)' /usr/include/netinet/in.h
diff --git a/Lib/symbol.py b/Lib/symbol.py
index 1422f12..f3ec122 100755
--- a/Lib/symbol.py
+++ b/Lib/symbol.py
@@ -3,49 +3,49 @@
single_input = 256
file_input = 257
eval_input = 258
-lambda_input = 259
-funcdef = 260
-parameters = 261
-varargslist = 262
-fpdef = 263
-fplist = 264
-stmt = 265
-simple_stmt = 266
-small_stmt = 267
-expr_stmt = 268
-print_stmt = 269
-del_stmt = 270
-pass_stmt = 271
-flow_stmt = 272
-break_stmt = 273
-continue_stmt = 274
-return_stmt = 275
-raise_stmt = 276
-import_stmt = 277
-global_stmt = 278
-access_stmt = 279
-accesstype = 280
-exec_stmt = 281
-compound_stmt = 282
-if_stmt = 283
-while_stmt = 284
-for_stmt = 285
-try_stmt = 286
-except_clause = 287
-suite = 288
-test = 289
-and_test = 290
-not_test = 291
-comparison = 292
-comp_op = 293
-expr = 294
-xor_expr = 295
-and_expr = 296
-shift_expr = 297
-arith_expr = 298
-term = 299
-factor = 300
-atom = 301
+funcdef = 259
+parameters = 260
+varargslist = 261
+fpdef = 262
+fplist = 263
+stmt = 264
+simple_stmt = 265
+small_stmt = 266
+expr_stmt = 267
+print_stmt = 268
+del_stmt = 269
+pass_stmt = 270
+flow_stmt = 271
+break_stmt = 272
+continue_stmt = 273
+return_stmt = 274
+raise_stmt = 275
+import_stmt = 276
+global_stmt = 277
+access_stmt = 278
+accesstype = 279
+exec_stmt = 280
+compound_stmt = 281
+if_stmt = 282
+while_stmt = 283
+for_stmt = 284
+try_stmt = 285
+except_clause = 286
+suite = 287
+test = 288
+and_test = 289
+not_test = 290
+comparison = 291
+comp_op = 292
+expr = 293
+xor_expr = 294
+and_expr = 295
+shift_expr = 296
+arith_expr = 297
+term = 298
+factor = 299
+atom = 300
+lambdef = 301
trailer = 302
subscript = 303
exprlist = 304
diff --git a/Lib/test/test_b1.py b/Lib/test/test_b1.py
index 434b379..5eb4f09 100644
--- a/Lib/test/test_b1.py
+++ b/Lib/test/test_b1.py
@@ -97,6 +97,22 @@ if filter(None, [1, 'hello', [], [3], '', None, 9, 0]) <> [1, 'hello', [3], 9]:
raise TestFailed, 'filter (remove false values)'
if filter(lambda x: x > 0, [1, -3, 9, 0, 2]) <> [1, 9, 2]:
raise TestFailed, 'filter (keep positives)'
+class Squares:
+ def __init__(self, max):
+ self.max = max
+ self.sofar = []
+ def __len__(self): return len(self.sofar)
+ def __getitem__(self, i):
+ if not 0 <= i < self.max: raise IndexError
+ n = len(self.sofar)
+ while n <= i:
+ self.sofar.append(n*n)
+ n = n+1
+ return self.sofar[i]
+if filter(None, Squares(10)) != [1, 4, 9, 16, 25, 36, 49, 64, 81]:
+ raise TestFailed, 'filter(None, Squares(10))'
+if filter(lambda x: x%2, Squares(10)) != [1, 9, 25, 49, 81]:
+ raise TestFailed, 'filter(oddp, Squares(10))'
print 'float'
if float(3.14) <> 3.14: raise TestFailed, 'float(3.14)'
@@ -158,6 +174,14 @@ if map(plus, [1, 3, 7], [4, 9, 2]) <> [1+4, 3+9, 7+2]:
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2])'
if map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0]) <> [1+4+1, 3+9+1, 7+2+0]:
raise TestFailed, 'map(plus, [1, 3, 7], [4, 9, 2], [1, 1, 0])'
+if map(None, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
+ raise TestFailed, 'map(None, Squares(10))'
+if map(int, Squares(10)) != [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]:
+ raise TestFailed, 'map(int, Squares(10))'
+if map(None, Squares(3), Squares(2)) != [(0,0), (1,1), (4,None)]:
+ raise TestFailed, 'map(None: x, Squares(3), Squares(2))'
+if map(max, Squares(3), Squares(2)) != [0, 1, 4]:
+ raise TestFailed, 'map(None: x, Squares(3), Squares(2))'
print 'max'
if max('123123') <> '3': raise TestFailed, 'max(\'123123\')'
diff --git a/Lib/test/test_b2.py b/Lib/test/test_b2.py
index 7118b08..10c0bfb 100644
--- a/Lib/test/test_b2.py
+++ b/Lib/test/test_b2.py
@@ -121,6 +121,25 @@ if reduce(lambda x, y: x*y, range(2,8), 1) <> 5040:
raise TestFailed, 'reduce(): compute 7!'
if reduce(lambda x, y: x*y, range(2,21), 1L) <> 2432902008176640000L:
raise TestFailed, 'reduce(): compute 20!, use long'
+class Squares:
+ def __init__(self, max):
+ self.max = max
+ self.sofar = []
+ def __len__(self): return len(self.sofar)
+ def __getitem__(self, i):
+ if not 0 <= i < self.max: raise IndexError
+ n = len(self.sofar)
+ while n <= i:
+ self.sofar.append(n*n)
+ n = n+1
+ return self.sofar[i]
+if reduce(lambda x, y: x+y, Squares(10)) != 285:
+ raise TestFailed, 'reduce(<+>, Squares(10))'
+if reduce(lambda x, y: x+y, Squares(10), 0) != 285:
+ raise TestFailed, 'reduce(<+>, Squares(10), 0)'
+if reduce(lambda x, y: x+y, Squares(0), 0) != 0:
+ raise TestFailed, 'reduce(<+>, Squares(0), 0)'
+
print 'reload'
import string
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 0988574..67baf09 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -41,7 +41,7 @@ if maxint == 2147483647:
raise TestFailed, \
'No OverflowError on huge integer literal ' + `s`
elif eval('maxint == 9223372036854775807'):
- if eval('9223372036854775807-1 != -01000000000000000000000'):
+ if eval('-9223372036854775807-1 != 01000000000000000000000'):
raise TestFailed, 'max negative int'
if eval('01777777777777777777777') != -1: raise TestFailed, 'oct -1'
if eval('0xffffffffffffffff') != -1: raise TestFailed, 'hex -1'
@@ -91,9 +91,35 @@ x = '"'; y = "\""; assert(len(x) == 1 and x == y and ord(x) == 34)
x = "doesn't \"shrink\" does it"
y = 'doesn\'t "shrink" does it'
assert(len(x) == 24 and x == y)
-x = "doesn \"shrink\" doesn't it"
-y = 'doesn "shrink" doesn\'t it'
-assert(len(x) == 25 and x == y)
+x = "does \"shrink\" doesn't it"
+y = 'does "shrink" doesn\'t it'
+assert(len(x) == 24 and x == y)
+x = """
+The "quick"
+brown fox
+jumps over
+the 'lazy' dog.
+"""
+y = '\nThe "quick"\nbrown fox\njumps over\nthe \'lazy\' dog.\n'
+assert(x == y)
+y = '''
+The "quick"
+brown fox
+jumps over
+the 'lazy' dog.
+'''; assert(x == y)
+y = "\n\
+The \"quick\"\n\
+brown fox\n\
+jumps over\n\
+the 'lazy' dog.\n\
+"; assert(x == y)
+y = '\n\
+The \"quick\"\n\
+brown fox\n\
+jumps over\n\
+the \'lazy\' dog.\n\
+'; assert(x == y)
print '1.2 Grammar'
@@ -113,7 +139,8 @@ x = eval('1, 0 or 1')
print 'funcdef'
### 'def' NAME parameters ':' suite
### parameters: '(' [varargslist] ')'
-### varargslist: (fpdef ',')* '*' NAME | fpdef (',' fpdef)* [',']
+### varargslist: (fpdef ['=' test] ',')* '*' NAME
+### | fpdef ['=' test] (',' fpdef ['=' test])* [',']
### fpdef: NAME | '(' fplist ')'
### fplist: fpdef (',' fpdef)* [',']
def f1(): pass
@@ -126,6 +153,54 @@ def v0(*rest): pass
def v1(a, *rest): pass
def v2(a, b, *rest): pass
def v3(a, (b, c), *rest): pass
+def d01(a=1): pass
+d01()
+d01(1)
+def d11(a, b=1): pass
+d11(1)
+d11(1, 2)
+def d21(a, b, c=1): pass
+d21(1, 2)
+d21(1, 2, 3)
+def d02(a=1, b=2): pass
+d02()
+d02(1)
+d02(1, 2)
+def d12(a, b=1, c=2): pass
+d12(1)
+d12(1, 2)
+d12(1, 2, 3)
+def d22(a, b, c=1, d=2): pass
+d22(1, 2)
+d22(1, 2, 3)
+d22(1, 2, 3, 4)
+def d01v(a=1, *rest): pass
+d01v()
+d01v(1)
+d01v(1, 2)
+def d11v(a, b=1, *rest): pass
+d11v(1)
+d11v(1, 2)
+d11v(1, 2, 3)
+def d21v(a, b, c=1, *rest): pass
+d21v(1, 2)
+d21v(1, 2, 3)
+d21v(1, 2, 3, 4)
+def d02v(a=1, b=2, *rest): pass
+d02v()
+d02v(1)
+d02v(1, 2)
+d02v(1, 2, 3)
+def d12v(a, b=1, c=2, *rest): pass
+d12v(1)
+d12v(1, 2)
+d12v(1, 2, 3)
+d12v(1, 2, 3, 4)
+def d22v(a, b, c=1, d=2, *rest): pass
+d22v(1, 2)
+d22v(1, 2, 3)
+d22v(1, 2, 3, 4)
+d22v(1, 2, 3, 4, 5)
### stmt: simple_stmt | compound_stmt
# Tested below
@@ -184,17 +259,11 @@ try: raise KeyboardInterrupt
except KeyboardInterrupt: pass
print 'import_stmt' # 'import' NAME (',' NAME)* | 'from' NAME 'import' ('*' | NAME (',' NAME)*)
-[1]
import sys
-[2]
import time, math
-[3]
-from time import sleep
-[4]
+from time import time
from sys import *
-[5]
from math import sin, cos
-[6]
print 'global_stmt' # 'global' NAME (',' NAME)*
def f():
@@ -242,24 +311,41 @@ while 0: pass
else: pass
print 'for_stmt' # 'for' exprlist 'in' exprlist ':' suite ['else' ':' suite]
-[1]
for i in 1, 2, 3: pass
-[2]
for i, j, k in (): pass
else: pass
-[3]
-
-print 'try_stmt' # 'try' ':' suite (except_clause ':' suite)+ | 'try' ':' suite 'finally' ':' suite
+class Squares:
+ def __init__(self, max):
+ self.max = max
+ self.sofar = []
+ def __len__(self): return len(self.sofar)
+ def __getitem__(self, i):
+ if not 0 <= i < self.max: raise IndexError
+ n = len(self.sofar)
+ while n <= i:
+ self.sofar.append(n*n)
+ n = n+1
+ return self.sofar[i]
+n = 0
+for x in Squares(10): n = n+x
+if n != 285: raise TestFailed, 'for over growing sequence'
+
+print 'try_stmt'
+### try_stmt: 'try' ':' suite (except_clause ':' suite)+ ['else' ':' suite]
+### | 'try' ':' suite 'finally' ':' suite
### except_clause: 'except' [expr [',' expr]]
try:
1/0
except ZeroDivisionError:
pass
+else:
+ pass
try: 1/0
except EOFError: pass
except TypeError, msg: pass
except RuntimeError, msg: pass
except: pass
+else: pass
try: 1/0
except (EOFError, TypeError, ZeroDivisionError): pass
try: 1/0
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 0a43de3..6a3f772 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -67,6 +67,10 @@ if (-12) + 24 <> 12: raise TestFailed, 'int op'
if (-12) + (-24) <> -36: raise TestFailed, 'int op'
if not 12 < 24: raise TestFailed, 'int op'
if not -24 < -12: raise TestFailed, 'int op'
+# Test for a particular bug in integer multiply
+xsize, ysize, zsize = 238, 356, 4
+if not (xsize*ysize*zsize == zsize*xsize*ysize == 338912):
+ raise TestFailed, 'int mul commutativity'
print '6.4.2 Long integers'
if 12L + 24L <> 36L: raise TestFailed, 'long op'
if 12L + (-24L) <> -12L: raise TestFailed, 'long op'
@@ -94,6 +98,8 @@ if 0*'abcde' <> '': raise TestFailed, 'string repetition 0*'
if min('abc') <> 'a' or max('abc') <> 'c': raise TestFailed, 'min/max string'
if 'a' in 'abc' and 'b' in 'abc' and 'c' in 'abc' and 'd' not in 'abc': pass
else: raise TestFailed, 'in/not in string'
+x = 'x'*103
+if '%s!'%x != x+'!': raise TestFailed, 'nasty string formatting bug'
print '6.5.2 Tuples'
if len(()) <> 0: raise TestFailed, 'len(())'
diff --git a/Lib/test/testall.out b/Lib/test/testall.out
index 46a728e..b921512 100644
--- a/Lib/test/testall.out
+++ b/Lib/test/testall.out
@@ -15,8 +15,6 @@ eval_input
funcdef
simple_stmt
expr_stmt
-1
-(1, 2, 3)
print_stmt
1 2 3
1 2 3
@@ -29,20 +27,11 @@ continue_stmt
return_stmt
raise_stmt
import_stmt
-[1]
-[2]
-[3]
-[4]
-[5]
-[6]
global_stmt
exec_stmt
if_stmt
while_stmt
for_stmt
-[1]
-[2]
-[3]
try_stmt
suite
test
diff --git a/Lib/tzparse.py b/Lib/tzparse.py
index 26824ab..ef325e9 100644
--- a/Lib/tzparse.py
+++ b/Lib/tzparse.py
@@ -12,7 +12,7 @@ def tzparse(tzstr):
if tzprog == None:
import regex
tzprog = regex.compile(tzpat)
- if not tzprog.match(tzstr):
+ if tzprog.match(tzstr) < 0:
raise ValueError, 'not the TZ syntax I understand'
regs = tzprog.regs
subs = []
@@ -78,5 +78,3 @@ def test():
x = localtime(t)
tm = x[:-1] + (0,)
print 'd =', d, 't =', t, '=', asctime(tm), x[-1]
-
-test()
diff --git a/Lib/whrandom.py b/Lib/whrandom.py
index c7881b5..670ca7a 100644
--- a/Lib/whrandom.py
+++ b/Lib/whrandom.py
@@ -35,31 +35,25 @@ class whrandom:
# Without arguments, initialize from current time.
# With arguments (x, y, z), initialize from them.
#
- def __init__(self, *xyz):
- if not xyz:
+ def __init__(self, x = None, y = None, z = None):
+ if x is None:
# Initialize from current time
import time
t = int(time.time())
t, x = divmod(t, 256)
t, y = divmod(t, 256)
t, z = divmod(t, 256)
- else:
- # Initialize from arguments (x, y, z)
- x, y, z = xyz
self.seed(x, y, z)
#
# Set the seed from (x, y, z).
# These must be integers in the range [0, 256).
#
- def seed(self, *xyz):
- if type(xyz) <> type(()) or len(xyz) <> 3:
- raise TypeError, '3 seeds required'
- x, y, z = xyz
+ def seed(self, x, y, z):
if not type(x) == type(y) == type(z) == type(0):
raise TypeError, 'seeds must be integers'
if not 0 <= x < 256 and 0 <= y < 256 and 0 <= z < 256:
raise ValueError, 'seeds must be in range(0, 256)'
- self._seed = xyz
+ self._seed = (x, y, z)
#
# Get the next random number in the range [0.0, 1.0).
#
diff --git a/Modules/Makefile.pre.in b/Modules/Makefile.pre.in
index e8e4a20..0b4fa5b 100644
--- a/Modules/Makefile.pre.in
+++ b/Modules/Makefile.pre.in
@@ -1,39 +1,46 @@
-# NOTE: Makefile.in.in is converted into Makefile.in by running the
-# makesetup script in the current directory. Makefile.in is converted
-# into Makefile by the configure script in the toplevel directory.
-# Once Makefile exists, it can be brought up to date by running
-# "make Makefile".
+# META-NOTE: this note is different from the note in the other Makefiles!
+# NOTE: Makefile.pre.in is converted into Makefile.pre by the configure
+# script in the toplevel directory or by ../config.status.
+# Makefile.pre is converted into Makefile by running the makesetup
+# script in the source directory. Once Makefile exists, it can be
+# brought up to date by running "make Makefile". (The makesetup also
+# creates config.c from config.c.in in the source directory.)
-# === Variables set by ./makesetup ===
+# === Variables set by makesetup ===
MODOBJS= @MODOBJS@
MODLIBS= @MODLIBS@
-MODCPPS= @MODCPPS@
-# === Definitions added by ./makesetup ===
+# === Definitions added by makesetup ===
-# === Variables set by $(TOP)/configure ===
+# === Variables set by configure ===
srcdir= @srcdir@
VPATH= @srcdir@
CC= @CC@
RANLIB= @RANLIB@
+AR= @AR@
+
DEFS= @DEFS@
LIBS= @LIBS@
+LIBM= @LIBM@
+LIBC= @LIBC@
+
+# Install prefix, may be changed by configure
+prefix= /usr/local
# === Variables that are customizable by hand ===
-TOP= ..
-INCLDIR= $(TOP)/Include
-OPT= -g
-CFLAGS= $(OPT) -I$(INCLDIR) $(DEFS)
+INCLDIR= $(srcdir)/../Include
+OPT= -O
+CFLAGS= $(OPT) -I$(INCLDIR) -I.. $(DEFS)
-AR= ar
MKDEP= mkdep
SHELL= /bin/sh
+MAKESETUP= $(srcdir)/makesetup
# === Fixed definitions ===
@@ -46,46 +53,88 @@ MYLIBS= $(LIB) \
../Objects/libObjects.a \
../Parser/libParser.a
-SYSLIBS= $(MODLIBS) -lm
+SYSLIBS= $(LIBM) $(LIBC)
# === Rules ===
-all: $(LIB) $(TOP)/python
+all: $(LIB) ../python
$(LIB): $(OBJS)
$(AR) cr $(LIB) $(OBJS)
$(RANLIB) $(LIB)
-$(TOP)/python: config.o $(MYLIBS)
- $(CC) config.o $(MYLIBS) $(LIBS) $(SYSLIBS) -o python
- mv python $(TOP)/python
+../python: config.o $(MYLIBS)
+ $(CC) config.o $(MYLIBS) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python
+ mv python ../python
-config.o: Makefile
+config.o: config.c Makefile
+ $(CC) $(CFLAGS) -DPYTHONPATH=\"$(PYTHONPATH)\" -c config.c
clean:
-rm -f *.o python core *~ [@,#]* *.old *.orig *.rej
clobber: clean
- -rm -f *.a tags TAGS
-
-Makefile: Makefile.in $(TOP)/config.status
- CONFIG_FILES=Makefile CONFIG_HEADERS= \
- $(SHELL) $(TOP)/config.status
+ -rm -f *.a tags TAGS config.c glmodule.c Makefile.pre
-config.c Makefile.in: Makefile.in.in config.c.in Setup makesetup
- $(SHELL) ./makesetup Setup
+config.c Makefile: Makefile.pre config.c.in $(MAKESETUP) Setup
+ $(SHELL) $(MAKESETUP) Setup
-depend:
- $(MKDEP) $(CFLAGS) \
- `echo $(OBJS) | tr ' ' '\012' | sed 's/\.o/.c/'`
-
-.PRECIOUS: Makefile.in Makefile config.c
+Setup:
+ cp $(srcdir)/Setup.in Setup
-glmodule.c: cgen.py cstubs
- python cgen.py <cstubs >glmodule.c
+Makefile.pre: Makefile.pre.in ../config.status
+ (cd ..; CONFIG_FILES=Modules/Makefile.pre CONFIG_HEADERS= \
+ $(SHELL) config.status)
-# === Rules added by ./makesetup ===
+depend:
+ $(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \
+ sed 's|\(.*\)\.o|$(srcdir)/\1.c|'`
+
+.PRECIOUS: ../python
+
+glmodule.c: $(srcdir)/cgen.py $(srcdir)/cstubs
+ python $(srcdir)/cgen.py <$(srcdir)/cstubs >glmodule.c
+
+almodule.o: almodule.c
+arraymodule.o: arraymodule.c
+audioopmodule.o: audioopmodule.c
+cdmodule.o: cdmodule.c
+clmodule.o: clmodule.c
+dbmmodule.o: dbmmodule.c
+fcntlmodule.o: fcntlmodule.c
+flmodule.o: flmodule.c
+fmmodule.o: fmmodule.c
+glmodule.o: glmodule.c
+imageopmodule.o: imageopmodule.c
+imgfilemodule.o: imgfilemodule.c
+mathmodule.o: mathmodule.c
+md5c.o: md5c.c
+md5module.o: md5module.c
+mpzmodule.o: mpzmodule.c
+nismodule.o: nismodule.c
+parsermodule.o: parsermodule.c
+posixmodule.o: posixmodule.c
+pwdmodule.o: pwdmodule.c
+regexmodule.o: regexmodule.c
+regexpr.o: regexpr.c
+rgbimgmodule.o: rgbimgmodule.c
+rotormodule.o: rotormodule.c
+selectmodule.o: selectmodule.c
+sgimodule.o: sgimodule.c
+socketmodule.o: socketmodule.c
+stdwinmodule.o: stdwinmodule.c
+stropmodule.o: stropmodule.c
+structmodule.o: structmodule.c
+sunaudiodevmodule.o: sunaudiodevmodule.c
+svmodule.o: svmodule.c
+threadmodule.o: threadmodule.c
+timemodule.o: timemodule.c
+timingmodule.o: timingmodule.c
+xxmodule.o: xxmodule.c
+yuvconvert.o: yuvconvert.c
+
+# === Rules added by makesetup ===
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/Modules/Setup.in b/Modules/Setup.in
index 7dd40fd..f7b5bace 100644
--- a/Modules/Setup.in
+++ b/Modules/Setup.in
@@ -1,7 +1,16 @@
-# This file is used by the makesetup script to construct Makefile.in
-# and config.c, from Makefile.in.in (sic!) and config.c.in,
-# respectively.
-#
+# The file Setup is used by the makesetup script to construct the files
+# Makefile and config.c, from Makefile.pre and config.c.in,
+# respectively. The file Setup itself is initially copied from
+# Setup.in; once it exists it will not be overwritten, so you can edit
+# Setup to your heart's content. One possibility is to overwrite it
+# with a copy of Setup.sgi or Setup.sunos[45] before you start editing.
+# Note that Makefile.pre is created from Makefile.pre.in by the toplevel
+# configure script.
+
+# (VPATH notes: Setup and Makefile.pre are in the build directory, as
+# are Makefile and config.c; Setup.in and config.c.in are in the source
+# directory.)
+
# Each line in this file describes one or more optional modules.
# Comment out lines to suppress modules.
# Lines have the following structure:
@@ -19,7 +28,7 @@
# <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
@@ -28,6 +37,28 @@
# 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 add any whitespace or comments!
+
+# 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
@@ -41,18 +72,25 @@ 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.
+# (If you have a really backward UNIX, select and socket may not be
+# supported...)
-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)
+pwd pwdmodule.o # pwd(3)
+grp grpmodule.o # 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 -- off by default
+# Some more UNIX dependent modules -- off by default, since these
+# are not supported by all UNIX systems.
+
+#dbm dbmmodule.o # dbm(3) may require -lndbm or similar
+#nis nismodule.o # Sun yellow pages -- not everywhere
+
+
+# Multimedia modules -- on by default.
# These represent audio samples or images as strings
audioop audioopmodule.o # Operations on audio samples
@@ -69,7 +107,7 @@ rgbimg rgbimgmodule.o # Read SGI RGB image files (but coded portably)
# "-lX11_s".
#STDWIN=/ufs/guido/src/stdwin
-#ARCH=sgi
+#ARCH=???
#stdwin stdwinmodule.o -I$(STDWIN)/H $(STDWIN)/Build/$(ARCH)/x11/lib/lib.a -lX11
@@ -81,10 +119,12 @@ 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.
+# You need to ftp the GNU MP library.
+# The GMP variable must point to the GMP source directory.
+# This was originally written and tested against GMP 1.2. I have
+# compiled it against GMP 1.3.2 (the latest I believe) and it seems to
+# work OK, but I haven't tested it thoroughly (lacking knowledge about
+# it).
#GMP=/ufs/guido/src/gmp
#mpz mpzmodule.o -I$(GMP) $(GMP)/libgmp.a
@@ -102,12 +142,13 @@ rotor rotormodule.o
# 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
+# # ADD THESE FOR IRIX5:
+#al almodule.o -laudio
+#cd cdmodule.o -lcdaudio -lds # -lmediad
+#cl clmodule.o -lcl # -lawareaudio
#fm fmmodule.o -lfm_s -lgl_s
-#gl glmodule.o -lgl_s
-#imgfile imgfilemodule.o -limage -lgutil -lm
+#gl glmodule.o -lgl_s -lX11_s
+#imgfile imgfilemodule.o -limage -lgutil
#sgi sgimodule.o
#sv svmodule.o yuvconvert.o -lsvideo -lXext -lX11_s
@@ -134,6 +175,34 @@ rotor rotormodule.o
# thread threadmodule.o
+# GNN's timing module
+# timing timingmodule.o
+
+
+# Lance Ellinghouse's signal module
+# signal signalmodule.o
+
+
+# Tommy Burnette's 'new' module (creates new empty objects of certain kinds)
+# new newmodule.o
+
+
+# John Redford's sybase module
+# sybase sybasemodule.o
+
+
+# Generic (SunOS / SVR4) dynamic loading module
+# dl dlmodule.o
+
+
+# Jack Jansen's imgformat module
+# imgformat imgformatmodule.o
+
+
+# Lance Ellinghouse's syslog module
+# syslog syslogmodule.o
+
+
# Example -- included for reference only
# xx xxmodule.o
diff --git a/Modules/almodule.c b/Modules/almodule.c
index d731eff..2ab60d4 100644
--- a/Modules/almodule.c
+++ b/Modules/almodule.c
@@ -1,5 +1,5 @@
/**********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -24,7 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* AL module -- interface to Mark Callow's Audio Library (AL). */
-#include "audio.h"
+#include <audio.h>
/* Check which version audio library we have: */
#ifdef AL_ERROR_NUMBER
@@ -50,7 +50,7 @@ typedef struct {
ALconfig ob_config;
} configobject;
-extern typeobject Configtype; /* Forward */
+staticforward typeobject Configtype;
#define is_configobject(v) ((v)->ob_type == &Configtype)
@@ -184,17 +184,17 @@ al_setfloatmax(self, args)
#endif /* AL_405 */
static struct methodlist config_methods[] = {
- {"getqueuesize", al_getqueuesize},
- {"setqueuesize", al_setqueuesize},
- {"getwidth", al_getwidth},
- {"setwidth", al_setwidth},
- {"getchannels", al_getchannels},
- {"setchannels", al_setchannels},
+ {"getqueuesize", (method)al_getqueuesize},
+ {"setqueuesize", (method)al_setqueuesize},
+ {"getwidth", (method)al_getwidth},
+ {"setwidth", (method)al_setwidth},
+ {"getchannels", (method)al_getchannels},
+ {"setchannels", (method)al_setchannels},
#ifdef AL_405
- {"getsampfmt", al_getsampfmt},
- {"setsampfmt", al_setsampfmt},
- {"getfloatmax", al_getfloatmax},
- {"setfloatmax", al_setfloatmax},
+ {"getsampfmt", (method)al_getsampfmt},
+ {"setsampfmt", (method)al_setsampfmt},
+ {"getfloatmax", (method)al_getfloatmax},
+ {"setfloatmax", (method)al_setfloatmax},
#endif /* AL_405 */
{NULL, NULL} /* sentinel */
};
@@ -215,16 +215,16 @@ config_getattr(self, name)
return findmethod(config_methods, (object *)self, name);
}
-typeobject Configtype = {
+static typeobject Configtype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"config", /*tp_name*/
sizeof(configobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- config_dealloc, /*tp_dealloc*/
+ (destructor)config_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- config_getattr, /*tp_getattr*/
+ (getattrfunc)config_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -250,7 +250,7 @@ typedef struct {
ALport ob_port;
} portobject;
-extern typeobject Porttype; /* Forward */
+staticforward typeobject Porttype;
#define is_portobject(v) ((v)->ob_type == &Porttype)
@@ -489,20 +489,19 @@ al_getstatus (self, args)
#endif /* AL_405 */
static struct methodlist port_methods[] = {
- {"closeport", al_closeport},
- {"close", al_closeport},
- {"getfd", al_getfd},
- {"fileno", al_getfd},
- {"getfilled", al_getfilled},
- {"getfillable", al_getfillable},
- {"readsamps", al_readsamps},
- {"writesamps", al_writesamps},
- {"setfillpoint", al_setfillpoint},
- {"getfillpoint", al_getfillpoint},
- {"setconfig", al_setconfig},
- {"getconfig", al_getconfig},
+ {"closeport", (method)al_closeport},
+ {"getfd", (method)al_getfd},
+ {"fileno", (method)al_getfd},
+ {"getfilled", (method)al_getfilled},
+ {"getfillable", (method)al_getfillable},
+ {"readsamps", (method)al_readsamps},
+ {"writesamps", (method)al_writesamps},
+ {"setfillpoint", (method)al_setfillpoint},
+ {"getfillpoint", (method)al_getfillpoint},
+ {"setconfig", (method)al_setconfig},
+ {"getconfig", (method)al_getconfig},
#ifdef AL_405
- {"getstatus", al_getstatus},
+ {"getstatus", (method)al_getstatus},
#endif /* AL_405 */
{NULL, NULL} /* sentinel */
};
@@ -524,16 +523,16 @@ port_getattr(p, name)
return findmethod(port_methods, (object *)p, name);
}
-typeobject Porttype = {
+static typeobject Porttype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"port", /*tp_name*/
sizeof(portobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- port_dealloc, /*tp_dealloc*/
+ (destructor)port_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- port_getattr, /*tp_getattr*/
+ (getattrfunc)port_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -736,14 +735,14 @@ al_getminmax(self, args)
}
static struct methodlist al_methods[] = {
- {"openport", al_openport},
- {"newconfig", al_newconfig},
- {"queryparams", al_queryparams},
- {"getparams", al_getparams},
- {"setparams", al_setparams},
- {"getname", al_getname},
- {"getdefault", al_getdefault},
- {"getminmax", al_getminmax},
+ {"openport", (method)al_openport},
+ {"newconfig", (method)al_newconfig},
+ {"queryparams", (method)al_queryparams},
+ {"getparams", (method)al_getparams},
+ {"setparams", (method)al_setparams},
+ {"getname", (method)al_getname},
+ {"getdefault", (method)al_getdefault},
+ {"getminmax", (method)al_getminmax},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 925a52d..4b89ad9 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -30,22 +30,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
#include "modsupport.h"
#include "ceval.h"
-
-#ifdef i860
-/* Cray APP doesn't have memmove */
-#define NEED_MEMMOVE
-extern char *memcpy();
-#endif
-
-#if defined(sun) && !defined(__STDC__)
-/* SunOS doesn't have memmove */
-#define NEED_MEMMOVE
-extern char *memcpy();
-#endif
-
-#ifdef NEED_MEMMOVE
-extern char *memmove();
-#endif
+#include <sys/types.h> /* For size_t */
struct arrayobject; /* Forward */
@@ -62,7 +47,7 @@ typedef struct arrayobject {
struct arraydescr *ob_descr;
} arrayobject;
-extern typeobject Arraytype;
+staticforward typeobject Arraytype;
#define is_arrayobject(op) ((op)->ob_type == &Arraytype)
@@ -252,7 +237,7 @@ newarrayobject(size, descr)
{
int i;
arrayobject *op;
- MALLARG nbytes;
+ size_t nbytes;
int itemsize;
if (size < 0) {
err_badcall();
@@ -962,22 +947,22 @@ array_tostring(self, args)
}
static struct methodlist array_methods[] = {
- {"append", array_append},
- {"byteswap", array_byteswap},
-/* {"count", array_count},*/
- {"fromfile", array_fromfile},
- {"fromlist", array_fromlist},
- {"fromstring", array_fromstring},
-/* {"index", array_index},*/
- {"insert", array_insert},
- {"read", array_fromfile},
-/* {"remove", array_remove},*/
- {"reverse", array_reverse},
-/* {"sort", array_sort},*/
- {"tofile", array_tofile},
- {"tolist", array_tolist},
- {"tostring", array_tostring},
- {"write", array_tofile},
+ {"append", (method)array_append},
+ {"byteswap", (method)array_byteswap},
+/* {"count", (method)array_count},*/
+ {"fromfile", (method)array_fromfile},
+ {"fromlist", (method)array_fromlist},
+ {"fromstring", (method)array_fromstring},
+/* {"index", (method)array_index},*/
+ {"insert", (method)array_insert},
+ {"read", (method)array_fromfile},
+/* {"remove", (method)array_remove},*/
+ {"reverse", (method)array_reverse},
+/* {"sort", (method)array_sort},*/
+ {"tofile", (method)array_tofile},
+ {"tolist", (method)array_tolist},
+ {"tostring", (method)array_tostring},
+ {"write", (method)array_tofile},
{NULL, NULL} /* sentinel */
};
@@ -1060,65 +1045,51 @@ array_repr(a)
v = array_tostring(a, (object *)NULL);
t = reprobject(v);
XDECREF(v);
- joinstring(&s, t);
- XDECREF(t);
- t = newstringobject(")");
- joinstring(&s, t);
- XDECREF(t);
- if (err_occurred()) {
- XDECREF(s);
- s = NULL;
- }
+ joinstring_decref(&s, t);
+ joinstring_decref(&s, newstringobject(")"));
return s;
}
sprintf(buf, "array('%c', [", a->ob_descr->typecode);
s = newstringobject(buf);
comma = newstringobject(", ");
for (i = 0; i < len && !err_occurred(); i++) {
+ if (i > 0)
+ joinstring(&s, comma);
v = (a->ob_descr->getitem)(a, i);
t = reprobject(v);
XDECREF(v);
- if (i > 0)
- joinstring(&s, comma);
- joinstring(&s, t);
- XDECREF(t);
+ joinstring_decref(&s, t);
}
XDECREF(comma);
- t = newstringobject("])");
- joinstring(&s, t);
- XDECREF(t);
- if (err_occurred()) {
- XDECREF(s);
- s = NULL;
- }
+ joinstring_decref(&s, newstringobject("])"));
return s;
}
static sequence_methods array_as_sequence = {
- array_length, /*sq_length*/
- array_concat, /*sq_concat*/
- array_repeat, /*sq_repeat*/
- array_item, /*sq_item*/
- array_slice, /*sq_slice*/
- array_ass_item, /*sq_ass_item*/
- array_ass_slice, /*sq_ass_slice*/
+ (inquiry)array_length, /*sq_length*/
+ (binaryfunc)array_concat, /*sq_concat*/
+ (intargfunc)array_repeat, /*sq_repeat*/
+ (intargfunc)array_item, /*sq_item*/
+ (intintargfunc)array_slice, /*sq_slice*/
+ (intobjargproc)array_ass_item, /*sq_ass_item*/
+ (intintobjargproc)array_ass_slice, /*sq_ass_slice*/
};
-typeobject Arraytype = {
+static typeobject Arraytype = {
OB_HEAD_INIT(&Typetype)
0,
"array",
sizeof(arrayobject),
0,
- array_dealloc, /*tp_dealloc*/
- array_print, /*tp_print*/
- array_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- array_compare, /*tp_compare*/
- array_repr, /*tp_repr*/
- 0, /*tp_as_number*/
- &array_as_sequence, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
+ (destructor)array_dealloc, /*tp_dealloc*/
+ (printfunc)array_print, /*tp_print*/
+ (getattrfunc)array_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ (cmpfunc)array_compare, /*tp_compare*/
+ (reprfunc)array_repr, /*tp_repr*/
+ 0, /*tp_as_number*/
+ &array_as_sequence, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
};
@@ -1187,33 +1158,3 @@ initarray()
{
initmodule("array", a_methods);
}
-
-
-#ifdef NEED_MEMMOVE
-
-/* A perhaps slow but I hope correct implementation of memmove */
-
-char *memmove(dst, src, n)
- char *dst;
- char *src;
- int n;
-{
- char *realdst = dst;
- if (n <= 0)
- return dst;
- if (src >= dst+n || dst >= src+n)
- return memcpy(dst, src, n);
- if (src > dst) {
- while (--n >= 0)
- *dst++ = *src++;
- }
- else if (src < dst) {
- src += n;
- dst += n;
- while (--n >= 0)
- *--dst = *--src;
- }
- return realdst;
-}
-
-#endif
diff --git a/Modules/audioop.c b/Modules/audioop.c
index 8bd833a..cfb97f2 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -22,17 +22,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
-/* audioopmodele - Module to detect peak values in arrays */
+/* audioopmodule - Module to detect peak values in arrays */
-#ifdef sun
-#define signed
+#include "allobjects.h"
+#include "modsupport.h"
+
+#if defined(__CHAR_UNSIGNED__) && defined(signed)
+!ERROR!; READ THE SOURCE FILE!;
+/* This module currently does not work on systems where only unsigned
+ characters are available. Take it out of Setup. Sorry. */
#endif
#include <math.h>
-#include "allobjects.h"
-#include "modsupport.h"
-
/* Code shamelessly stolen from sox,
** (c) Craig Reese, Joe Campbell and Jeff Poskanzer 1989 */
@@ -213,32 +215,6 @@ audioop_max(self, args)
}
static object *
-audioop_minmax(self, args)
- object *self;
- object *args;
-{
- signed char *cp;
- int len, size, val;
- int i;
- int min = 0x7fffffff, max = -0x7fffffff;
-
- if (!getargs(args, "(s#i)", &cp, &len, &size))
- return NULL;
- if (size != 1 && size != 2 && size != 4) {
- err_setstr(AudioopError, "Size should be 1, 2 or 4");
- return NULL;
- }
- for (i = 0; i < len; i += size) {
- if (size == 1) val = (int) *CHARP(cp, i);
- else if (size == 2) val = (int) *SHORTP(cp, i);
- else if (size == 4) val = (int) *LONGP(cp, i);
- if (val > max) max = val;
- if (val < min) min = val;
- }
- return mkvalue("(ii)", min, max);
-}
-
-static object *
audioop_avg(self, args)
object *self;
object *args;
@@ -997,136 +973,6 @@ audioop_ulaw2lin(self, args)
}
static object *
-audioop_lin2adpcm3(self, args)
- object *self;
- object *args;
-{
- signed char *cp;
- signed char *ncp;
- int len, size, val, step, valprev, delta;
- object *rv, *state, *str;
- int i;
-
- if ( !getargs(args, "(s#iO)",
- &cp, &len, &size, &state) )
- return 0;
-
-
- if ( size != 1 && size != 2 && size != 4) {
- err_setstr(AudioopError, "Size should be 1, 2 or 4");
- return 0;
- }
-
- str = newsizedstringobject(NULL, len/size);
- if ( str == 0 )
- return 0;
- ncp = (signed char *)getstringvalue(str);
-
- /* Decode state, should have (value, step) */
- if ( state == None ) {
- /* First time, it seems. Set defaults */
- valprev = 0;
- step = 4; /* The '4' is magic. Dunno it's significance */
- } else if ( !getargs(state, "(ii)", &valprev, &step) )
- return 0;
-
- for ( i=0; i < len; i += size ) {
- if ( size == 1 ) val = ((int)*CHARP(cp, i)) << 8;
- else if ( size == 2 ) val = (int)*SHORTP(cp, i);
- else if ( size == 4 ) val = ((int)*LONGP(cp, i)) >> 16;
-
- /* Step 1 - compute difference with previous value */
- delta = (val - valprev)/step;
-
- /* Step 2 - Clamp */
- if ( delta < -4 )
- delta = -4;
- else if ( delta > 3 )
- delta = 3;
-
- /* Step 3 - Update previous value */
- valprev += delta*step;
-
- /* Step 4 - Clamp previous value to 16 bits */
- if ( valprev > 32767 )
- valprev = 32767;
- else if ( valprev < -32768 )
- valprev = -32768;
-
- /* Step 5 - Update step value */
- step = step * newstep[abs(delta)];
- step++; /* Don't understand this. */
-
- /* Step 6 - Output value (as a whole byte, currently) */
- *ncp++ = delta;
- }
- rv = mkvalue("(O(ii))", str, valprev, step);
- DECREF(str);
- return rv;
-}
-
-static object *
-audioop_adpcm32lin(self, args)
- object *self;
- object *args;
-{
- signed char *cp;
- signed char *ncp;
- int len, size, val, valprev, step, delta;
- object *rv, *str, *state;
- int i;
-
- if ( !getargs(args, "(s#iO)",
- &cp, &len, &size, &state) )
- return 0;
-
- if ( size != 1 && size != 2 && size != 4) {
- err_setstr(AudioopError, "Size should be 1, 2 or 4");
- return 0;
- }
-
- /* Decode state, should have (value, step) */
- if ( state == None ) {
- /* First time, it seems. Set defaults */
- valprev = 0;
- step = 4; /* The '4' is magic. Dunno it's significance */
- } else if ( !getargs(state, "(ii)", &valprev, &step) )
- return 0;
-
- str = newsizedstringobject(NULL, len*size);
- if ( str == 0 )
- return 0;
- ncp = (signed char *)getstringvalue(str);
-
- for ( i=0; i < len*size; i += size ) {
- /* Step 1 - get the delta value */
- delta = *cp++;
-
- /* Step 2 - update output value */
- valprev = valprev + delta*step;
-
- /* Step 3 - clamp output value */
- if ( valprev > 32767 )
- valprev = 32767;
- else if ( valprev < -32768 )
- valprev = -32768;
-
- /* Step 4 - Update step value */
- step = step * newstep[abs(delta)];
- step++;
-
- /* Step 5 - Output value */
- if ( size == 1 ) *CHARP(ncp, i) = (signed char)(valprev >> 8);
- else if ( size == 2 ) *SHORTP(ncp, i) = (short)(valprev);
- else if ( size == 4 ) *LONGP(ncp, i) = (long)(valprev<<16);
- }
-
- rv = mkvalue("(O(ii))", str, valprev, step);
- DECREF(str);
- return rv;
-}
-
-static object *
audioop_lin2adpcm(self, args)
object *self;
object *args;
@@ -1330,7 +1176,6 @@ audioop_adpcm2lin(self, args)
static struct methodlist audioop_methods[] = {
{ "max", audioop_max },
- { "minmax", audioop_minmax },
{ "avg", audioop_avg },
{ "maxpp", audioop_maxpp },
{ "avgpp", audioop_avgpp },
@@ -1347,8 +1192,6 @@ static struct methodlist audioop_methods[] = {
{ "lin2lin", audioop_lin2lin },
{ "adpcm2lin", audioop_adpcm2lin },
{ "lin2adpcm", audioop_lin2adpcm },
- { "adpcm32lin", audioop_adpcm32lin },
- { "lin2adpcm3", audioop_lin2adpcm3 },
{ "tomono", audioop_tomono },
{ "tostereo", audioop_tostereo },
{ "getsample", audioop_getsample },
diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c
index b5d0def..0630ebc 100644
--- a/Modules/cdmodule.c
+++ b/Modules/cdmodule.c
@@ -1,5 +1,5 @@
/**********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -440,23 +440,23 @@ CD_togglepause(self, args)
}
static struct methodlist cdplayer_methods[] = {
- {"allowremoval", CD_allowremoval},
- {"bestreadsize", CD_bestreadsize},
- {"close", CD_close},
- {"eject", CD_eject},
- {"getstatus", CD_getstatus},
- {"gettrackinfo", CD_gettrackinfo},
- {"msftoblock", CD_msftoblock},
- {"play", CD_play},
- {"playabs", CD_playabs},
- {"playtrack", CD_playtrack},
- {"playtrackabs", CD_playtrackabs},
- {"preventremoval", CD_preventremoval},
- {"readda", CD_readda},
- {"seek", CD_seek},
- {"seektrack", CD_seektrack},
- {"stop", CD_stop},
- {"togglepause", CD_togglepause},
+ {"allowremoval", (method)CD_allowremoval},
+ {"bestreadsize", (method)CD_bestreadsize},
+ {"close", (method)CD_close},
+ {"eject", (method)CD_eject},
+ {"getstatus", (method)CD_getstatus},
+ {"gettrackinfo", (method)CD_gettrackinfo},
+ {"msftoblock", (method)CD_msftoblock},
+ {"play", (method)CD_play},
+ {"playabs", (method)CD_playabs},
+ {"playtrack", (method)CD_playtrack},
+ {"playtrackabs", (method)CD_playtrackabs},
+ {"preventremoval", (method)CD_preventremoval},
+ {"readda", (method)CD_readda},
+ {"seek", (method)CD_seek},
+ {"seektrack", (method)CD_seektrack},
+ {"stop", (method)CD_stop},
+ {"togglepause", (method)CD_togglepause},
{NULL, NULL} /* sentinel */
};
@@ -484,9 +484,9 @@ typeobject CdPlayertype = {
sizeof(cdplayerobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- cdplayer_dealloc, /*tp_dealloc*/
+ (destructor)cdplayer_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- cdplayer_getattr, /*tp_getattr*/
+ (getattrfunc)cdplayer_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -755,12 +755,12 @@ CD_addcallback(self, args)
}
static struct methodlist cdparser_methods[] = {
- {"addcallback", CD_addcallback},
- {"deleteparser", CD_deleteparser},
- {"parseframe", CD_parseframe},
- {"removecallback", CD_removecallback},
- {"resetparser", CD_resetparser},
- {"setcallback", CD_addcallback}, /* backward compatibility */
+ {"addcallback", (method)CD_addcallback},
+ {"deleteparser", (method)CD_deleteparser},
+ {"parseframe", (method)CD_parseframe},
+ {"removecallback", (method)CD_removecallback},
+ {"resetparser", (method)CD_resetparser},
+ {"setcallback", (method)CD_addcallback}, /* backward compatibility */
{NULL, NULL} /* sentinel */
};
@@ -795,9 +795,9 @@ typeobject CdParsertype = {
sizeof(cdparserobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- cdparser_dealloc, /*tp_dealloc*/
+ (destructor)cdparser_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- cdparser_getattr, /*tp_getattr*/
+ (getattrfunc)cdparser_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -877,10 +877,10 @@ CD_timetoa(self, args)
}
static struct methodlist CD_methods[] = {
- {"sbtoa", CD_sbtoa},
- {"open", CD_open},
- {"createparser",CD_createparser},
- {"timetoa", CD_timetoa},
+ {"sbtoa", (method)CD_sbtoa},
+ {"open", (method)CD_open},
+ {"createparser",(method)CD_createparser},
+ {"timetoa", (method)CD_timetoa},
{NULL, NULL} /* Sentinel */
};
diff --git a/Modules/cgen.py b/Modules/cgen.py
index 434765b..c133b2c 100644
--- a/Modules/cgen.py
+++ b/Modules/cgen.py
@@ -1,3 +1,26 @@
+########################################################################
+# 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.
+########################################################################
+
# Python script to parse cstubs file for gl and generate C stubs.
# usage: python cgen.py <cstubs >glmodule.c
#
diff --git a/Modules/cgensupport.h b/Modules/cgensupport.h
index 8472b03..4b295b3 100644
--- a/Modules/cgensupport.h
+++ b/Modules/cgensupport.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,7 +35,7 @@ typedef char *string;
#define mknewlongobject(x) newintobject(x)
#define mknewshortobject(x) newintobject((long)x)
#define mknewfloatobject(x) newfloatobject(x)
-#define mknewcharobject(c) mkvalue("c", c)
+#define mknewcharobject(ch) mkvalue("c", ch)
extern int getiobjectarg PROTO((object *args, int nargs, int i, object **p_a));
extern int getilongarg PROTO((object *args, int nargs, int i, long *p_a));
diff --git a/Modules/clmodule.c b/Modules/clmodule.c
index 63e81db..75542d1 100644
--- a/Modules/clmodule.c
+++ b/Modules/clmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -675,9 +675,9 @@ static typeobject Cltype = {
sizeof(clobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- cl_dealloc, /*tp_dealloc*/
+ (destructor)cl_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- cl_getattr, /*tp_getattr*/
+ (getattrfunc)cl_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -711,7 +711,7 @@ doOpen(object *self, object *args, int (*open_func)(int, CL_Handle *),
err_setstr(ClError, "Open(De)Compressor failed");
return NULL;
}
- return new;
+ return (object *)new;
}
static object *
diff --git a/Modules/config.c.in b/Modules/config.c.in
index b4f7d3d..cc2371a 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -1,5 +1,5 @@
-/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+/* -*- C -*- ***********************************************
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -22,115 +22,73 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
-/* Configurable Python configuration file */
+/* Universal Python configuration file */
-/* These modules are normally always included, but *may* be taken out */
-#define USE_MARSHAL 1 /* This is linked anyway */
-#define USE_MATH 1
-#define USE_STRUCT 1
-#define USE_TIME 1
-
-#ifdef macintosh
-#define USE_AUDIOOP 1
-#define USE_IMAGEOP 1
-#define USE_MAC 1
-#define USE_REGEX 1
-#define USE_STDWIN 1 /* You may turn this off */
-#define USE_STROP
-#endif
-
-#ifdef unix
-#define USE_GRP 1 /* Use together with pwd */
-#define USE_POSIX 1
-#define USE_PWD 1 /* Use together with grp */
-#define USE_SELECT 1
-#define USE_SOCKET 1
-#endif
-
-#ifdef MSDOS
-#define USE_POSIX 1 /* Subset defined in posixmodule.c */
-#define USE_REGEX 1
-#define USE_STROP 1
-#define USE_PC 1
+#ifdef HAVE_CONFIG_H
+#include "config.h"
#endif
#include <stdio.h>
+#include <string.h>
-#include "PROTO.h"
+#include "myproto.h"
#include "mymalloc.h"
#include "osdefs.h"
+#include "intrcheck.h"
-#include "patchlevel.h"
-#define VERSION "0.9.%d++ (%s)"
+#ifndef NO_MAIN
-#ifdef __DATE__
-#define DATE __DATE__
-#else
-#define DATE ">= 3 Nov 1993"
-#endif
-
-char version[80];
+/* Normally, the main program is called from here (so everything else
+ can be in libPython.a). We save a pointer to argv[0] because it
+ may be needed for dynamic loading of modules in import.c. If you
+ have your own main program and want to use non-SunOS dynamic
+ loading, you will have to provide your own version of
+ getprogramname(). */
-char *argv0; /* For dynamic loading in import.c */
+static char *argv0;
-extern char verbose;
-
-/*ARGSUSED*/
-void
-initargs(p_argc, p_argv)
- int *p_argc;
- char ***p_argv;
+main(argc, argv)
+ int argc;
+ char **argv;
{
- sprintf(version, VERSION, PATCHLEVEL, DATE);
-
- argv0 = **p_argv;
-
-#ifdef USE_FROZEN
- if (verbose)
-#else
- if (verbose || *p_argc < 2 && isatty(0) && isatty(1))
+#ifdef macintosh
+ wargs(&argc, &argv);
#endif
- {
- printf("Python %s.\n", version);
- printf(
-"Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum, Amsterdam\n");
- }
+ argv0 = argv[0];
+ realmain(argc, argv);
}
-void
-initcalls()
+char *
+getprogramname()
{
+ return argv0;
}
-void
-donecalls()
-{
-#ifdef USE_AUDIO
- asa_done();
#endif
-}
-#ifndef PYTHONPATH
+/* Return the initial python search path. This is called once from
+ initsys() to initialize sys.path.
+ The environment variable PYTHONPATH is fetched and the default path
+ appended. (The Mac has no environment variables, so there the
+ default path is always returned.) The default path may be passed
+ to the preprocessor; if not, a system-dependent default is used. */
+
+#ifndef PYTHONPATH
#ifdef macintosh
-/* On the Mac, the search path is a space-separated list of directories */
-#define PYTHONPATH ": :lib :demo"
+#define PYTHONPATH ": :Lib :Lib:stdwin :Demo"
#endif /* macintosh */
+#endif /* !PYTHONPATH */
-#ifdef unix
-#define PYTHONPATH ".:/usr/local/lib/python"
-#endif /* unix */
-
-#ifdef MSDOS
-/* In MS-DOS, the delimiter is a semicolon */
+#ifndef PYTHONPATH
+#if defined(MSDOS) || defined(NT)
#define PYTHONPATH ".;..\\lib;\\python\\lib"
-#endif /* MSDOS */
+#endif /* MSDOS || NT */
+#endif /* !PYTHONPATH */
#ifndef PYTHONPATH
-ERROR; ERROR; On what kind of system are you?;
-#endif
-
+#define PYTHONPATH ".:/usr/local/lib/python"
#endif /* !PYTHONPATH */
extern char *getenv();
@@ -163,335 +121,31 @@ getpythonpath()
/* Table of built-in modules.
- These are initialized when first imported. */
+ These are initialized when first imported.
+ Note: selection of optional extensions is now generally done by the
+ makesetup script. */
-/* Standard modules */
+/* -- ADDMODULE MARKER 1 -- */
-#ifdef USE_AL
-extern void inital();
-#endif
-#ifdef USE_AMOEBA
-extern void initamoeba();
-#endif
-#ifdef USE_AUDIO
-extern void initaudio();
-#endif
-#ifdef USE_AUDIOOP
-extern void initaudioop();
-#endif
-#ifdef USE_CD
-extern void initcd();
-#endif
-#ifdef USE_CL
-extern void initcl();
-#endif
-#ifdef USE_DBM
-extern void initdbm();
-#endif
-#ifdef USE_FCNTL
-extern void initfcntl();
-#endif
-#ifdef USE_FL
-extern void initfl();
-#endif
-#ifdef USE_FM
-extern void initfm();
-#endif
-#ifdef USE_GL
-extern void initgl();
-#endif
-#ifdef USE_GRP
-extern void initgrp();
-#endif
-#ifdef USE_IMGFILE
-extern void initimgfile();
-#endif
-#ifdef USE_JPEG
-extern void initjpeg();
-#endif
-#ifdef USE_MAC
-extern void initmac();
-#endif
-#ifdef USE_MARSHAL
extern void initmarshal();
-#endif
-#ifdef USE_MATH
-extern void initmath();
-#endif
-#ifdef USE_NIS
-extern void initnis();
-#endif
-#ifdef USE_PANEL
-extern void initpanel();
-#endif
-#ifdef USE_POSIX
-extern void initposix();
-#endif
-#ifdef USE_PWD
-extern void initpwd();
-#endif
-#ifdef USE_REGEX
-extern void initregex();
-#endif
-#ifdef USE_ROTOR
-extern void initrotor();
-#endif
-#ifdef USE_SELECT
-extern void initselect();
-#endif
-#ifdef USE_SGI
-extern void initsgi();
-#endif
-#ifdef USE_SOCKET
-extern void initsocket();
-#endif
-#ifdef USE_STDWIN
-extern void initstdwin();
-#endif
-#ifdef USE_STROP
-extern void initstrop();
-#endif
-#ifdef USE_STRUCT
-extern void initstruct();
-#endif
-#ifdef USE_SUNAUDIODEV
-extern void initsunaudiodev();
-#endif
-#ifdef USE_THREAD
-extern void initthread();
-#endif
-#ifdef USE_SV
-extern void initsv();
-#endif
-#ifdef USE_TIME
-extern void inittime();
-#endif
-#ifdef USE_IMAGEOP
-extern void initimageop();
-#endif
-#ifdef USE_MPZ
-extern void initmpz();
-#endif
-#ifdef USE_MD5
-extern void initmd5();
-#endif
-#ifdef USE_ARRAY
-extern void initarray();
-#endif
-#ifdef USE_XT
-extern void initXt();
-#endif
-#ifdef USE_XAW
-extern void initXaw();
-#endif
-#ifdef USE_XM
-extern void initXm();
-#endif
-#ifdef USE_GLX
-extern void initGlx();
-#endif
-#ifdef USE_HTML
-extern void initHTML();
-#endif
-#ifdef USE_XLIB
-extern void initXlib();
-#endif
-#ifdef USE_PARSER
-extern void initparser();
-#endif
-#ifdef USE_RGBIMG
-extern void initrgbimg();
-#endif
-/* -- ADDMODULE MARKER 1 -- */
struct {
char *name;
void (*initfunc)();
} inittab[] = {
-#ifdef USE_AL
- {"al", inital},
-#endif
-
-#ifdef USE_AMOEBA
- {"amoeba", initamoeba},
-#endif
-
-#ifdef USE_AUDIO
- {"audio", initaudio},
-#endif
-
-#ifdef USE_AUDIOOP
- {"audioop", initaudioop},
-#endif
-
-#ifdef USE_CD
- {"cd", initcd},
-#endif
-
-#ifdef USE_CL
- {"cl", initcl},
-#endif
-
-#ifdef USE_DBM
- {"dbm", initdbm},
-#endif
-
-#ifdef USE_FCNTL
- {"fcntl", initfcntl},
-#endif
-
-#ifdef USE_FL
- {"fl", initfl},
-#endif
-
-#ifdef USE_FM
- {"fm", initfm},
-#endif
-
-#ifdef USE_GL
- {"gl", initgl},
-#endif
-
-#ifdef USE_GRP
- {"grp", initgrp},
-#endif
-
-#ifdef USE_IMGFILE
- {"imgfile", initimgfile},
-#endif
-
-#ifdef USE_JPEG
- {"jpeg", initjpeg},
-#endif
-
-#ifdef USE_MAC
- {"mac", initmac},
-#endif
-
-#ifdef USE_MARSHAL
- {"marshal", initmarshal},
-#endif
-
-#ifdef USE_MATH
- {"math", initmath},
-#endif
-
-#ifdef USE_NIS
- {"nis", initnis},
-#endif
-
-#ifdef USE_PANEL
- {"pnl", initpanel},
-#endif
-
-#ifdef USE_POSIX
- {"posix", initposix},
-#endif
-
-#ifdef USE_PWD
- {"pwd", initpwd},
-#endif
-
-#ifdef USE_REGEX
- {"regex", initregex},
-#endif
-
-#ifdef USE_ROTOR
- {"rotor", initrotor},
-#endif
-
-#ifdef USE_SELECT
- {"select", initselect},
-#endif
-
-#ifdef USE_SGI
- {"sgi", initsgi},
-#endif
-
-#ifdef USE_SOCKET
- {"socket", initsocket},
-#endif
-
-#ifdef USE_STDWIN
- {"stdwin", initstdwin},
-#endif
-
-#ifdef USE_STROP
- {"strop", initstrop},
-#endif
-
-#ifdef USE_STRUCT
- {"struct", initstruct},
-#endif
-
-#ifdef USE_SUNAUDIODEV
- {"sunaudiodev", initsunaudiodev},
-#endif
-
-#ifdef USE_SV
- {"sv", initsv},
-#endif
-
-#ifdef USE_THREAD
- {"thread", initthread},
-#endif
-
-#ifdef USE_TIME
- {"time", inittime},
-#endif
-
-#ifdef USE_IMAGEOP
- {"imageop", initimageop},
-#endif
-
-#ifdef USE_MPZ
- {"mpz", initmpz},
-#endif
-
-#ifdef USE_MD5
- {"md5", initmd5},
-#endif
-
-#ifdef USE_ARRAY
- {"array", initarray},
-#endif
-
-#ifdef USE_XT
- {"Xt", initXt},
-#endif
-
-#ifdef USE_XAW
- {"Xaw", initXaw},
-#endif
-
-#ifdef USE_XM
- {"Xm", initXm},
-#endif
-
-#ifdef USE_GLX
- {"Glx", initGlx},
-#endif
-
-#ifdef USE_HTML
- {"HTML", initHTML},
-#endif
-
-#ifdef USE_XLIB
- {"Xlib", initXlib},
-#endif
+/* -- ADDMODULE MARKER 2 -- */
-#ifdef USE_PARSER
- {"parser", initparser},
-#endif
+ /* This module "lives in" with marshal.c */
+ {"marshal", initmarshal},
-#ifdef USE_RGBIMG
- {"rgbimg", initrgbimg},
-#endif
-
-/* -- ADDMODULE MARKER 2 -- */
+ /* These entries are here for sys.builtin_module_names */
+ {"__main__", NULL},
+ {"__builtin__", NULL},
+ {"sys", NULL},
- {0, 0} /* Sentinel */
+ /* Sentinel */
+ {0, 0}
};
#ifdef USE_FROZEN
diff --git a/Modules/cstubs b/Modules/cstubs
index b365f33..8481024 100644
--- a/Modules/cstubs
+++ b/Modules/cstubs
@@ -1,3 +1,27 @@
+/***********************************************************
+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.
+
+******************************************************************/
+
/*
Input used to generate the Python module "glmodule.c".
The stub generator is a Python script called "cgen.py".
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index 0f368d2..b484917 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -39,7 +39,7 @@ typedef struct {
DBM *di_dbm;
} dbmobject;
-extern typeobject Dbmtype; /* Really forward */
+staticforward typeobject Dbmtype;
#define is_dbmobject(v) ((v)->ob_type == &Dbmtype)
@@ -131,6 +131,7 @@ dbm_ass_sub(dp, v, w)
dp->di_size = -1;
if (w == NULL) {
if ( dbm_delete(dp->di_dbm, krec) < 0 ) {
+ dbm_clearerr(dp->di_dbm);
err_setstr(KeyError, GETSTRINGVALUE((stringobject *)v));
return -1;
}
@@ -141,6 +142,7 @@ dbm_ass_sub(dp, v, w)
return -1;
}
if ( dbm_store(dp->di_dbm, krec, drec, DBM_REPLACE) < 0 ) {
+ dbm_clearerr(dp->di_dbm);
err_setstr(DbmError, "Cannot add item to database");
return -1;
}
@@ -154,9 +156,9 @@ dbm_ass_sub(dp, v, w)
}
static mapping_methods dbm_as_mapping = {
- dbm_length, /*mp_length*/
- dbm_subscript, /*mp_subscript*/
- dbm_ass_sub, /*mp_ass_subscript*/
+ (inquiry)dbm_length, /*mp_length*/
+ (binaryfunc)dbm_subscript, /*mp_subscript*/
+ (objobjargproc)dbm_ass_sub, /*mp_ass_subscript*/
};
static object *
@@ -201,8 +203,8 @@ dbm_has_key(dp, args)
}
static struct methodlist dbm_methods[] = {
- {"keys", dbm_keys},
- {"has_key", dbm_has_key},
+ {"keys", (method)dbm_keys},
+ {"has_key", (method)dbm_has_key},
{NULL, NULL} /* sentinel */
};
@@ -214,20 +216,20 @@ dbm_getattr(dp, name)
return findmethod(dbm_methods, (object *)dp, name);
}
-typeobject Dbmtype = {
+static typeobject Dbmtype = {
OB_HEAD_INIT(&Typetype)
0,
"Dbm_dictionary",
sizeof(dbmobject),
0,
- dbm_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- dbm_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
+ (destructor)dbm_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)dbm_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
&dbm_as_mapping, /*tp_as_mapping*/
};
@@ -258,7 +260,7 @@ dbmopen(self, args)
}
static struct methodlist dbmmodule_methods[] = {
- { "open", dbmopen },
+ { "open", (method)dbmopen },
{ 0, 0 },
};
diff --git a/Modules/fcntlmodule.c b/Modules/fcntlmodule.c
index 7862b06..0c6b4f0 100644
--- a/Modules/fcntlmodule.c
+++ b/Modules/fcntlmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index ce22861..ab23b47 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -1,5 +1,5 @@
/**********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -56,7 +56,7 @@ typedef struct {
object *ob_callback_arg;
} genericobject;
-extern typeobject GenericObjecttype; /* Forward */
+staticforward typeobject GenericObjecttype;
#define is_genericobject(g) ((g)->ob_type == &GenericObjecttype)
@@ -298,16 +298,16 @@ generic_set_object_shortcut(g, args)
}
static struct methodlist generic_methods[] = {
- {"set_call_back", generic_set_call_back},
- {"delete_object", generic_delete_object},
- {"show_object", generic_show_object},
- {"hide_object", generic_hide_object},
- {"redraw_object", generic_redraw_object},
- {"freeze_object", generic_freeze_object},
- {"unfreeze_object", generic_unfreeze_object},
- {"activate_object", generic_activate_object},
- {"deactivate_object", generic_deactivate_object},
- {"set_object_shortcut", generic_set_object_shortcut},
+ {"set_call_back", (method)generic_set_call_back},
+ {"delete_object", (method)generic_delete_object},
+ {"show_object", (method)generic_show_object},
+ {"hide_object", (method)generic_hide_object},
+ {"redraw_object", (method)generic_redraw_object},
+ {"freeze_object", (method)generic_freeze_object},
+ {"unfreeze_object", (method)generic_unfreeze_object},
+ {"activate_object", (method)generic_activate_object},
+ {"deactivate_object", (method)generic_deactivate_object},
+ {"set_object_shortcut", (method)generic_set_object_shortcut},
{NULL, NULL} /* sentinel */
};
@@ -424,19 +424,19 @@ generic_repr(g)
return newstringobject(buf);
}
-typeobject GenericObjecttype = {
+static typeobject GenericObjecttype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "FORMS_object", /*tp_name*/
- sizeof(genericobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "FORMS_object", /*tp_name*/
+ sizeof(genericobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- generic_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- generic_getattr, /*tp_getattr*/
- generic_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- generic_repr, /*tp_repr*/
+ (destructor)generic_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)generic_getattr, /*tp_getattr*/
+ (setattrfunc)generic_setattr, /*tp_setattr*/
+ 0, /*tp_compare*/
+ (reprfunc)generic_repr, /*tp_repr*/
};
static object *
@@ -837,24 +837,24 @@ set_browser_specialkey (g, args)
}
static struct methodlist browser_methods[] = {
- {"set_browser_topline", set_browser_topline},
- {"clear_browser", clear_browser},
- {"add_browser_line", add_browser_line},
- {"addto_browser", addto_browser},
- {"insert_browser_line", insert_browser_line},
- {"delete_browser_line", delete_browser_line},
- {"replace_browser_line", replace_browser_line},
- {"get_browser_line", get_browser_line},
- {"load_browser", load_browser},
- {"get_browser_maxline", get_browser_maxline},
- {"select_browser_line", select_browser_line},
- {"deselect_browser_line", deselect_browser_line},
- {"deselect_browser", deselect_browser},
- {"isselected_browser_line", isselected_browser_line},
- {"get_browser", get_browser},
- {"set_browser_fontsize", set_browser_fontsize},
- {"set_browser_fontstyle", set_browser_fontstyle},
- {"set_browser_specialkey", set_browser_specialkey},
+ {"set_browser_topline", (method)set_browser_topline},
+ {"clear_browser", (method)clear_browser},
+ {"add_browser_line", (method)add_browser_line},
+ {"addto_browser", (method)addto_browser},
+ {"insert_browser_line", (method)insert_browser_line},
+ {"delete_browser_line", (method)delete_browser_line},
+ {"replace_browser_line", (method)replace_browser_line},
+ {"get_browser_line", (method)get_browser_line},
+ {"load_browser", (method)load_browser},
+ {"get_browser_maxline", (method)get_browser_maxline},
+ {"select_browser_line", (method)select_browser_line},
+ {"deselect_browser_line", (method)deselect_browser_line},
+ {"deselect_browser", (method)deselect_browser},
+ {"isselected_browser_line", (method)isselected_browser_line},
+ {"get_browser", (method)get_browser},
+ {"set_browser_fontsize", (method)set_browser_fontsize},
+ {"set_browser_fontstyle", (method)set_browser_fontstyle},
+ {"set_browser_specialkey", (method)set_browser_specialkey},
{NULL, NULL} /* sentinel */
};
@@ -893,10 +893,10 @@ set_button_shortcut(g, args)
}
static struct methodlist button_methods[] = {
- {"set_button", set_button},
- {"get_button", get_button},
- {"get_button_numb", get_button_numb},
- {"set_button_shortcut", set_button_shortcut},
+ {"set_button", (method)set_button},
+ {"get_button", (method)get_button},
+ {"get_button_numb", (method)get_button_numb},
+ {"set_button_shortcut", (method)set_button_shortcut},
{NULL, NULL} /* sentinel */
};
@@ -975,15 +975,15 @@ set_choice_fontstyle (g, args)
}
static struct methodlist choice_methods[] = {
- {"set_choice", set_choice},
- {"get_choice", get_choice},
- {"clear_choice", clear_choice},
- {"addto_choice", addto_choice},
- {"replace_choice", replace_choice},
- {"delete_choice", delete_choice},
- {"get_choice_text", get_choice_text},
- {"set_choice_fontsize", set_choice_fontsize},
- {"set_choice_fontstyle",set_choice_fontstyle},
+ {"set_choice", (method)set_choice},
+ {"get_choice", (method)get_choice},
+ {"clear_choice", (method)clear_choice},
+ {"addto_choice", (method)addto_choice},
+ {"replace_choice", (method)replace_choice},
+ {"delete_choice", (method)delete_choice},
+ {"get_choice_text", (method)get_choice_text},
+ {"set_choice_fontsize", (method)set_choice_fontsize},
+ {"set_choice_fontstyle",(method)set_choice_fontstyle},
{NULL, NULL} /* sentinel */
};
@@ -1005,7 +1005,7 @@ get_clock(g, args)
}
static struct methodlist clock_methods[] = {
- {"get_clock", get_clock},
+ {"get_clock", (method)get_clock},
{NULL, NULL} /* sentinel */
};
@@ -1060,12 +1060,12 @@ set_counter_return (g, args)
}
static struct methodlist counter_methods[] = {
- {"set_counter_value", set_counter_value},
- {"get_counter_value", get_counter_value},
- {"set_counter_bounds", set_counter_bounds},
- {"set_counter_step", set_counter_step},
- {"set_counter_precision", set_counter_precision},
- {"set_counter_return", set_counter_return},
+ {"set_counter_value", (method)set_counter_value},
+ {"get_counter_value", (method)get_counter_value},
+ {"set_counter_bounds", (method)set_counter_bounds},
+ {"set_counter_step", (method)set_counter_step},
+ {"set_counter_precision", (method)set_counter_precision},
+ {"set_counter_return", (method)set_counter_return},
{NULL, NULL} /* sentinel */
};
@@ -1113,11 +1113,11 @@ set_dial_step (g, args)
}
static struct methodlist dial_methods[] = {
- {"set_dial_value", set_dial_value},
- {"get_dial_value", get_dial_value},
- {"set_dial_bounds", set_dial_bounds},
- {"get_dial_bounds", get_dial_bounds},
- {"set_dial_step", set_dial_step},
+ {"set_dial_value", (method)set_dial_value},
+ {"get_dial_value", (method)get_dial_value},
+ {"set_dial_bounds", (method)set_dial_bounds},
+ {"get_dial_bounds", (method)get_dial_bounds},
+ {"set_dial_step", (method)set_dial_step},
{NULL, NULL} /* sentinel */
};
@@ -1156,10 +1156,10 @@ set_input_return (g, args)
}
static struct methodlist input_methods[] = {
- {"set_input", set_input},
- {"get_input", get_input},
- {"set_input_color", set_input_color},
- {"set_input_return", set_input_return},
+ {"set_input", (method)set_input},
+ {"get_input", (method)get_input},
+ {"set_input_color", (method)set_input_color},
+ {"set_input_return", (method)set_input_return},
{NULL, NULL} /* sentinel */
};
@@ -1201,10 +1201,10 @@ addto_menu (g, args)
}
static struct methodlist menu_methods[] = {
- {"set_menu", set_menu},
- {"get_menu", get_menu},
- {"get_menu_text", get_menu_text},
- {"addto_menu", addto_menu},
+ {"set_menu", (method)set_menu},
+ {"get_menu", (method)get_menu},
+ {"get_menu_text", (method)get_menu_text},
+ {"addto_menu", (method)addto_menu},
{NULL, NULL} /* sentinel */
};
@@ -1277,14 +1277,14 @@ set_slider_step (g, args)
static struct methodlist slider_methods[] = {
- {"set_slider_value", set_slider_value},
- {"get_slider_value", get_slider_value},
- {"set_slider_bounds", set_slider_bounds},
- {"get_slider_bounds", get_slider_bounds},
- {"set_slider_return", set_slider_return},
- {"set_slider_size", set_slider_size},
- {"set_slider_precision",set_slider_precision},
- {"set_slider_step", set_slider_step},
+ {"set_slider_value", (method)set_slider_value},
+ {"get_slider_value", (method)get_slider_value},
+ {"set_slider_bounds", (method)set_slider_bounds},
+ {"get_slider_bounds", (method)get_slider_bounds},
+ {"set_slider_return", (method)set_slider_return},
+ {"set_slider_size", (method)set_slider_size},
+ {"set_slider_precision",(method)set_slider_precision},
+ {"set_slider_step", (method)set_slider_step},
{NULL, NULL} /* sentinel */
};
@@ -1357,14 +1357,14 @@ get_positioner_ybounds (g, args)
}
static struct methodlist positioner_methods[] = {
- {"set_positioner_xvalue", set_positioner_xvalue},
- {"set_positioner_yvalue", set_positioner_yvalue},
- {"set_positioner_xbounds", set_positioner_xbounds},
- {"set_positioner_ybounds", set_positioner_ybounds},
- {"get_positioner_xvalue", get_positioner_xvalue},
- {"get_positioner_yvalue", get_positioner_yvalue},
- {"get_positioner_xbounds", get_positioner_xbounds},
- {"get_positioner_ybounds", get_positioner_ybounds},
+ {"set_positioner_xvalue", (method)set_positioner_xvalue},
+ {"set_positioner_yvalue", (method)set_positioner_yvalue},
+ {"set_positioner_xbounds", (method)set_positioner_xbounds},
+ {"set_positioner_ybounds", (method)set_positioner_ybounds},
+ {"get_positioner_xvalue", (method)get_positioner_xvalue},
+ {"get_positioner_yvalue", (method)get_positioner_yvalue},
+ {"get_positioner_xbounds", (method)get_positioner_xbounds},
+ {"get_positioner_ybounds", (method)get_positioner_ybounds},
{NULL, NULL} /* sentinel */
};
@@ -1387,8 +1387,8 @@ get_timer (g, args)
}
static struct methodlist timer_methods[] = {
- {"set_timer", set_timer},
- {"get_timer", get_timer},
+ {"set_timer", (method)set_timer},
+ {"get_timer", (method)get_timer},
{NULL, NULL} /* sentinel */
};
@@ -1399,7 +1399,7 @@ typedef struct {
FL_FORM *ob_form;
} formobject;
-extern typeobject Formtype; /* Forward */
+staticforward typeobject Formtype;
#define is_formobject(v) ((v)->ob_type == &Formtype)
@@ -1813,40 +1813,40 @@ form_set_object_focus(f, args)
static struct methodlist form_methods[] = {
/* adm */
- {"show_form", form_show_form},
- {"hide_form", form_hide_form},
- {"redraw_form", form_redraw_form},
- {"set_form_position", form_set_form_position},
- {"set_form_size", form_set_form_size},
- {"scale_form", form_scale_form},
- {"freeze_form", form_freeze_form},
- {"unfreeze_form", form_unfreeze_form},
- {"activate_form", form_activate_form},
- {"deactivate_form", form_deactivate_form},
- {"bgn_group", form_bgn_group},
- {"end_group", form_end_group},
- {"find_first", form_find_first},
- {"find_last", form_find_last},
- {"set_object_focus", form_set_object_focus},
+ {"show_form", (method)form_show_form},
+ {"hide_form", (method)form_hide_form},
+ {"redraw_form", (method)form_redraw_form},
+ {"set_form_position", (method)form_set_form_position},
+ {"set_form_size", (method)form_set_form_size},
+ {"scale_form", (method)form_scale_form},
+ {"freeze_form", (method)form_freeze_form},
+ {"unfreeze_form", (method)form_unfreeze_form},
+ {"activate_form", (method)form_activate_form},
+ {"deactivate_form", (method)form_deactivate_form},
+ {"bgn_group", (method)form_bgn_group},
+ {"end_group", (method)form_end_group},
+ {"find_first", (method)form_find_first},
+ {"find_last", (method)form_find_last},
+ {"set_object_focus", (method)form_set_object_focus},
/* basic objects */
- {"add_button", form_add_button},
-/* {"add_bitmap", form_add_bitmap}, */
- {"add_lightbutton", form_add_lightbutton},
- {"add_roundbutton", form_add_roundbutton},
- {"add_menu", form_add_menu},
- {"add_slider", form_add_slider},
- {"add_positioner", form_add_positioner},
- {"add_valslider", form_add_valslider},
- {"add_dial", form_add_dial},
- {"add_counter", form_add_counter},
- {"add_box", form_add_box},
- {"add_clock", form_add_clock},
- {"add_choice", form_add_choice},
- {"add_browser", form_add_browser},
- {"add_input", form_add_input},
- {"add_timer", form_add_timer},
- {"add_text", form_add_text},
+ {"add_button", (method)form_add_button},
+/* {"add_bitmap", (method)form_add_bitmap}, */
+ {"add_lightbutton", (method)form_add_lightbutton},
+ {"add_roundbutton", (method)form_add_roundbutton},
+ {"add_menu", (method)form_add_menu},
+ {"add_slider", (method)form_add_slider},
+ {"add_positioner", (method)form_add_positioner},
+ {"add_valslider", (method)form_add_valslider},
+ {"add_dial", (method)form_add_dial},
+ {"add_counter", (method)form_add_counter},
+ {"add_box", (method)form_add_box},
+ {"add_clock", (method)form_add_clock},
+ {"add_choice", (method)form_add_choice},
+ {"add_browser", (method)form_add_browser},
+ {"add_input", (method)form_add_input},
+ {"add_timer", (method)form_add_timer},
+ {"add_text", (method)form_add_text},
{NULL, NULL} /* sentinel */
};
@@ -1918,19 +1918,19 @@ form_repr(f)
return newstringobject(buf);
}
-typeobject Formtype = {
+static typeobject Formtype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "FORMS_form", /*tp_name*/
- sizeof(formobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "FORMS_form", /*tp_name*/
+ sizeof(formobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- form_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- form_getattr, /*tp_getattr*/
- form_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- form_repr, /*tp_repr*/
+ (destructor)form_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)form_getattr, /*tp_getattr*/
+ (setattrfunc)form_setattr, /*tp_setattr*/
+ 0, /*tp_compare*/
+ (reprfunc)form_repr, /*tp_repr*/
};
static object *
diff --git a/Modules/fmmodule.c b/Modules/fmmodule.c
index aa49be3..4875d9a 100644
--- a/Modules/fmmodule.c
+++ b/Modules/fmmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -40,7 +40,7 @@ typedef struct {
fmfonthandle fh_fh;
} fhobject;
-extern typeobject Fhtype; /* Really static, forward */
+staticforward typeobject Fhtype;
#define is_fhobject(v) ((v)->ob_type == &Fhtype)
@@ -166,15 +166,15 @@ fh_getstrwidth(self, args)
}
static struct methodlist fh_methods[] = {
- {"scalefont", fh_scalefont},
- {"setfont", fh_setfont},
- {"getfontname", fh_getfontname},
- {"getcomment", fh_getcomment},
- {"getfontinfo", fh_getfontinfo},
+ {"scalefont", (method)fh_scalefont},
+ {"setfont", (method)fh_setfont},
+ {"getfontname", (method)fh_getfontname},
+ {"getcomment", (method)fh_getcomment},
+ {"getfontinfo", (method)fh_getfontinfo},
#if 0
- {"getwholemetrics", fh_getwholemetrics},
+ {"getwholemetrics", (method)fh_getwholemetrics},
#endif
- {"getstrwidth", fh_getstrwidth},
+ {"getstrwidth", (method)fh_getstrwidth},
{NULL, NULL} /* sentinel */
};
@@ -196,17 +196,17 @@ fh_dealloc(fhp)
static typeobject Fhtype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "font handle", /*tp_name*/
- sizeof(fhobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "font handle", /*tp_name*/
+ sizeof(fhobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- fh_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- fh_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)fh_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)fh_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
diff --git a/Modules/imageop.c b/Modules/imageop.c
index 841ec1b..57cb90b 100644
--- a/Modules/imageop.c
+++ b/Modules/imageop.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -161,7 +161,7 @@ imageop_tovideo(self, args)
for (y=1; y<maxy; y++) { /* Interpolate other lines */
for(x=0; x<maxx; x++) {
i = y*maxx + x;
- *ncp++ = (cp[i] + cp[i-maxx]) >> 1;
+ *ncp++ = ((int)cp[i] + (int)cp[i-maxx]) >> 1;
}
}
} else {
@@ -171,11 +171,11 @@ imageop_tovideo(self, args)
for(x=0; x<maxx; x++) {
i = (y*maxx + x)*4 + 1;
*ncp++ = 0; /* Skip alfa comp */
- *ncp++ = (cp[i] + cp[i-4*maxx]) >> 1;
+ *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
i++;
- *ncp++ = (cp[i] + cp[i-4*maxx]) >> 1;
+ *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
i++;
- *ncp++ = (cp[i] + cp[i-4*maxx]) >> 1;
+ *ncp++ = ((int)cp[i] + (int)cp[i-4*maxx]) >> 1;
}
}
}
@@ -210,7 +210,7 @@ imageop_grey2mono(self, args)
bit = 0x80;
ovalue = 0;
for ( i=0; i < len; i++ ) {
- if ( cp[i] > tres )
+ if ( (int)cp[i] > tres )
ovalue |= bit;
bit >>= 1;
if ( bit == 0 ) {
@@ -252,7 +252,7 @@ imageop_grey2grey4(self, args)
pos = 0;
ovalue = 0;
for ( i=0; i < len; i++ ) {
- ovalue |= (cp[i] & 0xf0) >> pos;
+ ovalue |= ((int)cp[i] & 0xf0) >> pos;
pos += 4;
if ( pos == 8 ) {
*ncp++ = ovalue;
@@ -293,7 +293,7 @@ imageop_grey2grey2(self, args)
pos = 0;
ovalue = 0;
for ( i=0; i < len; i++ ) {
- ovalue |= (cp[i] & 0xc0) >> pos;
+ ovalue |= ((int)cp[i] & 0xc0) >> pos;
pos += 2;
if ( pos == 8 ) {
*ncp++ = ovalue;
diff --git a/Modules/imgfile.c b/Modules/imgfile.c
index e57d6c4..7163d72 100644
--- a/Modules/imgfile.c
+++ b/Modules/imgfile.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Modules/makesetup b/Modules/makesetup
index b5cc57b..69159f7 100755
--- a/Modules/makesetup
+++ b/Modules/makesetup
@@ -1,24 +1,103 @@
#! /bin/sh
-# This script converts Makefile.in.in and config.c.in into Makefile.in
-# and config.c, based on the module definitions found in the file
-# Setup.
+# Convert templates into Makefile and config.c, based on the module
+# definitions found in the file Setup.
+#
+# Usage: makesetup [-s dir] [-c file] [-m file] [Setup] ... [-n [Setup] ...]
+#
+# Options:
+# -s directory: alternative source directory (default derived from $0)
+# -c file: alternative config.c template (default $srcdir/config.c.in)
+# -c -: don't write config.c
+# -m file: alternative Makefile template (default ./Makefile.pre)
+# -m -: don't write Makefile
+#
+# Remaining arguments are one or more Setup files (default ./Setup).
+# Setup files after a -n option are used for their variables, modules
+# and libraries but not for their .o files.
+#
+# See Setup.in for a description of the format of the Setup file.
+#
+# The following edits are made:
+#
+# Copying config.c.in to config.c:
+# - insert an identifying comment at the start
+# - for each <module> mentioned in Setup:
+# + insert 'extern void init<module>();' before MARKER 1
+# + insert '{"<module>", initmodule},' before MARKER 2
+#
+# Copying Makefile.pre to Makefile:
+# - insert an identifying comment at the start
+# - replace @MODOBJS@ by the list of objects from Setup (except for
+# Setup files after a -n option)
+# - replace @MODLIBS@ by the list of libraries from Setup
+# - for each object file mentioned in Setup, insert a rule
+# '<file>.o: <file>.c; <build commands>' before the comment
+# 'Rules added by makesetup'
+# - for each variable definition found in Setup, insert the definition
+# before the comment 'Definitions added by makesetup'
+# Loop over command line options
+usage='
+usage: makesetup [-s srcdir] [-c config.c.in] [-m Makefile.pre]
+ [Setup] ... [-n [Setup] ...]'
+srcdir=''
+config=''
+makepre=''
+noobjects=''
+while :
+do
+ case $1 in
+ -s) shift; srcdir=$1; shift;;
+ -c) shift; config=$1; shift;;
+ -m) shift; makepre=$1; shift;;
+ --) shift; break;;
+ -n) noobjects=yes;;
+ -*) echo "$usage" 1>&2; exit 2;;
+ *) break;;
+ esac
+done
+
+# Set default srcdir and config if not set by command line
+# (Not all systems have dirname)
+case $srcdir in
+'') case $0 in
+ */*) srcdir=`echo $0 | sed 's,/[^/]*$,,'`;;
+ *) srcdir=.;;
+ esac;;
+esac
+case $config in
+'') config=$srcdir/config.c.in;;
+esac
+case $makepre in
+'') makepre=Makefile.pre;;
+esac
+
+# Newline for sed i and a commands
NL="\\
"
-sed -e 's/#.*//' -e '/^[ ]*$/d' ${1-Setup} |
+# Main loop
+for i in ${*-Setup}
+do
+ case $i in
+ -n) echo '<noobjects>';;
+ *) cat "$i";;
+ esac
+done |
+sed -e 's/[ ]*#.*//' -e '/^[ ]*$/d' |
(
DEFS=
MODS=
OBJS=
LIBS=
RULES=
-
while read line
do
+ # Output DEFS in reverse order so first definition overrides
case $line in
- *=*) DEFS="$DEFS$line$NL"; continue;;
+ *=*) DEFS="$line$NL$DEFS"; continue;;
+ '<noobjects>') noobjects=yes; continue;;
esac
objs=
cpps=
@@ -27,7 +106,7 @@ sed -e 's/#.*//' -e '/^[ ]*$/d' ${1-Setup} |
do
case $arg in
-[IDUC]*) cpps="$cpps $arg";;
- -[Ll]*) LIBS="$LIBS $arg";;
+ -[A-Zl]*) LIBS="$LIBS $arg";;
*.a) LIBS="$LIBS $arg";;
*.o) objs="$objs $arg";;
*.*) echo 1>&2 "bad word $arg in $line"
@@ -37,9 +116,16 @@ sed -e 's/#.*//' -e '/^[ ]*$/d' ${1-Setup} |
exit 1;;
esac
done
+ case $noobjects in
+ yes) continue;;
+ esac
for obj in $objs
do
src=`basename $obj .o`.c
+ case $src in
+ glmodule.c) ;;
+ *) src='$(srcdir)/'$src;;
+ esac
RULES="$RULES$obj: $src; \$(CC) \$(CFLAGS) $cpps -c $src$NL"
done
OBJS="$OBJS $objs"
@@ -52,20 +138,29 @@ sed -e 's/#.*//' -e '/^[ ]*$/d' ${1-Setup} |
EXTDECLS="${EXTDECLS}extern void init$mod();$NL"
INITBITS="${INITBITS} {\"$mod\", init$mod},$NL"
done
- sed -e "
- /MARKER 1/i$NL$EXTDECLS
+ case $config in
+ -) ;;
+ *) sed -e "
+ 1i$NL/* Generated automatically from $config by makesetup. */
+ /MARKER 1/i$NL$EXTDECLS
/MARKER 2/i$NL$INITBITS
- " config.c.in >config.c
+ " $config >config.c
+ ;;
+ esac
- sed -e "
+ case $makepre in
+ -) ;;
+ *) sed -e "
+ 1i$NL# Generated automatically from $makepre by makesetup.
s%@MODOBJS@%$OBJS%
s%@MODLIBS@%$LIBS%
- /Rules added by ..makesetup/a$NL$NL$RULES
-
- /Definitions added by ..makesetup/a$NL$NL$DEFS
-
- " Makefile.in.in >Makefile.in
+ /Rules added by makesetup/a$NL$NL$RULES
+ /Definitions added by makesetup/a$NL$NL$DEFS
+
+ " $makepre >Makefile
+ ;;
+ esac
)
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 67e3cf7..4137e60 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -40,9 +40,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#undef HUGE_VAL
#endif
+#ifndef macintosh
#ifndef __STDC__
extern double fmod PROTO((double, double));
#endif
+#endif
#ifdef HUGE_VAL
#define CHECK(x) if (errno != 0) ; \
@@ -132,10 +134,14 @@ FUNC1(math_sqrt, sqrt)
FUNC1(math_tan, tan)
FUNC1(math_tanh, tanh)
+#ifndef macintosh
+
double frexp PROTO((double, int *));
double ldexp PROTO((double, int));
double modf PROTO((double, double *));
+#endif
+
static object *
math_frexp(self, args)
object *self;
@@ -180,7 +186,15 @@ math_modf(self, args)
if (!getdoublearg(args, &x))
return NULL;
errno = 0;
+#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
+{
+ extended e;
+ x = modf(x, &e);
+ y = e;
+}
+#else
x = modf(x, &y);
+#endif
CHECK(x);
if (errno != 0)
return math_error();
diff --git a/Modules/md5.h b/Modules/md5.h
index 5c01861..29ac540 100644
--- a/Modules/md5.h
+++ b/Modules/md5.h
@@ -32,6 +32,9 @@ documentation and/or software.
The following makes PROTOTYPES default to 0 if it has not already
been defined with C compiler flags.
*/
+#ifdef HAVE_PROTOTYPES
+#define PROTOTYPES 1
+#endif
#ifndef PROTOTYPES
#define PROTOTYPES 0
#endif
diff --git a/Modules/md5c.c b/Modules/md5c.c
index ffa0f0f..d7c7e4f 100644
--- a/Modules/md5c.c
+++ b/Modules/md5c.c
@@ -23,6 +23,9 @@ These notices must be retained in any copies of any part of this
documentation and/or software.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
#include "md5.h"
/* Constants for MD5Transform routine.
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 6230cee..68d52f4 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -1,6 +1,6 @@
/***********************************************************
-Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
All Rights Reserved
@@ -21,44 +21,43 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+
/* MD5 module */
-/* This module provides an interface to a message digest algorithm,
- MD5 in this case */
+/* This module provides an interface to the RSA Data Security,
+ Inc. MD5 Message-Digest Algorithm, described in RFC 1321.
+ It requires the files md5c.c and md5.h (which are slightly changed
+ from the versions in the RFC to avoid the "global.h" file.) */
+
/* MD5 objects */
#include "allobjects.h"
-#include "modsupport.h" /* For getargs() etc. */
+#include "modsupport.h"
#include "md5.h"
+
typedef struct {
OB_HEAD
MD5_CTX md5; /* the context holder */
} md5object;
-extern typeobject MD5type; /* Really static, forward */
+staticforward typeobject MD5type;
#define is_md5object(v) ((v)->ob_type == &MD5type)
-/* #define MD5_DEBUG */
-
static md5object *
newmd5object()
{
md5object *md5p;
-
-#ifdef MD5_DEBUG
- fputs( "md5_object() called...\n", stderr );
-#endif /* def MD5_DEBUG */
md5p = NEWOBJ(md5object, &MD5type);
if (md5p == NULL)
return NULL;
MD5Init(&md5p->md5); /* actual initialisation */
return md5p;
-} /* newmd5object() */
+}
/* MD5 methods */
@@ -67,56 +66,20 @@ static void
md5_dealloc(md5p)
md5object *md5p;
{
-#ifdef MD5_DEBUG
- fputs( "md5_dealloc() called...\n", stderr );
-#endif /* def MD5_DEBUG */
-
DEL(md5p);
-} /* md5_dealloc() */
-
-
-/* MD5 initialisation */
-
-static object *
-MD5_md5(self, args)
- object *self;
- object *args;
-{
- md5object *md5p;
- char *cp = (char *)NULL;
- int len;
-
-
-#ifdef MD5_DEBUG
- fputs("MD5_md5() called...\n", stderr);
-#endif /* def MD5_DEBUG */
-
- if (!getargs(args, "")) {
- err_clear();
- if (!getargs(args, "s#", &cp, &len))
- return NULL;
- }
-
- if ((md5p = newmd5object()) == NULL)
- return NULL;
-
- if (cp)
- MD5Update(&md5p->md5, cp, len);
-
- return (object *)md5p;
-} /* MD5_md5() */
+}
/* MD5 methods-as-attributes */
+
static object *
md5_update(self, args)
md5object *self;
object *args;
{
- char *cp;
+ unsigned char *cp;
int len;
-
if (!getargs(args, "s#", &cp, &len))
return NULL;
@@ -124,9 +87,8 @@ md5_update(self, args)
INCREF(None);
return None;
-} /* md5_update() */
+}
-#define DIGESTLEN 16 /* this is used twice--walrus@umich.edu */
static object *
md5_digest(self, args)
md5object *self;
@@ -134,8 +96,7 @@ md5_digest(self, args)
{
MD5_CTX mdContext;
- char aDigest[DIGESTLEN];
-
+ unsigned char aDigest[16];
if (!getnoarg(args))
return NULL;
@@ -144,9 +105,8 @@ md5_digest(self, args)
mdContext = self->md5;
MD5Final(aDigest, &mdContext);
- return newsizedstringobject((char *)aDigest, DIGESTLEN);
-} /* md5_digest() */
-#undef DIGESTLEN
+ return newsizedstringobject((char *)aDigest, 16);
+}
static object *
md5_copy(self, args)
@@ -155,7 +115,6 @@ md5_copy(self, args)
{
md5object *md5p;
-
if (!getnoarg(args))
return NULL;
@@ -165,13 +124,12 @@ md5_copy(self, args)
md5p->md5 = self->md5;
return (object *)md5p;
-} /* md5_copy() */
+}
-
static struct methodlist md5_methods[] = {
- {"update", md5_update},
- {"digest", md5_digest},
- {"copy", md5_copy},
+ {"update", (method)md5_update},
+ {"digest", (method)md5_digest},
+ {"copy", (method)md5_copy},
{NULL, NULL} /* sentinel */
};
@@ -181,31 +139,56 @@ md5_getattr(self, name)
char *name;
{
return findmethod(md5_methods, (object *)self, name);
-} /* md5_getattr() */
+}
-#ifndef _AIX
-static
-#endif
-typeobject MD5type = {
+static typeobject MD5type = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"md5", /*tp_name*/
sizeof(md5object), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- md5_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- md5_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
+ (destructor)md5_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)md5_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
};
+
+/* MD5 functions */
+
+static object *
+MD5_md5(self, args)
+ object *self;
+ object *args;
+{
+ md5object *md5p;
+ unsigned char *cp = NULL;
+ int len;
+
+ if (!getargs(args, "")) {
+ err_clear();
+ if (!getargs(args, "s#", &cp, &len))
+ return NULL;
+ }
+
+ if ((md5p = newmd5object()) == NULL)
+ return NULL;
+
+ if (cp)
+ MD5Update(&md5p->md5, cp, len);
+
+ return (object *)md5p;
+}
+
+
/* List of functions exported by this module */
static struct methodlist md5_functions[] = {
- {"md5", MD5_md5},
+ {"md5", (method)MD5_md5},
{NULL, NULL} /* Sentinel */
};
@@ -215,12 +198,5 @@ static struct methodlist md5_functions[] = {
void
initmd5()
{
-#ifdef MD5_DEBUG
- fputs( "initmd5() called...\n", stderr );
-#endif /* def MD5_DEBUG */
(void)initmodule("md5", md5_functions);
-} /* initmd5() */
-
-#ifdef MAKEDUMMYINT
-int _md5_dummy_int; /* XXX otherwise, we're .bss-less (DYNLOAD->Jack?) */
-#endif /* def MAKEDUMMYINT */
+}
diff --git a/Modules/mpzmodule.c b/Modules/mpzmodule.c
index d0b9d7f..9d0bdb0 100644
--- a/Modules/mpzmodule.c
+++ b/Modules/mpzmodule.c
@@ -1,6 +1,6 @@
/***********************************************************
-Copyright 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
All Rights Reserved
@@ -21,6 +21,7 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+
/* MPZ module */
/* This module provides an interface to an alternate Multi-Precision
@@ -35,6 +36,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
#include "modsupport.h" /* For getargs() etc. */
#include <assert.h>
+#include <sys/types.h> /* For size_t */
/*
** These are the cpp-flags used in this file...
@@ -89,7 +91,7 @@ typedef struct {
MP_INT mpz; /* the actual number */
} mpzobject;
-extern typeobject MPZtype; /* Really static, forward */
+staticforward typeobject MPZtype;
#define is_mpzobject(v) ((v)->ob_type == &MPZtype)
@@ -993,8 +995,10 @@ mpz_mpzcoerce(z)
err_setstr(TypeError, "number coercion (to mpzobject) failed");
return NULL;
} /* mpz_mpzcoerce() */
-
-static void mpz_divm();
+
+/* Forward */
+static void mpz_divm PROTO((MP_INT *res, const MP_INT *num,
+ const MP_INT *den, const MP_INT *mod));
static object *
MPZ_powm(self, args)
@@ -1546,7 +1550,7 @@ static struct methodlist mpz_methods[] = {
{"hex", mpz_hex},
{"oct", mpz_oct},
#endif /* def MPZ_CONVERSIONS_AS_METHODS */
- {"binary", (object * (*) (object *, object *)) mpz_binary},
+ {"binary", (object *(*)(object *, object *))mpz_binary},
{NULL, NULL} /* sentinel */
};
@@ -1601,9 +1605,10 @@ mpz_repr(v)
-#define UF (object* (*) FPROTO((object *))) /* Unary function */
-#define BF (object* (*) FPROTO((object *, object *))) /* Binary function */
-#define IF (int (*) FPROTO((object *))) /* Int function */
+#define UF (unaryfunc)
+#define BF (binaryfunc)
+#define IF (inquiry)
+#define CF (coercion)
static number_methods mpz_as_number = {
BF mpz_addition, /*nb_add*/
@@ -1623,8 +1628,7 @@ static number_methods mpz_as_number = {
BF mpz_andfunc, /*nb_and*/
BF mpz_xorfunc, /*nb_xor*/
BF mpz_orfunc, /*nb_or*/
- (int (*) FPROTO((object **, object **)))
- mpz_coerce, /*nb_coerce*/
+ CF mpz_coerce, /*nb_coerce*/
#ifndef MPZ_CONVERSIONS_AS_METHODS
UF mpz_int, /*nb_int*/
UF mpz_long, /*nb_long*/
@@ -1641,13 +1645,13 @@ static typeobject MPZtype = {
sizeof(mpzobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- (void (*) (object *)) mpz_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (object * (*)(object *, char *)) mpz_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- (int (*) (object *, object *)) mpz_compare, /*tp_compare*/
- mpz_repr, /*tp_repr*/
- &mpz_as_number, /*tp_as_number*/
+ (destructor)mpz_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)mpz_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ (cmpfunc)mpz_compare, /*tp_compare*/
+ (reprfunc)mpz_repr, /*tp_repr*/
+ &mpz_as_number, /*tp_as_number*/
};
/* List of functions exported by this module */
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index 5db26f4..00c3561 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -57,6 +57,8 @@ nis_mapname (map)
return map;
}
+typedef int (*foreachfunc) PROTO((int, char *, int, char *, int, char *));
+
static int
nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
int instatus;
@@ -134,7 +136,7 @@ nis_cat (self, args)
cat = newdictobject ();
if (cat == NULL)
return NULL;
- cb.foreach = nis_foreach;
+ cb.foreach = (foreachfunc)nis_foreach;
cb.data = (char *)cat;
BGN_SAVE
map = nis_mapname (map);
@@ -147,9 +149,17 @@ nis_cat (self, args)
return cat;
}
-#define YPPROC_MAPLIST ((u_long)11)
-#define YPPROG ((u_long)100004)
-#define YPVERS ((u_long)2)
+/* These should be u_long on Sun h/w but not on 64-bit h/w.
+ This is not portable to machines with 16-bit ints and no prototypes */
+#ifndef YPPROC_MAPLIST
+#define YPPROC_MAPLIST 11
+#endif
+#ifndef YPPROG
+#define YPPROG 100004
+#endif
+#ifndef YPVERS
+#define YPVERS 2
+#endif
typedef char *domainname;
typedef char *mapname;
@@ -260,8 +270,9 @@ nisproc_maplist_2(argp, clnt)
static nisresp_maplist res;
memset(&res, 0, sizeof(res));
- if (clnt_call(clnt, YPPROC_MAPLIST, nis_xdr_domainname, argp, nis_xdr_ypresp_maplist
-, &res, TIMEOUT) != RPC_SUCCESS) {
+ if (clnt_call(clnt, YPPROC_MAPLIST, nis_xdr_domainname, (caddr_t)argp,
+ nis_xdr_ypresp_maplist, (caddr_t)&res, TIMEOUT)
+ != RPC_SUCCESS) {
return (NULL);
}
return (&res);
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 3274c1a..04db26e 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -22,6 +22,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+/* Raw interface to the parser. */
+
#include "allobjects.h"
#include "node.h"
#include "token.h"
@@ -85,12 +87,10 @@ parser_parsefile(self, args)
err_errno(IOError);
return NULL;
}
- err = parse_file(fp, filename, file_input, &n);
+ n = parse_file(fp, filename, file_input);
fclose(fp);
- if (err != E_DONE) {
- err_input(err);
+ if (n == NULL)
return NULL;
- }
res = node2tuple(n);
freetree(n);
return res;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 07d12e7..a0f34e5 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -24,78 +24,115 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* POSIX module implementation */
-#ifdef AMOEBA
-#define NO_LSTAT
-#define SYSV
+#ifdef _M_IX86
+#define NT
+/* NT may be defined externally as well. If it is defined, the module is
+ actually called 'nt', not 'posix', and some functions don't exist. */
#endif
-#ifdef __sgi
-#define DO_PG
-#endif
-
-#ifdef _NEXT_SOURCE
-#define mode_t int
-#define NO_UNAME
-#endif
+#include "allobjects.h"
+#include "modsupport.h"
+#include "ceval.h"
-#include <signal.h>
#include <string.h>
-#include <setjmp.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#ifdef DO_TIMES
-#include <sys/times.h>
-#include <sys/param.h>
#include <errno.h>
-#endif
-#ifdef SYSV
-
-#define UTIME_STRUCT 1
-#include <dirent.h>
-#define direct dirent
-#ifdef i386
-#define mode_t int
-#endif
-
-#else /* !SYSV */
-
-#include <sys/dir.h>
+#ifndef macintosh
+#include <sys/types.h>
+#include <sys/stat.h>
+#endif
-#endif /* !SYSV */
+#include "mytime.h" /* For clock_t on some systems */
-#ifndef NO_UNISTD
-#include <unistd.h> /* Take this out and hope the best if it doesn't exist */
+#ifdef HAVE_FCNTL_H
+#include <fcntl.h>
#endif
-#include "allobjects.h"
-#include "modsupport.h"
-#include "ceval.h"
-
-#ifdef _SEQUENT_
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#else /* _SEQUENT_ */
-/* XXX Aren't these always declared in unistd.h? */
+#else /* !HAVE_UNISTD_H */
+
+#ifdef macintosh
+#include "macdefs.h"
+#else
extern int mkdir PROTO((const char *, mode_t));
extern int chdir PROTO((const char *));
extern int rmdir PROTO((const char *));
extern int chmod PROTO((const char *, mode_t));
-extern char *getcwd(); /* No PROTO((char *, int)) -- non portable */
+extern int chown PROTO((const char *, uid_t, gid_t));
+extern char *getcwd PROTO((char *, int));
extern char *strerror PROTO((int));
extern int link PROTO((const char *, const char *));
extern int rename PROTO((const char *, const char *));
extern int stat PROTO((const char *, struct stat *));
extern int unlink PROTO((const char *));
extern int pclose PROTO((FILE *));
-#endif /* !_SEQUENT_ */
-#ifdef NO_LSTAT
-#define lstat stat
-#else
-extern int lstat PROTO((const char *, struct stat *));
+#ifdef HAVE_SYMLINK
extern int symlink PROTO((const char *, const char *));
#endif
+#ifdef HAVE_LSTAT
+extern int lstat PROTO((const char *, struct stat *));
+#endif
+#endif /* macintosh */
+#endif /* !HAVE_UNISTD_H */
+
+#if 1
+/* XXX These are for SunOS4.1.3 but shouldn't hurt elsewhere */
+extern int rename();
+extern int pclose();
+extern int lstat();
+extern int symlink();
+#endif
+#ifdef HAVE_UTIME_H
+#include <utime.h>
+#endif
+
+#ifdef HAVE_SYS_TIMES_H
+#include <sys/times.h>
+#endif
+
+#ifdef HAVE_SYS_PARAM_H
+#include <sys/param.h>
+#endif
+
+#ifdef HAVE_SYS_UTSNAME_H
+#include <sys/utsname.h>
+#endif
+
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
+#endif
+
+/* unistd.h defines _POSIX_VERSION on POSIX.1 systems. */
+#if defined(DIRENT) || defined(_POSIX_VERSION)
+#include <dirent.h>
+#define NLENGTH(dirent) (strlen((dirent)->d_name))
+#else /* not (DIRENT or _POSIX_VERSION) */
+#define dirent direct
+#define NLENGTH(dirent) ((dirent)->d_namlen)
+#ifdef SYSNDIR
+#include <sys/ndir.h>
+#endif /* SYSNDIR */
+#ifdef SYSDIR
+#include <sys/dir.h>
+#endif /* SYSDIR */
+#ifdef NDIR
+#include <ndir.h>
+#endif /* NDIR */
+#endif /* not (DIRENT or _POSIX_VERSION) */
+
+#ifdef NT
+#include <direct.h>
+#include <io.h>
+#include <process.h>
+#include <windows.h>
+#define popen _popen
+#endif /* NT */
+
+#ifdef OS2
+#include <io.h>
+#endif
/* Return a dictionary corresponding to the POSIX environment table */
@@ -195,6 +232,25 @@ posix_strint(args, func)
}
static object *
+posix_strintint(args, func)
+ object *args;
+ int (*func) FPROTO((const char *, int, int));
+{
+ char *path;
+ int i,i2;
+ int res;
+ if (!getargs(args, "(sii)", &path, &i, &i2))
+ return NULL;
+ BGN_SAVE
+ res = (*func)(path, i, i2);
+ END_SAVE
+ if (res < 0)
+ return posix_error();
+ INCREF(None);
+ return None;
+}
+
+static object *
posix_do_stat(self, args, statfunc)
object *self;
object *args;
@@ -242,6 +298,16 @@ posix_chmod(self, args)
return posix_strint(args, chmod);
}
+#ifdef HAVE_CHOWN
+static object *
+posix_chown(self, args)
+ object *self;
+ object *args;
+{
+ return posix_strintint(args, chown);
+}
+#endif
+
static object *
posix_getcwd(self, args)
object *self;
@@ -259,6 +325,7 @@ posix_getcwd(self, args)
return newstringobject(buf);
}
+#ifdef HAVE_LINK
static object *
posix_link(self, args)
object *self;
@@ -266,7 +333,64 @@ posix_link(self, args)
{
return posix_2str(args, link);
}
+#endif
+
+#ifdef NT
+static object *
+posix_listdir(self, args)
+ object *self;
+ object *args;
+{
+ char *name;
+ int len;
+ object *d, *v;
+ HANDLE hFindFile;
+ WIN32_FIND_DATA FileData;
+ char namebuf[MAX_PATH+5];
+
+ if (!getargs(args, "s#", &name, &len))
+ return NULL;
+ if (len >= MAX_PATH) {
+ err_setstr(ValueError, "path too long");
+ return NULL;
+ }
+ strcpy(namebuf, name);
+ if (namebuf[len-1] != '/' && namebuf[len-1] != '\\')
+ namebuf[len++] = '/';
+ strcpy(namebuf + len, "*.*");
+
+ if ((d = newlistobject(0)) == NULL)
+ return NULL;
+
+ hFindFile = FindFirstFile(namebuf, &FileData);
+ if (hFindFile == INVALID_HANDLE_VALUE) {
+ errno = GetLastError();
+ return posix_error();
+ }
+ do {
+ v = newstringobject(FileData.cFileName);
+ if (v == NULL) {
+ DECREF(d);
+ d = NULL;
+ break;
+ }
+ if (addlistitem(d, v) != 0) {
+ DECREF(v);
+ DECREF(d);
+ d = NULL;
+ break;
+ }
+ DECREF(v);
+ } while (FindNextFile(hFindFile, &FileData) == TRUE);
+
+ if (FindClose(hFindFile) == FALSE) {
+ errno = GetLastError();
+ return posix_error();
+ }
+ return d;
+}
+#else /* ! NT */
static object *
posix_listdir(self, args)
object *self;
@@ -275,7 +399,7 @@ posix_listdir(self, args)
char *name;
object *d, *v;
DIR *dirp;
- struct direct *ep;
+ struct dirent *ep;
if (!getargs(args, "s", &name))
return NULL;
BGN_SAVE
@@ -308,6 +432,7 @@ posix_listdir(self, args)
return d;
}
+#endif /* ! NT */
static object *
posix_mkdir(self, args)
@@ -317,6 +442,7 @@ posix_mkdir(self, args)
return posix_strint(args, mkdir);
}
+#ifdef HAVE_NICE
static object *
posix_nice(self, args)
object *self;
@@ -331,21 +457,7 @@ posix_nice(self, args)
return posix_error();
return newintobject((long) value);
}
-
-#if i386 && ! _SEQUENT_
-int
-rename(from, to)
- char *from;
- char *to;
-{
- int status;
- /* XXX Shouldn't this unlink the destination first? */
- status = link(from, to);
- if (status != 0)
- return status;
- return unlink(from);
-}
-#endif /* i386 && ! _SEQUENT_ */
+#endif /* HAVE_NICE */
static object *
posix_rename(self, args)
@@ -408,11 +520,7 @@ posix_unlink(self, args)
return posix_1str(args, unlink);
}
-#ifndef NO_UNAME
-#include <sys/utsname.h>
-
-extern int uname PROTO((struct utsname *));
-
+#ifdef HAVE_UNAME
static object *
posix_uname(self, args)
object *self;
@@ -435,11 +543,7 @@ posix_uname(self, args)
u.version,
u.machine);
}
-#endif /* NO_UNAME */
-
-#ifdef UTIME_STRUCT
-#include <utime.h>
-#endif
+#endif /* HAVE_UNAME */
static object *
posix_utime(self, args)
@@ -449,12 +553,11 @@ posix_utime(self, args)
char *path;
int res;
-#ifdef UTIME_STRUCT
+#ifdef HAVE_UTIME_H
struct utimbuf buf;
#define ATIME buf.actime
#define MTIME buf.modtime
#define UTIME_ARG &buf
-
#else
time_t buf[2];
#define ATIME buf[0]
@@ -532,8 +635,12 @@ posix_execv(self, args)
}
argvlist[argc] = NULL;
+#ifdef BAD_EXEC_PROTOTYPES
+ execv(path, (const char **) argvlist);
+#else
execv(path, argvlist);
-
+#endif
+
/* If we get here it's definitely an error */
DEL(argvlist);
@@ -614,7 +721,12 @@ posix_execve(self, args)
}
envlist[envc] = 0;
+
+#ifdef BAD_EXEC_PROTOTYPES
+ execve(path, (const char **)argvlist, envlist);
+#else
execve(path, argvlist, envlist);
+#endif
/* If we get here it's definitely an error */
@@ -684,6 +796,7 @@ posix_getpid(self, args)
return newintobject((long)getpid());
}
+#ifdef HAVE_GETPGRP
static object *
posix_getpgrp(self, args)
object *self;
@@ -691,13 +804,15 @@ posix_getpgrp(self, args)
{
if (!getnoarg(args))
return NULL;
-#ifdef SYSV
- return newintobject((long)getpgrp());
-#else
+#ifdef GETPGRP_HAVE_ARG
return newintobject((long)getpgrp(0));
+#else
+ return newintobject((long)getpgrp());
#endif
}
+#endif /* HAVE_GETPGRP */
+#ifdef HAVE_SETPGRP
static object *
posix_setpgrp(self, args)
object *self;
@@ -705,16 +820,18 @@ posix_setpgrp(self, args)
{
if (!getnoarg(args))
return NULL;
-#ifdef SYSV
- if (setpgrp() < 0)
-#else
+#ifdef GETPGRP_HAVE_ARG
if (setpgrp(0, 0) < 0)
+#else
+ if (setpgrp() < 0)
#endif
return posix_error();
INCREF(None);
return None;
}
+#endif /* HAVE_SETPGRP */
+
static object *
posix_getppid(self, args)
object *self;
@@ -763,12 +880,10 @@ posix_popen(self, args)
END_SAVE
if (fp == NULL)
return posix_error();
- /* From now on, ignore SIGPIPE and let the error checking
- do the work. */
- (void) signal(SIGPIPE, SIG_IGN);
return newopenfileobject(fp, name, mode, pclose);
}
+#ifdef HAVE_SETUID
static object *
posix_setuid(self, args)
object *self;
@@ -782,7 +897,9 @@ posix_setuid(self, args)
INCREF(None);
return None;
}
+#endif
+#ifdef HAVE_SETGID
static object *
posix_setgid(self, args)
object *self;
@@ -796,17 +913,14 @@ posix_setgid(self, args)
INCREF(None);
return None;
}
+#endif
+#ifdef HAVE_WAITPID
static object *
posix_waitpid(self, args)
object *self;
object *args;
{
-#ifdef NO_WAITPID
- err_setstr(PosixError,
- "posix.waitpid() not supported on this system");
- return NULL;
-#else
int pid, options, sts;
if (!getargs(args, "(ii)", &pid, &options))
return NULL;
@@ -817,8 +931,8 @@ posix_waitpid(self, args)
return posix_error();
else
return mkvalue("ii", pid, sts);
-#endif
}
+#endif /* HAVE_WAITPID */
static object *
posix_wait(self, args)
@@ -826,8 +940,6 @@ posix_wait(self, args)
object *args;
{
int pid, sts;
- if (args != NULL)
- return posix_waitpid(self, args); /* BW compat */
BGN_SAVE
pid = wait(&sts);
END_SAVE
@@ -842,19 +954,20 @@ posix_lstat(self, args)
object *self;
object *args;
{
+#ifdef HAVE_LSTAT
return posix_do_stat(self, args, lstat);
+#else /* !HAVE_LSTAT */
+ return posix_do_stat(self, args, stat);
+#endif /* !HAVE_LSTAT */
}
+#ifdef HAVE_READLINK
static object *
posix_readlink(self, args)
object *self;
object *args;
{
-#ifdef NO_LSTAT
- err_setstr(PosixError, "readlink not implemented on this system");
- return NULL;
-#else
- char buf[1024]; /* XXX Should use MAXPATHLEN */
+ char buf[MAXPATHLEN];
char *path;
int n;
if (!getargs(args, "s", &path))
@@ -865,25 +978,23 @@ posix_readlink(self, args)
if (n < 0)
return posix_error();
return newsizedstringobject(buf, n);
-#endif
}
+#endif /* HAVE_READLINK */
+#ifdef HAVE_SYMLINK
static object *
posix_symlink(self, args)
object *self;
object *args;
{
-#ifdef NO_LSTAT
- err_setstr(PosixError, "symlink not implemented on this system");
- return NULL;
-#else
return posix_2str(args, symlink);
-#endif
}
+#endif /* HAVE_SYMLINK */
-
-#ifdef DO_TIMES
-
+#ifdef HAVE_TIMES
+#ifndef HZ
+#define HZ 60 /* Universal constant :-) */
+#endif
static object *
posix_times(self, args)
object *self;
@@ -903,11 +1014,9 @@ posix_times(self, args)
(double)t.tms_cutime / HZ,
(double)t.tms_cstime / HZ);
}
+#endif /* HAVE_TIMES */
-#endif /* DO_TIMES */
-
-#ifdef DO_PG
-
+#ifdef HAVE_SETSID
static object *
posix_setsid(self, args)
object *self;
@@ -920,7 +1029,9 @@ posix_setsid(self, args)
INCREF(None);
return None;
}
+#endif /* HAVE_SETSID */
+#ifdef HAVE_SETPGID
static object *
posix_setpgid(self, args)
object *self;
@@ -934,7 +1045,9 @@ posix_setpgid(self, args)
INCREF(None);
return None;
}
+#endif /* HAVE_SETPGID */
+#ifdef HAVE_TCGETPGRP
static object *
posix_tcgetpgrp(self, args)
object *self;
@@ -948,7 +1061,9 @@ posix_tcgetpgrp(self, args)
return posix_error();
return newintobject((long)pgid);
}
+#endif /* HAVE_TCGETPGRP */
+#ifdef HAVE_TCSETPGRP
static object *
posix_tcsetpgrp(self, args)
object *self;
@@ -962,8 +1077,7 @@ posix_tcsetpgrp(self, args)
INCREF(None);
return None;
}
-
-#endif /* DO_PG */
+#endif /* HAVE_TCSETPGRP */
/* Functions acting on file descriptors */
@@ -1150,7 +1264,6 @@ posix_fdopen(self, args)
return posix_error();
/* From now on, ignore SIGPIPE and let the error checking
do the work. */
- (void) signal(SIGPIPE, SIG_IGN);
return newopenfileobject(fp, "(fdopen)", mode, fclose);
}
@@ -1174,49 +1287,84 @@ posix_pipe(self, args)
static struct methodlist posix_methods[] = {
{"chdir", posix_chdir},
{"chmod", posix_chmod},
+#ifdef HAVE_CHOWN
+ {"chown", posix_chown},
+#endif
{"getcwd", posix_getcwd},
+#ifdef HAVE_LINK
{"link", posix_link},
+#endif
{"listdir", posix_listdir},
{"lstat", posix_lstat},
{"mkdir", posix_mkdir},
+#ifdef HAVE_NICE
{"nice", posix_nice},
+#endif
+#ifdef HAVE_READLINK
{"readlink", posix_readlink},
+#endif
{"rename", posix_rename},
{"rmdir", posix_rmdir},
{"stat", posix_stat},
+#ifdef HAVE_SYMLINK
{"symlink", posix_symlink},
+#endif
{"system", posix_system},
{"umask", posix_umask},
-#ifndef NO_UNAME
+#ifdef HAVE_UNAME
{"uname", posix_uname},
#endif
{"unlink", posix_unlink},
+#ifndef NT
{"utime", posix_utime},
-#ifdef DO_TIMES
+#endif /* ! NT */
+#ifdef HAVE_TIMES
{"times", posix_times},
#endif
{"_exit", posix__exit},
{"execv", posix_execv},
{"execve", posix_execve},
+#ifndef NT
{"fork", posix_fork},
{"getegid", posix_getegid},
{"geteuid", posix_geteuid},
{"getgid", posix_getgid},
+#endif /* ! NT */
{"getpid", posix_getpid},
+#ifdef HAVE_GETPGRP
{"getpgrp", posix_getpgrp},
+#endif
+#ifndef NT
{"getppid", posix_getppid},
{"getuid", posix_getuid},
{"kill", posix_kill},
+#endif /* ! NT */
{"popen", posix_popen},
+#ifdef HAVE_SETUID
{"setuid", posix_setuid},
+#endif
+#ifdef HAVE_SETGID
{"setgid", posix_setgid},
+#endif
+#ifdef HAVE_SETPGRP
{"setpgrp", posix_setpgrp},
+#endif
+#ifndef NT
{"wait", posix_wait},
+#endif /* ! NT */
+#ifdef HAVE_WAITPID
{"waitpid", posix_waitpid},
-#ifdef DO_PG
+#endif
+#ifdef HAVE_SETSID
{"setsid", posix_setsid},
+#endif
+#ifdef HAVE_SETPGID
{"setpgid", posix_setpgid},
+#endif
+#ifdef HAVE_TCGETPGRP
{"tcgetpgrp", posix_tcgetpgrp},
+#endif
+#ifdef HAVE_TCSETPGRP
{"tcsetpgrp", posix_tcsetpgrp},
#endif
{"open", posix_open},
@@ -1228,12 +1376,35 @@ static struct methodlist posix_methods[] = {
{"write", posix_write},
{"fstat", posix_fstat},
{"fdopen", posix_fdopen},
+#ifndef NT
{"pipe", posix_pipe},
+#endif /* ! NT */
{NULL, NULL} /* Sentinel */
};
+#ifdef NT
+void
+initnt()
+{
+ object *m, *d, *v;
+
+ m = initmodule("nt", posix_methods);
+ d = getmoduledict(m);
+
+ /* Initialize nt.environ dictionary */
+ v = convertenviron();
+ if (v == NULL || dictinsert(d, "environ", v) != 0)
+ fatal("can't define nt.environ");
+ DECREF(v);
+
+ /* Initialize nt.error exception */
+ PosixError = newstringobject("nt.error");
+ if (PosixError == NULL || dictinsert(d, "error", PosixError) != 0)
+ fatal("can't define nt.error");
+}
+#else /* ! NT */
void
initposix()
{
@@ -1253,17 +1424,4 @@ initposix()
if (PosixError == NULL || dictinsert(d, "error", PosixError) != 0)
fatal("can't define posix.error");
}
-
-
-/* Function used elsewhere to get a file's modification time */
-
-long
-getmtime(path)
- char *path;
-{
- struct stat st;
- if (stat(path, &st) != 0)
- return -1;
- else
- return st.st_mtime;
-}
+#endif /* ! NT */
diff --git a/Modules/pwdmodule.c b/Modules/pwdmodule.c
index 00ea348..5775473 100644
--- a/Modules/pwdmodule.c
+++ b/Modules/pwdmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -22,18 +22,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
-/* Passwd/group file access module */
+/* UNIX password file access module */
#include "allobjects.h"
#include "modsupport.h"
#include <sys/types.h>
#include <pwd.h>
-#include <grp.h>
-
-
-/* Module pwd */
-
static object *mkpwent(p)
struct passwd *p;
@@ -109,94 +104,3 @@ initpwd()
{
initmodule("pwd", pwd_methods);
}
-
-
-/* Module grp */
-
-
-static object *mkgrent(p)
- struct group *p;
-{
- object *v, *w;
- char **member;
- if ((w = newlistobject(0)) == NULL) {
- return NULL;
- }
- for (member = p->gr_mem; *member != NULL; member++) {
- object *x = newstringobject(*member);
- if (x == NULL || addlistitem(w, x) != 0) {
- XDECREF(x);
- DECREF(w);
- return NULL;
- }
- }
- v = mkvalue("(sslO)",
- p->gr_name,
- p->gr_passwd,
- (long)p->gr_gid,
- w);
- DECREF(w);
- return v;
-}
-
-static object *grp_getgrgid(self, args)
- object *self, *args;
-{
- int gid;
- struct group *p;
- if (!getintarg(args, &gid))
- return NULL;
- if ((p = getgrgid(gid)) == NULL) {
- err_setstr(KeyError, "getgrgid(): gid not found");
- return NULL;
- }
- return mkgrent(p);
-}
-
-static object *grp_getgrnam(self, args)
- object *self, *args;
-{
- char *name;
- struct group *p;
- if (!getstrarg(args, &name))
- return NULL;
- if ((p = getgrnam(name)) == NULL) {
- err_setstr(KeyError, "getgrnam(): name not found");
- return NULL;
- }
- return mkgrent(p);
-}
-
-static object *grp_getgrall(self, args)
- object *self, *args;
-{
- object *d;
- struct group *p;
- if (!getnoarg(args))
- return NULL;
- if ((d = newlistobject(0)) == NULL)
- return NULL;
- setgrent();
- while ((p = getgrent()) != NULL) {
- object *v = mkgrent(p);
- if (v == NULL || addlistitem(d, v) != 0) {
- XDECREF(v);
- DECREF(d);
- return NULL;
- }
- }
- return d;
-}
-
-static struct methodlist grp_methods[] = {
- {"getgrgid", grp_getgrgid},
- {"getgrnam", grp_getgrnam},
- {"getgrall", grp_getgrall},
- {NULL, NULL} /* sentinel */
-};
-
-void
-initgrp()
-{
- initmodule("grp", grp_methods);
-}
diff --git a/Modules/regexmodule.c b/Modules/regexmodule.c
index 13c6cb2..c4b15ff 100644
--- a/Modules/regexmodule.c
+++ b/Modules/regexmodule.c
@@ -4,7 +4,7 @@ XXX support mstop parameter on search
*/
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -35,6 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "regexpr.h"
+#include "ctype.h"
static object *RegexError; /* Exception */
@@ -45,6 +46,9 @@ typedef struct {
char re_fastmap[256]; /* Storage for fastmap */
object *re_translate; /* String object for translate table */
object *re_lastok; /* String object last matched/searched */
+ object *re_groupindex; /* Group name to index dictionary */
+ object *re_givenpat; /* Pattern with symbolic groups */
+ object *re_realpat; /* Pattern without symbolic groups */
} regexobject;
/* Regex object methods */
@@ -55,8 +59,9 @@ reg_dealloc(re)
{
XDECREF(re->re_translate);
XDECREF(re->re_lastok);
- XDEL(re->re_patbuf.buffer);
- XDEL(re->re_patbuf.translate);
+ XDECREF(re->re_groupindex);
+ XDECREF(re->re_givenpat);
+ XDECREF(re->re_realpat);
DEL(re);
}
@@ -188,8 +193,24 @@ reg_group(re, args)
}
return res;
}
- if (!getargs(args, "i", &i))
- return NULL;
+ if (!getargs(args, "i", &i)) {
+ object *n;
+ err_clear();
+ if (!getargs(args, "S", &n))
+ return NULL;
+ else {
+ object *index;
+ if (re->re_groupindex == NULL)
+ index = NULL;
+ else
+ index = mappinglookup(re->re_groupindex, n);
+ if (index == NULL) {
+ err_setstr(RegexError, "group() group name doesn't exist");
+ return NULL;
+ }
+ i = getintvalue(index);
+ }
+ }
if (i < 0 || i >= RE_NREGS) {
err_setstr(RegexError, "group() index out of range");
return NULL;
@@ -209,9 +230,9 @@ reg_group(re, args)
}
static struct methodlist reg_methods[] = {
- {"match", reg_match},
- {"search", reg_search},
- {"group", reg_group},
+ {"match", (method)reg_match},
+ {"search", (method)reg_search},
+ {"group", (method)reg_group},
{NULL, NULL} /* sentinel */
};
@@ -243,12 +264,39 @@ reg_getattr(re, name)
INCREF(re->re_translate);
return re->re_translate;
}
+ if (strcmp(name, "groupindex") == 0) {
+ if (re->re_groupindex == NULL) {
+ INCREF(None);
+ return None;
+ }
+ INCREF(re->re_groupindex);
+ return re->re_groupindex;
+ }
+ if (strcmp(name, "realpat") == 0) {
+ if (re->re_realpat == NULL) {
+ INCREF(None);
+ return None;
+ }
+ INCREF(re->re_realpat);
+ return re->re_realpat;
+ }
+ if (strcmp(name, "givenpat") == 0) {
+ if (re->re_givenpat == NULL) {
+ INCREF(None);
+ return None;
+ }
+ INCREF(re->re_givenpat);
+ return re->re_givenpat;
+ }
if (strcmp(name, "__members__") == 0) {
- object *list = newlistobject(3);
+ object *list = newlistobject(6);
if (list) {
setlistitem(list, 0, newstringobject("last"));
setlistitem(list, 1, newstringobject("regs"));
setlistitem(list, 2, newstringobject("translate"));
+ setlistitem(list, 3, newstringobject("groupindex"));
+ setlistitem(list, 4, newstringobject("realpat"));
+ setlistitem(list, 5, newstringobject("givenpat"));
if (err_occurred()) {
DECREF(list);
list = NULL;
@@ -266,21 +314,25 @@ static typeobject Regextype = {
sizeof(regexobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- reg_dealloc, /*tp_dealloc*/
+ (destructor)reg_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- reg_getattr, /*tp_getattr*/
+ (getattrfunc)reg_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
};
static object *
-newregexobject(pat, size, translate)
- char *pat;
- int size;
+newregexobject(pattern, translate, givenpat, groupindex)
+ object *pattern;
object *translate;
+ object *givenpat;
+ object *groupindex;
{
regexobject *re;
+ char *pat = getstringvalue(pattern);
+ int size = getstringsize(pattern);
+
if (translate != NULL && getstringsize(translate) != 256) {
err_setstr(RegexError,
"translation table must be 256 bytes");
@@ -299,6 +351,11 @@ newregexobject(pat, size, translate)
XINCREF(translate);
re->re_translate = translate;
re->re_lastok = NULL;
+ re->re_groupindex = groupindex;
+ INCREF(pattern);
+ re->re_realpat = pattern;
+ INCREF(givenpat);
+ re->re_givenpat = givenpat;
error = re_compile_pattern(pat, size, &re->re_patbuf);
if (error != NULL) {
err_setstr(RegexError, error);
@@ -314,17 +371,131 @@ regex_compile(self, args)
object *self;
object *args;
{
- char *pat;
- int size;
+ object *pat = NULL;
object *tran = NULL;
- if (!getargs(args, "s#", &pat, &size)) {
+ if (!getargs(args, "S", &pat)) {
err_clear();
- if (!getargs(args, "(s#S)", &pat, &size, &tran))
+ if (!getargs(args, "(SS)", &pat, &tran))
return NULL;
}
- return newregexobject(pat, size, tran);
+ return newregexobject(pat, tran, pat, NULL);
}
+static object *
+symcomp(pattern, gdict)
+ object *pattern;
+ object *gdict;
+{
+ char *opat = getstringvalue(pattern);
+ char *oend = opat + getstringsize(pattern);
+ int group_count = 0;
+ int escaped = 0;
+ char *o = opat;
+ char *n;
+ char name_buf[128];
+ char *g;
+ object *npattern;
+ int require_escape = re_syntax & RE_NO_BK_PARENS ? 0 : 1;
+
+ npattern = newsizedstringobject((char*)NULL, getstringsize(pattern));
+ if (npattern == NULL)
+ return NULL;
+ n = getstringvalue(npattern);
+
+ while (o < oend) {
+ if (*o == '(' && escaped == require_escape) {
+ char *backtrack;
+ escaped = 0;
+ ++group_count;
+ *n++ = *o;
+ if (++o >= oend || *o != '<')
+ continue;
+ /* *o == '<' */
+ if (o+1 < oend && *(o+1) == '>')
+ continue;
+ backtrack = o;
+ g = name_buf;
+ for (++o; o < oend;) {
+ if (*o == '>') {
+ object *group_name = NULL;
+ object *group_index = NULL;
+ *g++ = '\0';
+ group_name = newstringobject(name_buf);
+ group_index = newintobject(group_count);
+ if (group_name == NULL || group_index == NULL
+ || mappinginsert(gdict, group_name, group_index) != 0) {
+ XDECREF(group_name);
+ XDECREF(group_index);
+ XDECREF(npattern);
+ return NULL;
+ }
+ ++o; /* eat the '>' */
+ break;
+ }
+ if (!isalnum(*o) && *o != '_') {
+ o = backtrack;
+ break;
+ }
+ *g++ = *o++;
+ }
+ }
+ if (*o == '[' && !escaped) {
+ *n++ = *o;
+ ++o; /* eat the char following '[' */
+ *n++ = *o;
+ while (o < oend && *o != ']') {
+ ++o;
+ *n++ = *o;
+ }
+ if (o < oend)
+ ++o;
+ }
+ else if (*o == '\\') {
+ escaped = 1;
+ *n++ = *o;
+ ++o;
+ }
+ else {
+ escaped = 0;
+ *n++ = *o;
+ ++o;
+ }
+ }
+
+ if (resizestring(&npattern, n - getstringvalue(npattern)) == 0)
+ return npattern;
+ else {
+ DECREF(npattern);
+ return NULL;
+ }
+
+}
+
+static object *
+regex_symcomp(self, args)
+ object *self;
+ object *args;
+{
+ object *pattern;
+ object *tran = NULL;
+ object *gdict = NULL;
+ object *npattern;
+ if (!getargs(args, "S", &pattern)) {
+ err_clear();
+ if (!getargs(args, "(SS)", &pattern, &tran))
+ return NULL;
+ }
+ gdict = newmappingobject();
+ if (gdict == NULL
+ || (npattern = symcomp(pattern, gdict)) == NULL) {
+ DECREF(gdict);
+ DECREF(pattern);
+ return NULL;
+ }
+ return newregexobject(npattern, tran, pattern, gdict);
+}
+
+
static object *cache_pat;
static object *cache_prog;
@@ -384,6 +555,7 @@ regex_set_syntax(self, args)
static struct methodlist regex_global_methods[] = {
{"compile", regex_compile},
+ {"symcomp", regex_symcomp},
{"match", regex_match},
{"search", regex_search},
{"set_syntax", regex_set_syntax},
diff --git a/Modules/regexpr.c b/Modules/regexpr.c
index d5c0c85..f877558 100644
--- a/Modules/regexpr.c
+++ b/Modules/regexpr.c
@@ -22,11 +22,9 @@ Free Software Foundation.
Emacs-specific code and syntax table code is almost directly borrowed
from GNU regexp.
-$Header$
-
*/
-#include "PROTO.h" /* For PROTO macro --Guido */
+#include "myproto.h" /* For PROTO macro --Guido */
#include <stdio.h>
#include <assert.h>
@@ -116,6 +114,7 @@ enum regexp_syntax_op /* syntax codes for plain and quoted characters */
static int re_compile_initialized = 0;
static int regexp_syntax = 0;
+int re_syntax = 0; /* Exported copy of regexp_syntax */
static unsigned char regexp_plain_ops[256];
static unsigned char regexp_quoted_ops[256];
static unsigned char regexp_precedences[Rnum_ops];
@@ -256,6 +255,7 @@ int syntax;
ret = regexp_syntax;
regexp_syntax = syntax;
+ re_syntax = syntax; /* Exported copy */
re_compile_initialize();
return ret;
}
@@ -644,7 +644,7 @@ regexp_t bufp;
}
if (range)
{
- for (a = prev; a <= ch; a++)
+ for (a = prev; a <= (int)ch; a++)
SETBIT(pattern, offset, a);
prev = -1;
range = 0;
diff --git a/Modules/regexpr.h b/Modules/regexpr.h
index 7e82abd..034da3c 100644
--- a/Modules/regexpr.h
+++ b/Modules/regexpr.h
@@ -25,11 +25,6 @@ Last modified: Mon Nov 4 15:49:46 1991 ylo
#ifndef REGEXPR_H
#define REGEXPR_H
-#if defined(__STDC__) || defined(THINK_C)
-#undef HAVE_PROTOTYPES
-#define HAVE_PROTOTYPES
-#endif
-
#define RE_NREGS 100 /* number of registers available */
typedef struct re_pattern_buffer
@@ -69,6 +64,10 @@ typedef struct re_registers
#ifdef HAVE_PROTOTYPES
+extern int re_syntax;
+/* This is the actual syntax mask. It was added so that Python
+ could do syntax-dependent munging of patterns before compilation. */
+
int re_set_syntax(int syntax);
/* This sets the syntax to use and returns the previous syntax. The
syntax is specified by a bit mask of the above defined bits. */
@@ -129,6 +128,7 @@ int re_exec(char *s);
#else /* HAVE_PROTOTYPES */
+extern int re_syntax;
int re_set_syntax();
char *re_compile_pattern();
int re_match();
diff --git a/Modules/rgbimgmodule.c b/Modules/rgbimgmodule.c
index 4421f5d..de888eb 100644
--- a/Modules/rgbimgmodule.c
+++ b/Modules/rgbimgmodule.c
@@ -16,7 +16,9 @@
*/
#include "allobjects.h"
#include "modsupport.h"
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
+#endif
#include <string.h>
/*
@@ -199,7 +201,7 @@ IMAGE *image;
static int writetab(outf,tab,len)
FILE *outf;
-unsigned long *tab;
+/*unsigned*/ long *tab;
int len;
{
int r;
@@ -213,7 +215,7 @@ int len;
static readtab(inf,tab,len)
FILE *inf;
-unsigned long *tab;
+/*unsigned*/ long *tab;
int len;
{
while(len) {
@@ -744,7 +746,7 @@ initrgbimg()
object *m, *d;
m = initmodule("rgbimg", rgbimg_methods);
d = getmoduledict(m);
- ImgfileError = newstringobject("rgbimg,error");
+ ImgfileError = newstringobject("rgbimg.error");
if (ImgfileError == NULL || dictinsert(d, "error", ImgfileError))
fatal("can't define rgbimg.error");
}
diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c
index d397e2c..a6d043f 100644
--- a/Modules/rotormodule.c
+++ b/Modules/rotormodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -89,7 +89,7 @@ typedef struct {
unsigned char *advances; /* [num_rotors] */
} rotorobject;
-extern typeobject Rotortype; /* Really static, forward */
+staticforward typeobject Rotortype;
#define is_rotorobject(v) ((v)->ob_type == &Rotortype)
@@ -486,7 +486,7 @@ static unsigned char RTR_e_char(r, p)
}
} else {
while (i < r->rotors) {
- tp = r->e_rotor[(i*r->size)+(((r->positions[i] ^ tp) % r->size))];
+ tp = r->e_rotor[(i*r->size)+(((r->positions[i] ^ tp) % (unsigned int) r->size))];
i++;
}
}
@@ -525,7 +525,7 @@ static unsigned char RTR_d_char(r, c)
}
} else {
while (0 <= i) {
- tc = (r->positions[i] ^ r->d_rotor[(i*r->size)+tc]) % r->size;
+ tc = (r->positions[i] ^ r->d_rotor[(i*r->size)+tc]) % (unsigned int) r->size;
i--;
}
}
@@ -656,7 +656,7 @@ rotor_encrypt(self, args)
}
memset(tmp,'\0',len+1);
memcpy(tmp,string,len);
- RTR_e_region(self,tmp,len, TRUE);
+ RTR_e_region(self,(unsigned char *)tmp,len, TRUE);
rtn = newsizedstringobject(tmp,len);
free(tmp);
return(rtn);
@@ -680,7 +680,7 @@ rotor_encryptmore(self, args)
}
memset(tmp,'\0',len+1);
memcpy(tmp,string,len);
- RTR_e_region(self,tmp,len, FALSE);
+ RTR_e_region(self,(unsigned char *)tmp,len, FALSE);
rtn = newsizedstringobject(tmp,len);
free(tmp);
return(rtn);
@@ -704,7 +704,7 @@ rotor_decrypt(self, args)
}
memset(tmp,'\0',len+1);
memcpy(tmp,string,len);
- RTR_d_region(self,tmp,len, TRUE);
+ RTR_d_region(self,(unsigned char *)tmp,len, TRUE);
rtn = newsizedstringobject(tmp,len);
free(tmp);
return(rtn);
@@ -728,7 +728,7 @@ rotor_decryptmore(self, args)
}
memset(tmp,'\0',len+1);
memcpy(tmp,string,len);
- RTR_d_region(self,tmp,len, FALSE);
+ RTR_d_region(self,(unsigned char *)tmp,len, FALSE);
rtn = newsizedstringobject(tmp,len);
free(tmp);
return(rtn);
@@ -749,11 +749,11 @@ rotor_setkey(self, args)
}
static struct methodlist rotor_methods[] = {
- {"encrypt", rotor_encrypt},
- {"encryptmore", rotor_encryptmore},
- {"decrypt", rotor_decrypt},
- {"decryptmore", rotor_decryptmore},
- {"setkey", rotor_setkey},
+ {"encrypt", (method)rotor_encrypt},
+ {"encryptmore", (method)rotor_encryptmore},
+ {"decrypt", (method)rotor_decrypt},
+ {"decryptmore", (method)rotor_decryptmore},
+ {"setkey", (method)rotor_setkey},
{NULL, NULL} /* sentinel */
};
@@ -769,17 +769,17 @@ rotor_getattr(s, name)
static typeobject Rotortype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
+ 0, /*ob_size*/
"rotor", /*tp_name*/
- sizeof(rotorobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ sizeof(rotorobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- rotor_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- rotor_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)rotor_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)rotor_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 2cae7f4..ef3ec23 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,7 +28,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "ceval.h"
-#include "myselect.h"
+#include <sys/types.h>
+#include "myselect.h" /* Also includes mytime.h */
static object *SelectError;
@@ -63,12 +64,13 @@ list2set(list, set, fd2obj)
err_badarg();
return -1;
}
- if ( v >= FD_SETSIZE ) {
- err_setstr(SystemError, "FD_SETSIZE too low in select()");
+ if ( v < 0 || v >= FD_SETSIZE ) {
+ err_setstr(ValueError, "filedescriptor out of range in select()");
return -1;
}
if ( v > max ) max = v;
FD_SET(v, set);
+ XDECREF(fd2obj[v]);
fd2obj[v] = o;
}
return max+1;
@@ -91,11 +93,12 @@ set2list(set, max, fd2obj)
for(i=0; i<max; i++)
if ( FD_ISSET(i,set) ) {
if ( i > FD_SETSIZE ) {
- err_setstr(SystemError, "FD_SETSIZE too low in select()");
+ err_setstr(SystemError,
+ "filedescriptor out of range returned in select()");
return NULL;
}
o = fd2obj[i];
- if ( o == 0 ) {
+ if ( o == NULL ) {
err_setstr(SystemError,
"Bad filedescriptor returned from select()");
return NULL;
diff --git a/Modules/sgimodule.c b/Modules/sgimodule.c
index 418609d..92a8acd 100644
--- a/Modules/sgimodule.c
+++ b/Modules/sgimodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 211ebe7..640505b 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -107,6 +107,19 @@ signal_handler(sig_num)
static object *
+signal_alarm(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ int t;
+ if (!getargs(args, "i", &t))
+ return NULL;
+ alarm(t);
+ INCREF(None);
+ return None;
+}
+
+static object *
signal_signal(self, args)
object *self; /* Not used */
object *args;
@@ -173,6 +186,7 @@ signal_getsignal(self, args)
/* List of functions defined in the module */
static struct methodlist signal_methods[] = {
+ {"alarm", signal_alarm},
{"signal", signal_signal},
{"getsignal", signal_getsignal},
{NULL, NULL} /* sentinel */
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index 3fc8755..32f22db 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -30,7 +30,7 @@ This module provides an interface to Berkeley socket IPC.
Limitations:
- only AF_INET and AF_UNIX address families are supported
-- no asynchronous I/O (but read polling: avail)
+- no asynchronous I/O (but you can use select() on sockets)
- no read/write operations (use send/recv or makefile instead)
- setsockopt() and getsockopt() only support integer options
@@ -51,7 +51,6 @@ Interface:
Socket methods:
- s.accept() --> new socket object, sockaddr
-- s.avail() --> boolean
- s.setsockopt(level, optname, flag) --> None
- s.getsockopt(level, optname) --> flag
- s.bind(sockaddr) --> None
@@ -62,8 +61,8 @@ Socket methods:
- s.makefile(mode) --> file object
- s.recv(nbytes [,flags]) --> string
- s.recvfrom(nbytes [,flags]) --> string, sockaddr
-- s.send(string [,flags]) --> None
-- s.sendto(string, [flags,] sockaddr) --> None
+- s.send(string [,flags]) --> nbytes
+- s.sendto(string, [flags,] sockaddr) --> nbytes
- s.shutdown(how) --> None
- s.close() --> None
@@ -73,17 +72,17 @@ Socket methods:
#include "modsupport.h"
#include "ceval.h"
-#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
+#include <sys/types.h>
+#include "mytime.h"
#include <signal.h>
+#include <netdb.h>
#include <sys/socket.h>
#include <netinet/in.h>
+#ifdef HAVE_SYS_UN_H
#include <sys/un.h>
-#include <netdb.h>
-
-#ifdef i860
-/* Cray APP doesn't have getpeername() */
-#define NO_GETPEERNAME
+#else
+#undef AF_UNIX
#endif
@@ -121,7 +120,7 @@ typedef struct {
some of which call newsocobject(), which uses Socktype, so
there has to be a circular reference. */
-extern typeobject Socktype; /* Forward */
+staticforward typeobject Socktype;
/* Create a new socket object.
@@ -233,11 +232,13 @@ makesockaddr(addr, addrlen)
return ret;
}
+#ifdef AF_UNIX
case AF_UNIX:
{
struct sockaddr_un *a = (struct sockaddr_un *) addr;
return newstringobject(a->sun_path);
}
+#endif /* AF_UNIX */
/* More cases here... */
@@ -263,6 +264,7 @@ getsockaddrarg(s, args, addr_ret, len_ret)
{
switch (s->sock_family) {
+#ifdef AF_UNIX
case AF_UNIX:
{
static struct sockaddr_un addr;
@@ -280,6 +282,7 @@ getsockaddrarg(s, args, addr_ret, len_ret)
*len_ret = len + sizeof addr.sun_family;
return 1;
}
+#endif /* AF_UNIX */
case AF_INET:
{
@@ -318,11 +321,13 @@ getsockaddrlen(s, len_ret)
{
switch (s->sock_family) {
+#ifdef AF_UNIX
case AF_UNIX:
{
*len_ret = sizeof (struct sockaddr_un);
return 1;
}
+#endif /* AF_UNIX */
case AF_INET:
{
@@ -477,29 +482,6 @@ sock_getsockopt(s, args)
}
-/* s.avail() method */
-
-static object *
-sock_avail(s, args)
- sockobject *s;
- object *args;
-{
- struct timeval timeout;
- fd_set readers;
- int n;
- if (!getnoarg(args))
- return NULL;
- timeout.tv_sec = 0;
- timeout.tv_usec = 0;
- FD_ZERO(&readers);
- FD_SET(s->sock_fd, &readers);
- n = select(s->sock_fd+1, &readers, (fd_set *)0, (fd_set *)0, &timeout);
- if (n < 0)
- return socket_error();
- return newintobject((long) (n != 0));
-}
-
-
/* s.bind(sockaddr) method */
static object *
@@ -599,7 +581,7 @@ sock_getsockname(s, args)
}
-#ifndef NO_GETPEERNAME
+#ifdef HAVE_GETPEERNAME /* Cray APP doesn't have this :-( */
/* s.getpeername() method */
static object *
@@ -620,7 +602,7 @@ sock_getpeername(s, args)
return socket_error();
return makesockaddr((struct sockaddr *) addrbuf, addrlen);
}
-#endif
+#endif /* HAVE_GETPEERNAME */
/* s.listen(n) method */
@@ -635,6 +617,8 @@ sock_listen(s, args)
if (!getintarg(args, &backlog))
return NULL;
BGN_SAVE
+ if (backlog < 1)
+ backlog = 1;
res = listen(s->sock_fd, backlog);
END_SAVE
if (res < 0)
@@ -755,8 +739,7 @@ sock_send(s, args)
END_SAVE
if (n < 0)
return socket_error();
- INCREF(None);
- return None;
+ return newintobject((long)n);
}
@@ -784,8 +767,7 @@ sock_sendto(s, args)
END_SAVE
if (n < 0)
return socket_error();
- INCREF(None);
- return None;
+ return newintobject((long)n);
}
@@ -813,27 +795,26 @@ sock_shutdown(s, args)
/* List of methods for socket objects */
static struct methodlist sock_methods[] = {
- {"accept", sock_accept},
- {"avail", sock_avail},
- {"allowbroadcast", sock_allowbroadcast},
- {"setsockopt", sock_setsockopt},
- {"getsockopt", sock_getsockopt},
- {"bind", sock_bind},
- {"close", sock_close},
- {"connect", sock_connect},
- {"fileno", sock_fileno},
- {"getsockname", sock_getsockname},
-#ifndef NO_GETPEERNAME
- {"getpeername", sock_getpeername},
+ {"accept", (method)sock_accept},
+ {"allowbroadcast", (method)sock_allowbroadcast},
+ {"setsockopt", (method)sock_setsockopt},
+ {"getsockopt", (method)sock_getsockopt},
+ {"bind", (method)sock_bind},
+ {"close", (method)sock_close},
+ {"connect", (method)sock_connect},
+ {"fileno", (method)sock_fileno},
+ {"getsockname", (method)sock_getsockname},
+#ifdef HAVE_GETPEERNAME
+ {"getpeername", (method)sock_getpeername},
#endif
- {"listen", sock_listen},
- {"makefile", sock_makefile},
- {"recv", sock_recv},
- {"recvfrom", sock_recvfrom},
- {"send", sock_send},
- {"sendto", sock_sendto},
- {"shutdown", sock_shutdown},
- {NULL, NULL} /* sentinel */
+ {"listen", (method)sock_listen},
+ {"makefile", (method)sock_makefile},
+ {"recv", (method)sock_recv},
+ {"recvfrom", (method)sock_recvfrom},
+ {"send", (method)sock_send},
+ {"sendto", (method)sock_sendto},
+ {"shutdown", (method)sock_shutdown},
+ {NULL, NULL} /* sentinel */
};
@@ -860,19 +841,17 @@ sock_getattr(s, name)
}
-/* Type object for socket objects.
- XXX This should be static, but some compilers don't grok the
- XXX forward reference to it in that case... */
+/* Type object for socket objects. */
-typeobject Socktype = {
+static typeobject Socktype = {
OB_HEAD_INIT(&Typetype)
0,
"socket",
sizeof(sockobject),
0,
- sock_dealloc, /*tp_dealloc*/
+ (destructor)sock_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- sock_getattr, /*tp_getattr*/
+ (getattrfunc)sock_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -1061,7 +1040,9 @@ initsocket()
if (SocketError == NULL || dictinsert(d, "error", SocketError) != 0)
fatal("can't define socket.error");
insint(d, "AF_INET", AF_INET);
+#ifdef AF_UNIX
insint(d, "AF_UNIX", AF_UNIX);
+#endif /* AF_UNIX */
insint(d, "SOCK_STREAM", SOCK_STREAM);
insint(d, "SOCK_DGRAM", SOCK_DGRAM);
insint(d, "SOCK_RAW", SOCK_RAW);
diff --git a/Modules/stdwinmodule.c b/Modules/stdwinmodule.c
index fc81cff..2342527 100644
--- a/Modules/stdwinmodule.c
+++ b/Modules/stdwinmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -75,7 +75,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define HAVE_BITMAPS
#endif /* !macintosh */
-#ifdef USE_THREAD
+#ifdef WITH_THREAD
#include "thread.h"
@@ -113,7 +113,7 @@ typedef struct {
object *w_attr; /* Attributes dictionary */
} windowobject;
-extern typeobject Windowtype; /* Really static, forward */
+staticforward typeobject Windowtype;
#define is_windowobject(wp) ((wp)->ob_type == &Windowtype)
@@ -124,7 +124,7 @@ typedef struct {
object *m_attr; /* Attributes dictionary */
} menuobject;
-extern typeobject Menutype; /* Really static, forward */
+staticforward typeobject Menutype;
#define is_menuobject(mp) ((mp)->ob_type == &Menutype)
@@ -134,7 +134,7 @@ typedef struct {
object *b_attr; /* Attributes dictionary */
} bitmapobject;
-extern typeobject Bitmaptype; /* Really static, forward */
+staticforward typeobject Bitmaptype;
#define is_bitmapobject(mp) ((mp)->ob_type == &Bitmaptype)
@@ -730,44 +730,44 @@ drawing_bitmap(self, args)
static struct methodlist drawing_methods[] = {
#ifdef HAVE_BITMAPS
- {"bitmap", drawing_bitmap},
+ {"bitmap", (method)drawing_bitmap},
#endif
- {"box", drawing_box},
- {"circle", drawing_circle},
- {"cliprect", drawing_cliprect},
- {"close", drawing_close},
- {"elarc", drawing_elarc},
- {"enddrawing", drawing_close},
- {"erase", drawing_erase},
- {"fillcircle", drawing_fillcircle},
- {"fillelarc", drawing_fillelarc},
- {"fillpoly", drawing_fillpoly},
- {"invert", drawing_invert},
- {"line", drawing_line},
- {"noclip", drawing_noclip},
- {"paint", drawing_paint},
- {"poly", drawing_poly},
- {"shade", drawing_shade},
- {"text", drawing_text},
- {"xorcircle", drawing_xorcircle},
- {"xorelarc", drawing_xorelarc},
- {"xorline", drawing_xorline},
- {"xorpoly", drawing_xorpoly},
+ {"box", (method)drawing_box},
+ {"circle", (method)drawing_circle},
+ {"cliprect", (method)drawing_cliprect},
+ {"close", (method)drawing_close},
+ {"elarc", (method)drawing_elarc},
+ {"enddrawing", (method)drawing_close},
+ {"erase", (method)drawing_erase},
+ {"fillcircle", (method)drawing_fillcircle},
+ {"fillelarc", (method)drawing_fillelarc},
+ {"fillpoly", (method)drawing_fillpoly},
+ {"invert", (method)drawing_invert},
+ {"line", (method)drawing_line},
+ {"noclip", (method)drawing_noclip},
+ {"paint", (method)drawing_paint},
+ {"poly", (method)drawing_poly},
+ {"shade", (method)drawing_shade},
+ {"text", (method)drawing_text},
+ {"xorcircle", (method)drawing_xorcircle},
+ {"xorelarc", (method)drawing_xorelarc},
+ {"xorline", (method)drawing_xorline},
+ {"xorpoly", (method)drawing_xorpoly},
/* Text measuring methods: */
- {"baseline", drawing_baseline},
- {"lineheight", drawing_lineheight},
- {"textbreak", drawing_textbreak},
- {"textwidth", drawing_textwidth},
+ {"baseline", (method)drawing_baseline},
+ {"lineheight", (method)drawing_lineheight},
+ {"textbreak", (method)drawing_textbreak},
+ {"textwidth", (method)drawing_textwidth},
/* Font setting methods: */
- {"setfont", drawing_setfont},
+ {"setfont", (method)drawing_setfont},
/* Color methods: */
- {"getbgcolor", drawing_getbgcolor},
- {"getfgcolor", drawing_getfgcolor},
- {"setbgcolor", drawing_setbgcolor},
- {"setfgcolor", drawing_setfgcolor},
+ {"getbgcolor", (method)drawing_getbgcolor},
+ {"getfgcolor", (method)drawing_getfgcolor},
+ {"setbgcolor", (method)drawing_setbgcolor},
+ {"setfgcolor", (method)drawing_setfgcolor},
{NULL, NULL} /* sentinel */
};
@@ -791,9 +791,9 @@ typeobject Drawingtype = {
sizeof(drawingobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- drawing_dealloc, /*tp_dealloc*/
+ (destructor)drawing_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- drawing_getattr, /*tp_getattr*/
+ (getattrfunc)drawing_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -809,7 +809,7 @@ typedef struct {
object *t_attr; /* Attributes dictionary */
} textobject;
-extern typeobject Texttype; /* Really static, forward */
+staticforward typeobject Texttype;
static textobject *
newtextobject(wp, left, top, right, bottom)
@@ -1073,20 +1073,20 @@ text_setview(self, args)
}
static struct methodlist text_methods[] = {
- {"arrow", text_arrow},
- {"close", text_close},
- {"draw", text_draw},
- {"event", text_event},
- {"getfocus", text_getfocus},
- {"getfocustext",text_getfocustext},
- {"getrect", text_getrect},
- {"gettext", text_gettext},
- {"move", text_move},
- {"replace", text_replace},
- {"setactive", text_setactive},
- {"setfocus", text_setfocus},
- {"settext", text_settext},
- {"setview", text_setview},
+ {"arrow", (method)text_arrow},
+ {"close", (method)text_close},
+ {"draw", (method)text_draw},
+ {"event", (method)text_event},
+ {"getfocus", (method)text_getfocus},
+ {"getfocustext",(method)text_getfocustext},
+ {"getrect", (method)text_getrect},
+ {"gettext", (method)text_gettext},
+ {"move", (method)text_move},
+ {"replace", (method)text_replace},
+ {"setactive", (method)text_setactive},
+ {"setfocus", (method)text_setfocus},
+ {"settext", (method)text_settext},
+ {"setview", (method)text_setview},
{NULL, NULL} /* sentinel */
};
@@ -1137,17 +1137,17 @@ text_setattr(tp, name, v)
return dictinsert(tp->t_attr, name, v);
}
-typeobject Texttype = {
+static typeobject Texttype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"textedit", /*tp_name*/
sizeof(textobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- text_dealloc, /*tp_dealloc*/
+ (destructor)text_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- text_getattr, /*tp_getattr*/
- text_setattr, /*tp_setattr*/
+ (getattrfunc)text_getattr, /*tp_getattr*/
+ (setattrfunc)text_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
};
@@ -1289,11 +1289,11 @@ menu_check(self, args)
}
static struct methodlist menu_methods[] = {
- {"additem", menu_additem},
- {"setitem", menu_setitem},
- {"enable", menu_enable},
- {"check", menu_check},
- {"close", menu_close},
+ {"additem", (method)menu_additem},
+ {"setitem", (method)menu_setitem},
+ {"enable", (method)menu_enable},
+ {"check", (method)menu_check},
+ {"close", (method)menu_close},
{NULL, NULL} /* sentinel */
};
@@ -1344,17 +1344,17 @@ menu_setattr(mp, name, v)
return dictinsert(mp->m_attr, name, v);
}
-typeobject Menutype = {
+static typeobject Menutype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"menu", /*tp_name*/
sizeof(menuobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- menu_dealloc, /*tp_dealloc*/
+ (destructor)menu_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- menu_getattr, /*tp_getattr*/
- menu_setattr, /*tp_setattr*/
+ (getattrfunc)menu_getattr, /*tp_getattr*/
+ (setattrfunc)menu_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
};
@@ -1447,10 +1447,10 @@ bitmap_getsize(self, args)
}
static struct methodlist bitmap_methods[] = {
- {"close", bitmap_close},
- {"getsize", bitmap_getsize},
- {"getbit", bitmap_getbit},
- {"setbit", bitmap_setbit},
+ {"close", (method)bitmap_close},
+ {"getsize", (method)bitmap_getsize},
+ {"getbit", (method)bitmap_getbit},
+ {"setbit", (method)bitmap_setbit},
{NULL, NULL} /* sentinel */
};
@@ -1501,17 +1501,17 @@ bitmap_setattr(bp, name, v)
return dictinsert(bp->b_attr, name, v);
}
-typeobject Bitmaptype = {
+static typeobject Bitmaptype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"bitmap", /*tp_name*/
sizeof(bitmapobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- bitmap_dealloc, /*tp_dealloc*/
+ (destructor)bitmap_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- bitmap_getattr, /*tp_getattr*/
- bitmap_setattr, /*tp_setattr*/
+ (getattrfunc)bitmap_getattr, /*tp_getattr*/
+ (setattrfunc)bitmap_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
};
@@ -1852,29 +1852,29 @@ window_getxwindowid(self, args)
#endif
static struct methodlist window_methods[] = {
- {"begindrawing",window_begindrawing},
- {"change", window_change},
- {"close", window_close},
- {"getdocsize", window_getdocsize},
- {"getorigin", window_getorigin},
- {"gettitle", window_gettitle},
- {"getwinpos", window_getwinpos},
- {"getwinsize", window_getwinsize},
- {"menucreate", window_menucreate},
- {"scroll", window_scroll},
- {"setactive", window_setactive},
- {"setdocsize", window_setdocsize},
- {"setorigin", window_setorigin},
- {"setselection",window_setselection},
- {"settimer", window_settimer},
- {"settitle", window_settitle},
- {"setwincursor",window_setwincursor},
- {"setwinpos", window_setwinpos},
- {"setwinsize", window_setwinsize},
- {"show", window_show},
- {"textcreate", window_textcreate},
+ {"begindrawing",(method)window_begindrawing},
+ {"change", (method)window_change},
+ {"close", (method)window_close},
+ {"getdocsize", (method)window_getdocsize},
+ {"getorigin", (method)window_getorigin},
+ {"gettitle", (method)window_gettitle},
+ {"getwinpos", (method)window_getwinpos},
+ {"getwinsize", (method)window_getwinsize},
+ {"menucreate", (method)window_menucreate},
+ {"scroll", (method)window_scroll},
+ {"setactive", (method)window_setactive},
+ {"setdocsize", (method)window_setdocsize},
+ {"setorigin", (method)window_setorigin},
+ {"setselection",(method)window_setselection},
+ {"settimer", (method)window_settimer},
+ {"settitle", (method)window_settitle},
+ {"setwincursor",(method)window_setwincursor},
+ {"setwinpos", (method)window_setwinpos},
+ {"setwinsize", (method)window_setwinsize},
+ {"show", (method)window_show},
+ {"textcreate", (method)window_textcreate},
#ifdef CWI_HACKS
- {"getxwindowid",window_getxwindowid},
+ {"getxwindowid",(method)window_getxwindowid},
#endif
{NULL, NULL} /* sentinel */
};
@@ -1926,17 +1926,17 @@ window_setattr(wp, name, v)
return dictinsert(wp->w_attr, name, v);
}
-typeobject Windowtype = {
+static typeobject Windowtype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"window", /*tp_name*/
sizeof(windowobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- window_dealloc, /*tp_dealloc*/
+ (destructor)window_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- window_getattr, /*tp_getattr*/
- window_setattr, /*tp_setattr*/
+ (getattrfunc)window_getattr, /*tp_getattr*/
+ (setattrfunc)window_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
};
@@ -2515,23 +2515,24 @@ static struct methodlist stdwin_methods[] = {
{"setdefwinsize", stdwin_setdefwinsize},
/* Text measuring methods borrow code from drawing objects: */
- {"baseline", drawing_baseline},
- {"lineheight", drawing_lineheight},
- {"textbreak", drawing_textbreak},
- {"textwidth", drawing_textwidth},
+ {"baseline", (method)drawing_baseline},
+ {"lineheight", (method)drawing_lineheight},
+ {"textbreak", (method)drawing_textbreak},
+ {"textwidth", (method)drawing_textwidth},
/* Same for font setting methods: */
- {"setfont", drawing_setfont},
+ {"setfont", (method)drawing_setfont},
/* Same for color setting/getting methods: */
- {"getbgcolor", drawing_getbgcolor},
- {"getfgcolor", drawing_getfgcolor},
- {"setbgcolor", drawing_setbgcolor},
- {"setfgcolor", drawing_setfgcolor},
+ {"getbgcolor", (method)drawing_getbgcolor},
+ {"getfgcolor", (method)drawing_getfgcolor},
+ {"setbgcolor", (method)drawing_setbgcolor},
+ {"setfgcolor", (method)drawing_setfgcolor},
{NULL, NULL} /* sentinel */
};
+#ifndef macintosh
static int
checkstringlist(args, ps, pn)
object *args;
@@ -2592,6 +2593,7 @@ putbackstringlist(list, s, n)
DECREF(newlist);
return 1;
}
+#endif /* macintosh */
void
initstdwin()
@@ -2601,6 +2603,9 @@ initstdwin()
char buf[1000];
if (!inited) {
+#ifdef macintosh
+ winit();
+#else
int argc = 0;
char **argv = NULL;
object *sys_argv = sysget("argv");
@@ -2625,6 +2630,7 @@ initstdwin()
if (!putbackstringlist(sys_argv, argv, argc))
err_clear();
}
+#endif
inited = 1;
}
m = initmodule("stdwin", stdwin_methods);
@@ -2634,7 +2640,7 @@ initstdwin()
StdwinError = newstringobject("stdwin.error");
if (StdwinError == NULL || dictinsert(d, "error", StdwinError) != 0)
fatal("can't define stdwin.error");
-#ifdef USE_THREAD
+#ifdef WITH_THREAD
StdwinLock = allocate_lock();
if (StdwinLock == NULL)
fatal("can't allocate stdwin lock");
diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c
index fe67ca0..c980272 100644
--- a/Modules/stropmodule.c
+++ b/Modules/stropmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -31,6 +31,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* XXX This file assumes that the <ctype.h> is*() functions
XXX are defined for all 8-bit characters! */
+#include <errno.h>
+
static object *
strop_split(self, args)
@@ -236,7 +238,7 @@ strop_rindex(self, args)
object *args;
{
char *s, *sub;
- int len, n, i;
+ int len, n, i, j;
if (getargs(args, "(s#s#i)", &s, &len, &sub, &n, &i)) {
if (i < 0)
@@ -250,16 +252,16 @@ strop_rindex(self, args)
err_clear();
if (!getargs(args, "(s#s#)", &s, &len, &sub, &n))
return NULL;
- i = len;
+ i = 0;
}
if (n == 0)
return newintobject((long)i);
- for (i -= n; i >= 0; --i)
- if (s[i] == sub[0] &&
- (n == 1 || strncmp(&s[i+1], &sub[1], n-1) == 0))
- return newintobject((long)i);
+ for (j = len-n; j >= i; --j)
+ if (s[j] == sub[0] &&
+ (n == 1 || strncmp(&s[j+1], &sub[1], n-1) == 0))
+ return newintobject((long)j);
err_setstr(ValueError, "substring not found");
return NULL;
@@ -408,9 +410,108 @@ strop_swapcase(self, args)
}
+static object *
+strop_atoi(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ extern long mystrtol PROTO((const char *, char **, int));
+ extern unsigned long mystrtoul PROTO((const char *, char **, int));
+ char *s, *end;
+ int base = 10;
+ long x;
+
+ if (args != NULL && is_tupleobject(args)) {
+ if (!getargs(args, "(si)", &s, &base))
+ return NULL;
+ if (base != 0 && base < 2 || base > 36) {
+ err_setstr(ValueError, "invalid base for atoi()");
+ return NULL;
+ }
+ }
+ else if (!getargs(args, "s", &s))
+ return NULL;
+ errno = 0;
+ if (base == 0 && s[0] == '0')
+ x = (long) mystrtoul(s, &end, base);
+ else
+ x = mystrtol(s, &end, base);
+ if (*end != '\0') {
+ err_setstr(ValueError, "invalid literal for atoi()");
+ return NULL;
+ }
+ else if (errno != 0) {
+ err_setstr(OverflowError, "atoi() literal too large");
+ return NULL;
+ }
+ return newintobject(x);
+}
+
+
+static object *
+strop_atol(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ char *s, *end;
+ int base = 10;
+ object *x;
+
+ if (args != NULL && is_tupleobject(args)) {
+ if (!getargs(args, "(si)", &s, &base))
+ return NULL;
+ if (base != 0 && base < 2 || base > 36) {
+ err_setstr(ValueError, "invalid base for atol()");
+ return NULL;
+ }
+ }
+ else if (!getargs(args, "s", &s))
+ return NULL;
+ x = long_escan(s, &end, base);
+ if (x == NULL)
+ return NULL;
+ if (base == 0 && (*end == 'l' || *end == 'L'))
+ end++;
+ if (*end != '\0') {
+ err_setstr(ValueError, "invalid literal for atol()");
+ DECREF(x);
+ return NULL;
+ }
+ return x;
+}
+
+
+static object *
+strop_atof(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ extern double strtod PROTO((const char *, char **));
+ char *s, *end;
+ double x;
+
+ if (!getargs(args, "s", &s))
+ return NULL;
+ errno = 0;
+ x = strtod(s, &end);
+ if (*end != '\0') {
+ err_setstr(ValueError, "invalid literal for atof()");
+ return NULL;
+ }
+ else if (errno != 0) {
+ err_setstr(OverflowError, "atof() literal too large");
+ return NULL;
+ }
+ return newfloatobject(x);
+}
+
+
/* List of functions defined in the module */
static struct methodlist strop_methods[] = {
+ {"atof", strop_atof},
+ {"atoi", strop_atoi},
+ {"atol", strop_atol},
{"index", strop_index},
{"joinfields", strop_joinfields},
{"lower", strop_lower},
diff --git a/Modules/structmodule.c b/Modules/structmodule.c
index 03e8f18..7d8815e 100644
--- a/Modules/structmodule.c
+++ b/Modules/structmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
index 5bd7249..a2f3869 100644
--- a/Modules/sunaudiodev.c
+++ b/Modules/sunaudiodev.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,10 +28,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "structmember.h"
+#ifdef HAVE_SYS_AUDIOIO_H
+#define SOLARIS
+#endif
+
#include <stropts.h>
#include <sys/ioctl.h>
#ifdef SOLARIS
-#include <multimedia/libaudio.h>
+#include <sys/audioio.h>
#else
#include <sun/audioio.h>
#endif
@@ -52,8 +56,8 @@ typedef struct {
audio_info_t ai;
} sadstatusobject;
-extern typeobject Sadtype; /* Really static, forward */
-extern typeobject Sadstatustype; /* Really static, forward */
+staticforward typeobject Sadtype;
+staticforward typeobject Sadstatustype;
static sadstatusobject *sads_alloc(); /* Forward */
static object *SunAudioError;
@@ -427,17 +431,17 @@ sads_setattr(xp, name, v)
static typeobject Sadtype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "sun_audio_device", /*tp_name*/
- sizeof(sadobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "sun_audio_device", /*tp_name*/
+ sizeof(sadobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- sad_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- sad_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)sad_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)sad_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
static typeobject Sadstatustype = {
@@ -447,12 +451,12 @@ static typeobject Sadstatustype = {
sizeof(sadstatusobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- sads_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- sads_getattr, /*tp_getattr*/
- sads_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)sads_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)sads_getattr, /*tp_getattr*/
+ (setattrfunc)sads_setattr, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
/* ------------------------------------------------------------------- */
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index d3fda30..dad2414 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -1,5 +1,5 @@
/**********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -227,7 +227,7 @@ svc_lrectwrite(self, args)
#endif
static object *
-writefile(self, args)
+svc_writefile(self, args)
captureobject *self;
object *args;
{
@@ -276,19 +276,19 @@ svc_FindVisibleRegion(self, args)
}
static struct methodlist capture_methods[] = {
- {"YUVtoRGB", svc_YUVtoRGB},
- {"RGB8toRGB32", svc_RGB8toRGB32},
- {"InterleaveFields", svc_InterleaveFields},
- {"UnlockCaptureData", svc_UnlockCaptureData},
- {"FindVisibleRegion", svc_FindVisibleRegion},
- {"GetFields", svc_GetFields},
- {"YUVtoYUV422DC", svc_YUVtoYUV422DC},
- {"YUVtoYUV422DC_quarter",svc_YUVtoYUV422DC_quarter},
- {"YUVtoYUV422DC_sixteenth",svc_YUVtoYUV422DC_sixteenth},
+ {"YUVtoRGB", (method)svc_YUVtoRGB},
+ {"RGB8toRGB32", (method)svc_RGB8toRGB32},
+ {"InterleaveFields", (method)svc_InterleaveFields},
+ {"UnlockCaptureData", (method)svc_UnlockCaptureData},
+ {"FindVisibleRegion", (method)svc_FindVisibleRegion},
+ {"GetFields", (method)svc_GetFields},
+ {"YUVtoYUV422DC", (method)svc_YUVtoYUV422DC},
+ {"YUVtoYUV422DC_quarter",(method)svc_YUVtoYUV422DC_quarter},
+ {"YUVtoYUV422DC_sixteenth",(method)svc_YUVtoYUV422DC_sixteenth},
#ifdef USE_GL
- {"lrectwrite", svc_lrectwrite},
+ {"lrectwrite", (method)svc_lrectwrite},
#endif
- {"writefile", writefile},
+ {"writefile", (method)svc_writefile},
{NULL, NULL} /* sentinel */
};
@@ -316,17 +316,17 @@ capture_getattr(self, name)
typeobject Capturetype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "capture", /*tp_name*/
- sizeof(captureobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "capture", /*tp_name*/
+ sizeof(captureobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- capture_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- capture_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)capture_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)capture_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
static object *
@@ -835,25 +835,25 @@ sv_SetParam(self, args)
}
static struct methodlist svideo_methods[] = {
- {"BindGLWindow", sv_BindGLWindow},
- {"EndContinuousCapture",sv_EndContinuousCapture},
- {"IsVideoDisplayed", sv_IsVideoDisplayed},
- {"OutputOffset", sv_OutputOffset},
- {"PutFrame", sv_PutFrame},
- {"QuerySize", sv_QuerySize},
- {"SetSize", sv_SetSize},
- {"SetStdDefaults", sv_SetStdDefaults},
- {"UseExclusive", sv_UseExclusive},
- {"WindowOffset", sv_WindowOffset},
- {"InitContinuousCapture",sv_InitContinuousCapture},
- {"CaptureBurst", sv_CaptureBurst},
- {"CaptureOneFrame", sv_CaptureOneFrame},
- {"GetCaptureData", sv_GetCaptureData},
- {"CloseVideo", sv_CloseVideo},
- {"LoadMap", sv_LoadMap},
- {"GetParam", sv_GetParam},
- {"GetParamRange", sv_GetParamRange},
- {"SetParam", sv_SetParam},
+ {"BindGLWindow", (method)sv_BindGLWindow},
+ {"EndContinuousCapture",(method)sv_EndContinuousCapture},
+ {"IsVideoDisplayed", (method)sv_IsVideoDisplayed},
+ {"OutputOffset", (method)sv_OutputOffset},
+ {"PutFrame", (method)sv_PutFrame},
+ {"QuerySize", (method)sv_QuerySize},
+ {"SetSize", (method)sv_SetSize},
+ {"SetStdDefaults", (method)sv_SetStdDefaults},
+ {"UseExclusive", (method)sv_UseExclusive},
+ {"WindowOffset", (method)sv_WindowOffset},
+ {"InitContinuousCapture",(method)sv_InitContinuousCapture},
+ {"CaptureBurst", (method)sv_CaptureBurst},
+ {"CaptureOneFrame", (method)sv_CaptureOneFrame},
+ {"GetCaptureData", (method)sv_GetCaptureData},
+ {"CloseVideo", (method)sv_CloseVideo},
+ {"LoadMap", (method)sv_LoadMap},
+ {"GetParam", (method)sv_GetParam},
+ {"GetParamRange", (method)sv_GetParamRange},
+ {"SetParam", (method)sv_SetParam},
{NULL, NULL} /* sentinel */
};
@@ -930,9 +930,9 @@ typeobject Svtype = {
sizeof(svobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- svideo_dealloc, /*tp_dealloc*/
+ (destructor)svideo_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- svideo_getattr, /*tp_getattr*/
+ (getattrfunc)svideo_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
@@ -973,10 +973,10 @@ sv_OpenVideo(self, args)
}
static struct methodlist sv_methods[] = {
- {"InterleaveFields", sv_InterleaveFields},
- {"RGB8toRGB32", sv_RGB8toRGB32},
- {"YUVtoRGB", sv_YUVtoRGB},
- {"OpenVideo", sv_OpenVideo},
+ {"InterleaveFields", (method)sv_InterleaveFields},
+ {"RGB8toRGB32", (method)sv_RGB8toRGB32},
+ {"YUVtoRGB", (method)sv_YUVtoRGB},
+ {"OpenVideo", (method)sv_OpenVideo},
{NULL, NULL} /* Sentinel */
};
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 40169a3..301f060 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -29,9 +29,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "ceval.h"
+#ifndef WITH_THREAD
+Error! The rest of Python is not compiled with thread support.
+Rerun configure, adding a --with-thread option.
+#endif
+
#include "thread.h"
-int threads_started = 0;
+extern int threads_started;
static object *ThreadError;
@@ -43,7 +48,7 @@ typedef struct {
type_lock lock_lock;
} lockobject;
-extern typeobject Locktype; /* Really static, forward */
+staticforward typeobject Locktype;
#define is_lockobject(v) ((v)->ob_type == &Locktype)
@@ -147,12 +152,12 @@ lock_locked_lock(self, args)
}
static struct methodlist lock_methods[] = {
- {"acquire_lock", lock_acquire_lock},
- {"acquire", lock_acquire_lock},
- {"release_lock", lock_release_lock},
- {"release", lock_release_lock},
- {"locked_lock", lock_locked_lock},
- {"locked", lock_locked_lock},
+ {"acquire_lock", (method)lock_acquire_lock},
+ {"acquire", (method)lock_acquire_lock},
+ {"release_lock", (method)lock_release_lock},
+ {"release", (method)lock_release_lock},
+ {"locked_lock", (method)lock_locked_lock},
+ {"locked", (method)lock_locked_lock},
{NULL, NULL} /* sentinel */
};
@@ -166,17 +171,17 @@ lock_getattr(self, name)
static typeobject Locktype = {
OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "lock", /*tp_name*/
- sizeof(lockobject), /*tp_size*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "lock", /*tp_name*/
+ sizeof(lockobject), /*tp_size*/
+ 0, /*tp_itemsize*/
/* methods */
- lock_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- lock_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
+ (destructor)lock_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc)lock_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
};
@@ -238,6 +243,7 @@ thread_exit_thread(self, args)
for (;;) { } /* Should not be reached */
}
+#ifndef NO_EXIT_PROG
static object *
thread_exit_prog(self, args)
object *self; /* Not used */
@@ -249,6 +255,7 @@ thread_exit_prog(self, args)
goaway(sts); /* Calls exit_prog(sts) or _exit_prog(sts) */
for (;;) { } /* Should not be reached */
}
+#endif
static object *
thread_allocate_lock(self, args)
@@ -260,14 +267,33 @@ thread_allocate_lock(self, args)
return (object *) newlockobject();
}
+static object *
+thread_get_ident(self, args)
+ object *self; /* Not used */
+ object *args;
+{
+ long ident;
+ if (!getnoarg(args))
+ return NULL;
+ ident = get_thread_ident();
+ if (ident == -1) {
+ err_setstr(ThreadError, "no current thread ident");
+ return NULL;
+ }
+ return newintobject(ident);
+}
+
static struct methodlist thread_methods[] = {
- {"start_new_thread", thread_start_new_thread},
- {"start_new", thread_start_new_thread},
- {"allocate_lock", thread_allocate_lock},
- {"allocate", thread_allocate_lock},
- {"exit_thread", thread_exit_thread},
- {"exit", thread_exit_thread},
- {"exit_prog", thread_exit_prog},
+ {"start_new_thread", (method)thread_start_new_thread},
+ {"start_new", (method)thread_start_new_thread},
+ {"allocate_lock", (method)thread_allocate_lock},
+ {"allocate", (method)thread_allocate_lock},
+ {"exit_thread", (method)thread_exit_thread},
+ {"exit", (method)thread_exit_thread},
+ {"get_ident", (method)thread_get_ident},
+#ifndef NO_EXIT_PROG
+ {"exit_prog", (method)thread_exit_prog},
+#endif
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 5406907..d35eba8 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,210 +28,94 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "modsupport.h"
#include "ceval.h"
-#include "sigtype.h"
-
-#include <signal.h>
-#include <setjmp.h>
-
-#ifdef BSD_TIME
-#define HAVE_GETTIMEOFDAY
-#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
+#ifdef macintosh
+#include <time.h>
+#else
+#include <sys/types.h>
#endif
-#ifdef macintosh
-#define NO_UNISTD
+#ifdef QUICKWIN
+#include <io.h>
#endif
-#ifndef NO_UNISTD
+#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
-/* What happens here is not trivial.
- The BSD_TIME code needs <sys/time.h> (for struct timeval).
- The rest of the code needs only time_t, except some MS-DOS
- code which needs clock_t as well.
- Standard C says that time_t is defined in <time.h>, and
- does not have <sys/types.h>; THINK C agrees (MS-DOS too?).
- What's worse, in pure 4.3 BSD, older SunOS versions, and
- probably everything derived from BSD, you can't #include
- both <time.h> and <sys/time.h> in the same file, since
- <sys/time.h> includes <time.h> without any protection,
- and <time.h> contains a typedef, which can't be parsed twice!
- So on traditional UNIX systems we include <sys/types.h>
- and <sys/time.h> and hope this implies <time.h> and time_t,
- while on other systems, including conforming Standard C
- systems (where 'unix' can't be defined), we rely on <time.h>.
- Still one problem: BSD_TIME won't work with strict Standard C...
-*/
-
-#ifdef unix
-#include <sys/types.h>
-#include <sys/time.h> /* Implies <time.h> everywhere, as far as I know */
-#else /* !unix */
-#include <time.h>
-#endif /* !unix */
-
-#ifdef SYSV
-#if defined(sun) && defined(__STDC__)
-/* Temporary hack for Solaris 2. */
-#define _timezone timezone
-#define _altzone altzone
-#define _daylight daylight
-#define _tzname tzname
+#ifdef HAVE_SELECT
+#include "myselect.h"
+#else
+#include "mytime.h"
#endif
-/* Access timezone stuff */
-#ifdef OLDTZ /* ANSI prepends underscore to these */
-#define _timezone timezone /* seconds to be added to GMT */
-#define _altzone 0 /* _timezone if daylight saving time */
-#define _daylight 0 /* if zero, _altzone is not available*/
-#define _tzname tzname /* Name of timezone and altzone */
+
+#ifdef HAVE_FTIME
+#include <sys/timeb.h>
#endif
-#ifdef NOALTTZ /* if system doesn't support alt tz */
-#undef _daylight
-#undef _altzone
-#define _daylight 0
-#define _altzone 0
+
+#ifdef _M_IX86
+#include <windows.h>
+#define timezone _timezone
#endif
-#endif /* SYSV */
/* Forward declarations */
-static void floatsleep PROTO((double));
-static long millitimer PROTO((void));
-
-/* Time methods */
+static int floatsleep PROTO((double));
+static double floattime PROTO(());
static object *
time_time(self, args)
object *self;
object *args;
{
-#ifdef HAVE_GETTIMEOFDAY
- struct timeval t;
- struct timezone tz;
+ double secs;
if (!getnoarg(args))
return NULL;
- if (gettimeofday(&t, &tz) != 0) {
+ secs = floattime();
+ if (secs == 0.0) {
err_errno(IOError);
return NULL;
}
- return newfloatobject(t.tv_sec*1.0 + t.tv_usec*0.000001);
-#else /* !HAVE_GETTIMEOFDAY */
- time_t secs;
- if (!getnoarg(args))
- return NULL;
- time(&secs);
-#ifdef macintosh
-/* The Mac epoch is 1904, while UNIX uses 1970; Python prefers 1970 */
-/* Moreover, the Mac returns local time. This we cannot fix... */
-#define TIMEDIFF ((time_t) \
- (((1970-1904)*365L + (1970-1904)/4) * 24 * 3600))
- secs -= TIMEDIFF;
-#endif
- return newfloatobject((double)secs);
-#endif /* !HAVE_GETTIMEOFDAY */
+ return newfloatobject(secs);
}
-static jmp_buf sleep_intr;
+#ifdef HAVE_CLOCK
-/* ARGSUSED */
-static void
-sleep_catcher(sig)
- int sig; /* Not used but required by interface */
-{
- longjmp(sleep_intr, 1);
-}
+#ifndef CLOCKS_PER_SEC
+#define CLOCKS_PER_SEC 1000000
+#endif
static object *
-time_sleep(self, args)
+time_clock(self, args)
object *self;
object *args;
{
- double secs;
- SIGTYPE (*sigsave)() = 0; /* Initialized to shut lint up */
- if (!getargs(args, "d", &secs))
- return NULL;
- BGN_SAVE
- if (setjmp(sleep_intr)) {
- RET_SAVE
- signal(SIGINT, sigsave);
- err_set(KeyboardInterrupt);
+ if (!getnoarg(args))
return NULL;
- }
- sigsave = signal(SIGINT, SIG_IGN);
- if (sigsave != (SIGTYPE (*)()) SIG_IGN)
- signal(SIGINT, sleep_catcher);
- floatsleep(secs);
- END_SAVE
- signal(SIGINT, sigsave);
- INCREF(None);
- return None;
+ return newfloatobject(((double)clock()) / CLOCKS_PER_SEC);
}
-
-#ifdef macintosh
-#define DO_MILLI
-#endif
-
-#ifdef AMOEBA
-#define DO_MILLI
-extern long sys_milli();
-#define millitimer sys_milli
-#endif /* AMOEBA */
-
-#ifdef BSD_TIME
-#define DO_MILLI
-#endif /* BSD_TIME */
-
-#ifdef MSDOS
-#define DO_MILLI
-#endif
-
-#ifdef DO_MILLI
+#endif /* HAVE_CLOCK */
static object *
-time_millisleep(self, args)
+time_sleep(self, args)
object *self;
object *args;
{
- long msecs;
- SIGTYPE (*sigsave)();
- if (!getlongarg(args, &msecs))
+ double secs;
+ if (!getargs(args, "d", &secs))
return NULL;
BGN_SAVE
- if (setjmp(sleep_intr)) {
+ if (floatsleep(secs) != 0) {
RET_SAVE
- signal(SIGINT, sigsave);
- err_set(KeyboardInterrupt);
return NULL;
}
- sigsave = signal(SIGINT, SIG_IGN);
- if (sigsave != (SIGTYPE (*)()) SIG_IGN)
- signal(SIGINT, sleep_catcher);
- floatsleep(msecs / 1000.0);
END_SAVE
- signal(SIGINT, sigsave);
INCREF(None);
return None;
}
static object *
-time_millitimer(self, args)
- object *self;
- object *args;
-{
- long msecs;
- if (!getnoarg(args))
- return NULL;
- msecs = millitimer();
- return newintobject(msecs);
-}
-
-#endif /* DO_MILLI */
-
-
-static object *
time_convert(when, function)
time_t when;
- struct tm * (*function) PROTO((time_t *));
+ struct tm * (*function) PROTO((const time_t *));
{
struct tm *p = function(&when);
return mkvalue("(iiiiiiiii)",
@@ -324,8 +208,6 @@ time_ctime(self, args)
return newstringobject(p);
}
-/* Some very old systems may not have mktime(). Comment it out then! */
-
static object *
time_mktime(self, args)
object *self;
@@ -338,12 +220,11 @@ time_mktime(self, args)
}
static struct methodlist time_methods[] = {
-#ifdef DO_MILLI
- {"millisleep", time_millisleep},
- {"millitimer", time_millitimer},
-#endif /* DO_MILLI */
- {"sleep", time_sleep},
{"time", time_time},
+#ifdef HAVE_CLOCK
+ {"clock", time_clock},
+#endif
+ {"sleep", time_sleep},
{"gmtime", time_gmtime},
{"localtime", time_localtime},
{"asctime", time_asctime},
@@ -352,26 +233,32 @@ static struct methodlist time_methods[] = {
{NULL, NULL} /* sentinel */
};
-
void
inittime()
{
object *m, *d;
m = initmodule("time", time_methods);
d = getmoduledict(m);
-#ifdef SYSV
+#ifdef HAVE_TZNAME
tzset();
- dictinsert(d, "timezone", newintobject((long)_timezone));
- dictinsert(d, "altzone", newintobject((long)_altzone));
- dictinsert(d, "daylight", newintobject((long)_daylight));
- dictinsert(d, "tzname", mkvalue("(zz)", _tzname[0], _tzname[1]));
-#else /* !SYSV */
+ dictinsert(d, "timezone", newintobject((long)timezone));
+#ifdef HAVE_ALTZONE
+ dictinsert(d, "altzone", newintobject((long)altzone));
+#else
+ dictinsert(d, "altzone", newintobject((long)timezone-3600));
+#endif
+ dictinsert(d, "daylight", newintobject((long)daylight));
+ dictinsert(d, "tzname", mkvalue("(zz)", tzname[0], tzname[1]));
+#else /* !HAVE_TZNAME */
+#if HAVE_TM_ZONE
{
#define YEAR ((time_t)((365 * 24 + 6) * 3600))
time_t t;
struct tm *p;
long winterzone, summerzone;
char wintername[10], summername[10];
+ /* XXX This won't work on the southern hemisphere.
+ XXX Anybody got a better idea? */
t = (time((time_t *)0) / YEAR) * YEAR;
p = localtime(&t);
winterzone = -p->tm_gmtoff;
@@ -389,68 +276,54 @@ inittime()
dictinsert(d, "tzname",
mkvalue("(zz)", wintername, summername));
}
-#endif /* !SYSV */
+#endif /* HAVE_TM_ZONE */
+#endif /* !HAVE_TZNAME */
}
-#ifdef macintosh
-
-#define MacTicks (* (long *)0x16A)
+/* Implement floattime() for various platforms */
-#ifdef THINK_C_3_0
-sleep(secs)
- int secs;
+static double
+floattime()
{
- register long deadline;
-
- deadline = MacTicks + mecs * 60;
- while (MacTicks < deadline) {
- if (intrcheck())
- sleep_catcher(SIGINT);
- }
-}
-#endif
-
-static void
-floatsleep(secs)
- double secs;
-{
- register long deadline;
-
- deadline = MacTicks + (long)(secs * 60.0);
- while (MacTicks < deadline) {
- if (intrcheck())
- sleep_catcher(SIGINT);
- }
-}
-
-static long
-millitimer()
-{
- return MacTicks * 50 / 3; /* MacTicks * 1000 / 60 */
+ /* There are three ways to get the time:
+ (1) gettimeofday() -- resolution in microseconds
+ (2) ftime() -- resolution in milliseconds
+ (3) time() -- resolution in seconds
+ In all cases the return value is a float in seconds.
+ Since on some systems (e.g. SCO ODT 3.0) gettimeofday() may
+ fail, so we fall back on ftime() or time().
+ Note: clock resolution does not imply clock accuracy! */
+#ifdef HAVE_GETTIMEOFDAY
+ {
+ struct timeval t;
+ if (gettimeofday(&t, (struct timezone *)NULL) == 0)
+ return (double)t.tv_sec + t.tv_usec*0.000001;
+ }
+#endif /* !HAVE_GETTIMEOFDAY */
+ {
+#ifdef HAVE_FTIME
+ struct timeb t;
+ ftime(&t);
+ return (double)t.time + t.millitm*0.001;
+#else /* !HAVE_FTIME */
+ time_t secs;
+ time(&secs);
+ return (double)secs;
+#endif /* !HAVE_FTIME */
+ }
}
-#endif /* macintosh */
+/* Implement floatsleep() for various platforms.
+ When interrupted (or when another error occurs), return -1 and
+ set an exception; else return 0. */
-#ifdef unix
-
-#ifdef BSD_TIME
-
-static long
-millitimer()
-{
- struct timeval t;
- struct timezone tz;
- if (gettimeofday(&t, &tz) != 0)
- return -1;
- return t.tv_sec*1000 + t.tv_usec/1000;
-}
-
-static void
+static int
floatsleep(secs)
double secs;
{
+#ifdef HAVE_SELECT
struct timeval t;
double frac;
extern double fmod PROTO((double, double));
@@ -459,51 +332,57 @@ floatsleep(secs)
secs = floor(secs);
t.tv_sec = (long)secs;
t.tv_usec = (long)(frac*1000000.0);
- (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
-}
-
-#else /* !BSD_TIME */
-
-static void
-floatsleep(secs)
- double secs;
-{
- sleep((int)secs);
-}
-
-#endif /* !BSD_TIME */
-
-#endif /* unix */
-
-
+ if (select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t) != 0) {
+ err_errno(IOError);
+ return -1;
+ }
+#else /* !HAVE_SELECT */
+#ifdef macintosh
+#define MacTicks (* (long *)0x16A)
+ long deadline;
+ deadline = MacTicks + (long)(secs * 60.0);
+ while (MacTicks < deadline) {
+ if (sigcheck())
+ return -1;
+ }
+#else /* !macintosh */
#ifdef MSDOS
-
-#ifndef CLOCKS_PER_SEC
-#define CLOCKS_PER_SEC 55 /* 54.945 msec per tick (18.2 HZ clock) */
+ struct timeb t1, t2;
+ double frac;
+ extern double fmod PROTO((double, double));
+ extern double floor PROTO((double));
+ if (secs <= 0.0)
+ return;
+ frac = fmod(secs, 1.0);
+ secs = floor(secs);
+ ftime(&t1);
+ t2.time = t1.time + (int)secs;
+ t2.millitm = t1.millitm + (int)(frac*1000.0);
+ while (t2.millitm >= 1000) {
+ t2.time++;
+ t2.millitm -= 1000;
+ }
+ for (;;) {
+#ifdef QUICKWIN
+ _wyield();
#endif
-
-static void
-floatsleep(secs)
- double secs;
-{
- delay(long(secs/1000.0));
-}
-
-static long
-millitimer()
-{
- clock_t ticks;
-
- ticks = clock(); /* ticks since program start */
- return ticks * CLOCKS_PER_SEC;/* XXX shouldn't this be different? */
-}
-
-floatsleep(secs)
- double secs;
-{
- clock_t t= clock( );
- while( (clock()-t)/CLOCKS_PER_SEC<secs )
- ;
+ if (sigcheck())
+ return -1;
+ ftime(&t1);
+ if (t1.time > t2.time ||
+ t1.time == t2.time && t1.millitm >= t2.millitm)
+ break;
+ }
+#else /* !MSDOS */
+#ifdef _M_IX86
+ /* XXX Can't interrupt this sleep */
+ Sleep((int)(secs*1000));
+#else /* _M_IX86 */
+ /* XXX Can't interrupt this sleep */
+ sleep((int)secs);
+#endif /* _M_IX86 */
+#endif /* !MSDOS */
+#endif /* !macintosh */
+#endif /* !HAVE_SELECT */
+ return 0;
}
-
-#endif /* MSDOS */
diff --git a/Modules/version.c b/Modules/version.c
deleted file mode 100644
index d71b59f..0000000
--- a/Modules/version.c
+++ /dev/null
@@ -1,396 +0,0 @@
-/***********************************************************
-Copyright 1991, 1992, 1993 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.
-
-******************************************************************/
-
-/* Python version information */
-
-/* Return the version string. This is constructed from the official
- version number, the patch level, and the current date (if known to
- the compiler, else a manually inserted date). */
-
-#define VERSION "1.0.%d ALPHA (%s)"
-
-#ifdef __DATE__
-#define DATE __DATE__
-#else
-#define DATE ">= 21 Dec 1993"
-#endif
-
-char *
-getversion()
-{
- static char version[80];
- sprintf(version, VERSION, PATCHLEVEL, DATE);
- return version;
-}
-
-
-/* Return the copyright string. This is updated manually. */
-
-char *
-getcopyright()
-{
- return
-"Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum, Amsterdam";
-}
-
-
-/* Return the initial python search path. This is called once from
- initsys() to initialize sys.path.
- The environment variable PYTHONPATH is fetched and the default path
- appended. (The Mac has no environment variables, so there the
- default path is always returned.) The default path may be passed
- to the preprocessor; if not, a system-dependent default is used. */
-
-#ifndef PYTHONPATH
-#ifdef macintosh
-#define PYTHONPATH ": :lib :demo"
-#endif /* macintosh */
-#endif /* !PYTHONPATH */
-
-#ifndef PYTHONPATH
-#ifdef MSDOS
-#define PYTHONPATH ".;..\\lib;\\python\\lib"
-#endif /* MSDOS */
-#endif /* !PYTHONPATH */
-
-#ifndef PYTHONPATH
-#define PYTHONPATH ".:/usr/local/lib/python"
-#endif /* !PYTHONPATH */
-
-extern char *getenv();
-
-char *
-getpythonpath()
-{
-#ifdef macintosh
- return PYTHONPATH;
-#else /* !macintosh */
- char *path = getenv("PYTHONPATH");
- char *defpath = PYTHONPATH;
- char *buf;
- char *p;
- int n;
-
- if (path == 0 || *path == '\0')
- return defpath;
- n = strlen(path) + strlen(defpath) + 2;
- buf = malloc(n);
- if (buf == NULL)
- return path; /* XXX too bad -- but not likely */
- strcpy(buf, path);
- p = buf + strlen(buf);
- *p++ = DELIM;
- strcpy(p, defpath);
- return buf;
-#endif /* !macintosh */
-}
-
-
-/* Table of built-in modules.
- These are initialized when first imported.
- Note: selection of optional extensions is now generally done by the
- mkext.py script in ../Extensions, but for non-UNIX systems most
- well-known extensions are still listed here. */
-
-/* Standard modules */
-
-#ifdef USE_AL
-extern void inital();
-#endif
-#ifdef USE_AMOEBA
-extern void initamoeba();
-#endif
-#ifdef USE_AUDIO
-extern void initaudio();
-#endif
-#ifdef USE_AUDIOOP
-extern void initaudioop();
-#endif
-#ifdef USE_CD
-extern void initcd();
-#endif
-#ifdef USE_CL
-extern void initcl();
-#endif
-#ifdef USE_DBM
-extern void initdbm();
-#endif
-#ifdef USE_FCNTL
-extern void initfcntl();
-#endif
-#ifdef USE_FL
-extern void initfl();
-#endif
-#ifdef USE_FM
-extern void initfm();
-#endif
-#ifdef USE_GL
-extern void initgl();
-#endif
-#ifdef USE_GRP
-extern void initgrp();
-#endif
-#ifdef USE_IMGFILE
-extern void initimgfile();
-#endif
-#ifdef USE_JPEG
-extern void initjpeg();
-#endif
-#ifdef USE_MAC
-extern void initmac();
-#endif
-#ifdef USE_MARSHAL
-extern void initmarshal();
-#endif
-#ifdef USE_MATH
-extern void initmath();
-#endif
-#ifdef USE_NIS
-extern void initnis();
-#endif
-#ifdef USE_PANEL
-extern void initpanel();
-#endif
-#ifdef USE_POSIX
-extern void initposix();
-#endif
-#ifdef USE_PWD
-extern void initpwd();
-#endif
-#ifdef USE_REGEX
-extern void initregex();
-#endif
-#ifdef USE_ROTOR
-extern void initrotor();
-#endif
-#ifdef USE_SELECT
-extern void initselect();
-#endif
-#ifdef USE_SGI
-extern void initsgi();
-#endif
-#ifdef USE_SOCKET
-extern void initsocket();
-#endif
-#ifdef USE_STDWIN
-extern void initstdwin();
-#endif
-#ifdef USE_STROP
-extern void initstrop();
-#endif
-#ifdef USE_STRUCT
-extern void initstruct();
-#endif
-#ifdef USE_SUNAUDIODEV
-extern void initsunaudiodev();
-#endif
-#ifdef USE_SV
-extern void initsv();
-#endif
-#ifdef USE_TIME
-extern void inittime();
-#endif
-#ifdef USE_IMAGEOP
-extern void initimageop();
-#endif
-#ifdef USE_MPZ
-extern void initmpz();
-#endif
-#ifdef USE_MD5
-extern void initmd5();
-#endif
-#ifdef USE_ARRAY
-extern void initarray();
-#endif
-#ifdef USE_XT
-extern void initXt();
-#endif
-#ifdef USE_XAW
-extern void initXaw();
-#endif
-#ifdef USE_XM
-extern void initXm();
-#endif
-#ifdef USE_GLX
-extern void initGlx();
-#endif
-#ifdef USE_HTML
-extern void initHTML();
-#endif
-#ifdef USE_XLIB
-extern void initXlib();
-#endif
-#ifdef USE_PARSER
-extern void initparser();
-#endif
-/* -- ADDMODULE MARKER 1 -- */
-
-struct {
- char *name;
- void (*initfunc)();
-} inittab[] = {
-
-#ifdef USE_AL
- {"al", inital},
-#endif
-
-#ifdef USE_AMOEBA
- {"amoeba", initamoeba},
-#endif
-
-#ifdef USE_AUDIO
- {"audio", initaudio},
-#endif
-
-#ifdef USE_AUDIOOP
- {"audioop", initaudioop},
-#endif
-
-#ifdef USE_CD
- {"cd", initcd},
-#endif
-
-#ifdef USE_CL
- {"cl", initcl},
-#endif
-
-#ifdef USE_DBM
- {"dbm", initdbm},
-#endif
-
-#ifdef USE_FCNTL
- {"fcntl", initfcntl},
-#endif
-
-#ifdef USE_FL
- {"fl", initfl},
-#endif
-
-#ifdef USE_FM
- {"fm", initfm},
-#endif
-
-#ifdef USE_GL
- {"gl", initgl},
-#endif
-
-#ifdef USE_GRP
- {"grp", initgrp},
-#endif
-
-#ifdef USE_IMGFILE
- {"imgfile", initimgfile},
-#endif
-
-#ifdef USE_JPEG
- {"jpeg", initjpeg},
-#endif
-
-#ifdef USE_MAC
- {"mac", initmac},
-#endif
-
-#ifdef USE_MARSHAL
- {"marshal", initmarshal},
-#endif
-
-#ifdef USE_MATH
- {"math", initmath},
-#endif
-
-#ifdef USE_NIS
- {"nis", initnis},
-#endif
-
-#ifdef USE_PANEL
- {"pnl", initpanel},
-#endif
-
-#ifdef USE_POSIX
- {"posix", initposix},
-#endif
-
-#ifdef USE_PWD
- {"pwd", initpwd},
-#endif
-
-#ifdef USE_REGEX
- {"regex", initregex},
-#endif
-
-#ifdef USE_ROTOR
- {"rotor", initrotor},
-#endif
-
-#ifdef USE_SELECT
- {"select", initselect},
-#endif
-
-#ifdef USE_SGI
- {"sgi", initsgi},
-#endif
-
-#ifdef USE_SOCKET
- {"socket", initsocket},
-#endif
-
-#ifdef USE_STDWIN
- {"stdwin", initstdwin},
-#endif
-
-#ifdef USE_STROP
- {"strop", initstrop},
-#endif
-
-#ifdef USE_STRUCT
- {"struct", initstruct},
-#endif
-
-#ifdef USE_SUNAUDIODEV
- {"sunaudiodev", initsunaudiodev},
-#endif
-
-#ifdef USE_SV
- {"sv", initsv},
-#endif
-
-#ifdef USE_TIME
- {"time", inittime},
-#endif
-
-#ifdef USE_IMAGEOP
- {"imageop", initimageop},
-#endif
-
-#ifdef USE_MPZ
- {"mpz", initmpz},
-#endif
-
-#ifdef USE_MD5
- {"md5", initmd5},
-#endif
-
-#ifdef USE_ARRAY
- {"array", initarray},
-#endif
diff --git a/Modules/yuv.h b/Modules/yuv.h
index 4046df6..60b6287 100644
--- a/Modules/yuv.h
+++ b/Modules/yuv.h
@@ -1,3 +1,27 @@
+/***********************************************************
+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.
+
+******************************************************************/
+
#ifndef Py_YUV_H
#define Py_YUV_H
#ifdef __cplusplus
diff --git a/Modules/yuvconvert.c b/Modules/yuvconvert.c
index 1b0ea63..69ec47c 100644
--- a/Modules/yuvconvert.c
+++ b/Modules/yuvconvert.c
@@ -1,3 +1,27 @@
+/***********************************************************
+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.
+
+******************************************************************/
+
#include "yuv.h"
void
diff --git a/Objects/Makefile.in b/Objects/Makefile.in
index 42671d9..d0c086f 100644
--- a/Objects/Makefile.in
+++ b/Objects/Makefile.in
@@ -9,17 +9,17 @@ VPATH= @srcdir@
CC= @CC@
RANLIB= @RANLIB@
+AR= @AR@
+
DEFS= @DEFS@
# === Other things that are customizable but not by configure ===
-TOP= ..
-INCLDIR= $(TOP)/Py
-OPT= -g
-CFLAGS= $(OPT) -I$(INCLDIR) $(DEFS)
+INCLDIR= $(srcdir)/../Include
+OPT= -O
+CFLAGS= $(OPT) -I$(INCLDIR) -I.. $(DEFS)
-AR= ar
MKDEP= mkdep
SHELL= /bin/sh
@@ -57,11 +57,33 @@ clean:
clobber: clean
-rm -f *.a tags TAGS
-Makefile: Makefile.in $(TOP)/config.status
- CONFIG_FILES=Makefile $(SHELL) $(TOP)/config.status
-
-depend: $(SRCS)
- $(MKDEP) $(CFLAGS) $(SRCS) $(PGENSRCS)
+Makefile: $(srcdir)/Makefile.in ../config.status
+ (cd ..; CONFIG_FILES=Objects/Makefile CONFIG_HEADERS= \
+ $(SHELL) config.status)
+
+depend:
+ $(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \
+ sed 's|\(.*\)\.o|$(srcdir)/\1.c|'`
+
+.PRECIOUS: Makefile
+
+accessobject.o: accessobject.c
+classobject.o: classobject.c
+fileobject.o: fileobject.c
+floatobject.o: floatobject.c
+frameobject.o: frameobject.c
+funcobject.o: funcobject.c
+intobject.o: intobject.c
+listobject.o: listobject.c
+longobject.o: longobject.c
+mappingobject.o: mappingobject.c
+methodobject.o: methodobject.c
+moduleobject.o: moduleobject.c
+object.o: object.c
+rangeobject.o: rangeobject.c
+stringobject.o: stringobject.c
+tupleobject.o: tupleobject.c
+typeobject.o: typeobject.c
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/Objects/accessobject.c b/Objects/accessobject.c
index b2cd4ad..d516e67 100644
--- a/Objects/accessobject.c
+++ b/Objects/accessobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -26,7 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* XXX TO DO LIST
- __init__ and __del__ (and all other similar methods)
- should be usable even when private, not ignored (???)
+ should be usable even when private, not ignored
*/
#include "allobjects.h"
@@ -321,12 +321,12 @@ typeobject Accesstype = {
sizeof(accessobject), /*tp_size*/
0, /*tp_itemsize*/
/* methods */
- access_dealloc, /*tp_dealloc*/
+ (destructor)access_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- access_getattr, /*tp_getattr*/
+ (getattrfunc)access_getattr, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
- access_repr, /*tp_repr*/
+ (reprfunc)access_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 268cf1a..35ce0b1 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -103,7 +103,7 @@ class_getattr(op, name)
register char *name;
{
register object *v;
- object *class;
+ classobject *class;
if (strcmp(name, "__dict__") == 0) {
INCREF(op->cl_dict);
return op->cl_dict;
@@ -189,12 +189,12 @@ typeobject Classtype = {
"class",
sizeof(classobject),
0,
- class_dealloc, /*tp_dealloc*/
+ (destructor)class_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- class_getattr, /*tp_getattr*/
- class_setattr, /*tp_setattr*/
+ (getattrfunc)class_getattr, /*tp_getattr*/
+ (setattrfunc)class_setattr, /*tp_setattr*/
0, /*tp_compare*/
- class_repr, /*tp_repr*/
+ (reprfunc)class_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
@@ -235,7 +235,7 @@ addaccess(class, inst)
n = gettuplesize(class->cl_bases);
for (i = 0; i < n; i++) {
- if (addaccess(gettupleitem(class->cl_bases, i), inst) < 0)
+ if (addaccess((classobject *)gettupleitem(class->cl_bases, i), inst) < 0)
return -1;
}
@@ -613,9 +613,9 @@ instance_ass_subscript(inst, key, value)
}
static mapping_methods instance_as_mapping = {
- instance_length, /*mp_length*/
- instance_subscript, /*mp_subscript*/
- instance_ass_subscript, /*mp_ass_subscript*/
+ (inquiry)instance_length, /*mp_length*/
+ (binaryfunc)instance_subscript, /*mp_subscript*/
+ (objobjargproc)instance_ass_subscript, /*mp_ass_subscript*/
};
static object *
@@ -764,13 +764,13 @@ instance_ass_slice(inst, i, j, value)
}
static sequence_methods instance_as_sequence = {
- instance_length, /*sq_length*/
- instance_concat, /*sq_concat*/
- instance_repeat, /*sq_repeat*/
- instance_item, /*sq_item*/
- instance_slice, /*sq_slice*/
- instance_ass_item, /*sq_ass_item*/
- instance_ass_slice, /*sq_ass_slice*/
+ (inquiry)instance_length, /*sq_length*/
+ (binaryfunc)instance_concat, /*sq_concat*/
+ (intargfunc)instance_repeat, /*sq_repeat*/
+ (intargfunc)instance_item, /*sq_item*/
+ (intintargfunc)instance_slice, /*sq_slice*/
+ (intobjargproc)instance_ass_item, /*sq_ass_item*/
+ (intintobjargproc)instance_ass_slice, /*sq_ass_slice*/
};
static object *
@@ -916,29 +916,29 @@ UNARY(instance_oct, "__oct__")
UNARY(instance_hex, "__hex__")
static number_methods instance_as_number = {
- instance_add, /*nb_add*/
- instance_sub, /*nb_subtract*/
- instance_mul, /*nb_multiply*/
- instance_div, /*nb_divide*/
- instance_mod, /*nb_remainder*/
- instance_divmod, /*nb_divmod*/
- instance_pow, /*nb_power*/
- instance_neg, /*nb_negative*/
- instance_pos, /*nb_positive*/
- instance_abs, /*nb_absolute*/
- instance_nonzero, /*nb_nonzero*/
- instance_invert, /*nb_invert*/
- instance_lshift, /*nb_lshift*/
- instance_rshift, /*nb_rshift*/
- instance_and, /*nb_and*/
- instance_xor, /*nb_xor*/
- instance_or, /*nb_or*/
- instance_coerce, /*nb_coerce*/
- instance_int, /*nb_int*/
- instance_long, /*nb_long*/
- instance_float, /*nb_float*/
- instance_oct, /*nb_oct*/
- instance_hex, /*nb_hex*/
+ (binaryfunc)instance_add, /*nb_add*/
+ (binaryfunc)instance_sub, /*nb_subtract*/
+ (binaryfunc)instance_mul, /*nb_multiply*/
+ (binaryfunc)instance_div, /*nb_divide*/
+ (binaryfunc)instance_mod, /*nb_remainder*/
+ (binaryfunc)instance_divmod, /*nb_divmod*/
+ (binaryfunc)instance_pow, /*nb_power*/
+ (unaryfunc)instance_neg, /*nb_negative*/
+ (unaryfunc)instance_pos, /*nb_positive*/
+ (unaryfunc)instance_abs, /*nb_absolute*/
+ (inquiry)instance_nonzero, /*nb_nonzero*/
+ (unaryfunc)instance_invert, /*nb_invert*/
+ (binaryfunc)instance_lshift, /*nb_lshift*/
+ (binaryfunc)instance_rshift, /*nb_rshift*/
+ (binaryfunc)instance_and, /*nb_and*/
+ (binaryfunc)instance_xor, /*nb_xor*/
+ (binaryfunc)instance_or, /*nb_or*/
+ (coercion)instance_coerce, /*nb_coerce*/
+ (unaryfunc)instance_int, /*nb_int*/
+ (unaryfunc)instance_long, /*nb_long*/
+ (unaryfunc)instance_float, /*nb_float*/
+ (unaryfunc)instance_oct, /*nb_oct*/
+ (unaryfunc)instance_hex, /*nb_hex*/
};
typeobject Instancetype = {
@@ -947,17 +947,17 @@ typeobject Instancetype = {
"instance",
sizeof(instanceobject),
0,
- instance_dealloc, /*tp_dealloc*/
+ (destructor)instance_dealloc, /*tp_dealloc*/
0, /*tp_print*/
(object * (*) FPROTO((object *, char *)))
- instance_getattr, /*tp_getattr*/
- instance_setattr, /*tp_setattr*/
- instance_compare, /*tp_compare*/
- instance_repr, /*tp_repr*/
+ (getattrfunc)instance_getattr, /*tp_getattr*/
+ (setattrfunc)instance_setattr, /*tp_setattr*/
+ (cmpfunc)instance_compare, /*tp_compare*/
+ (reprfunc)instance_repr, /*tp_repr*/
&instance_as_number, /*tp_as_number*/
&instance_as_sequence, /*tp_as_sequence*/
&instance_as_mapping, /*tp_as_mapping*/
- instance_hash, /*tp_hash*/
+ (hashfunc)instance_hash, /*tp_hash*/
};
@@ -1126,14 +1126,14 @@ typeobject Instancemethodtype = {
"instance method",
sizeof(instancemethodobject),
0,
- instancemethod_dealloc, /*tp_dealloc*/
+ (destructor)instancemethod_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- instancemethod_getattr, /*tp_getattr*/
+ (getattrfunc)instancemethod_getattr, /*tp_getattr*/
0, /*tp_setattr*/
- instancemethod_compare, /*tp_compare*/
- instancemethod_repr, /*tp_repr*/
+ (cmpfunc)instancemethod_compare, /*tp_compare*/
+ (reprfunc)instancemethod_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
- instancemethod_hash, /*tp_hash*/
+ (hashfunc)instancemethod_hash, /*tp_hash*/
};
diff --git a/Objects/fileobject.c b/Objects/fileobject.c
index 518fe04..eb8f4aa 100644
--- a/Objects/fileobject.c
+++ b/Objects/fileobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -26,6 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h"
#include "modsupport.h"
+#include "structmember.h"
#include "ceval.h"
#define BUF(v) GETSTRINGVALUE((stringobject *)v)
@@ -113,6 +114,30 @@ newfileobject(name, mode)
return (object *)f;
}
+void
+setfilebufsize(f, bufsize)
+ object *f;
+ int bufsize;
+{
+ if (bufsize >= 0) {
+#ifdef HAVE_SETVBUF
+ int type;
+ switch (bufsize) {
+ case 0:
+ type = _IONBF;
+ break;
+ case 1:
+ type = _IOLBF;
+ bufsize = BUFSIZ;
+ break;
+ default:
+ type = _IOFBF;
+ }
+ setvbuf(((fileobject *)f)->f_fp, (char *)NULL, type, bufsize);
+#endif /* HAVE_SETVBUF */
+ }
+}
+
static object *
err_closed()
{
@@ -290,16 +315,16 @@ file_read(f, args)
if (f->f_fp == NULL)
return err_closed();
- if (args == NULL) {
+ if (args == NULL)
n = 0;
+ else {
+ if (!getargs(args, "i", &n))
+ return NULL;
if (n < 0) {
err_setstr(ValueError, "negative read count");
return NULL;
}
}
- else if (!getargs(args, "i", &n))
- return NULL;
-
n2 = n != 0 ? n : BUFSIZ;
v = newsizedstringobject((char *)NULL, n2);
if (v == NULL)
@@ -358,10 +383,9 @@ getline(f, n)
for (;;) {
if ((c = getc(fp)) == EOF) {
clearerr(fp);
- if (intrcheck()) {
+ if (sigcheck()) {
RET_SAVE
DECREF(v);
- err_set(KeyboardInterrupt);
return NULL;
}
if (n < 0 && buf == BUF(v)) {
@@ -583,26 +607,58 @@ file_writelines(f, args)
}
static struct methodlist file_methods[] = {
- {"close", file_close},
- {"flush", file_flush},
- {"fileno", file_fileno},
- {"isatty", file_isatty},
- {"read", file_read},
- {"readline", file_readline},
- {"readlines", file_readlines},
- {"seek", file_seek},
- {"tell", file_tell},
- {"write", file_write},
- {"writelines", file_writelines},
+ {"close", (method)file_close},
+ {"flush", (method)file_flush},
+ {"fileno", (method)file_fileno},
+ {"isatty", (method)file_isatty},
+ {"read", (method)file_read},
+ {"readline", (method)file_readline},
+ {"readlines", (method)file_readlines},
+ {"seek", (method)file_seek},
+ {"tell", (method)file_tell},
+ {"write", (method)file_write},
+ {"writelines", (method)file_writelines},
{NULL, NULL} /* sentinel */
};
+#define OFF(x) offsetof(fileobject, x)
+
+static struct memberlist file_memberlist[] = {
+ {"softspace", T_INT, OFF(f_softspace)},
+ {"mode", T_OBJECT, OFF(f_mode), RO},
+ {"name", T_OBJECT, OFF(f_name), RO},
+ /* getattr(f, "closed") is implemented without this table */
+ {"closed", T_INT, 0, RO},
+ {NULL} /* Sentinel */
+};
+
static object *
file_getattr(f, name)
fileobject *f;
char *name;
{
- return findmethod(file_methods, (object *)f, name);
+ object *res;
+
+ res = findmethod(file_methods, (object *)f, name);
+ if (res != NULL)
+ return res;
+ err_clear();
+ if (strcmp(name, "closed") == 0)
+ return newintobject((long)(f->f_fp == 0));
+ return getmember((char *)f, file_memberlist, name);
+}
+
+static int
+file_setattr(f, name, v)
+ fileobject *f;
+ char *name;
+ object *v;
+{
+ if (v == NULL) {
+ err_setstr(AttributeError, "can't delete file attributes");
+ return -1;
+ }
+ return setmember((char *)f, file_memberlist, name, v);
}
typeobject Filetype = {
@@ -611,12 +667,12 @@ typeobject Filetype = {
"file",
sizeof(fileobject),
0,
- file_dealloc, /*tp_dealloc*/
+ (destructor)file_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- file_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
+ (getattrfunc)file_getattr, /*tp_getattr*/
+ (setattrfunc)file_setattr, /*tp_setattr*/
0, /*tp_compare*/
- file_repr, /*tp_repr*/
+ (reprfunc)file_repr, /*tp_repr*/
};
/* Interface for the 'soft space' between print items. */
@@ -710,7 +766,7 @@ writestring(s, f)
if (fp != NULL)
fputs(s, fp);
}
- else {
+ else if (!err_occurred()) {
object *v = newstringobject(s);
if (v == NULL) {
err_clear();
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index d3a2c77..5ff67db 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -47,7 +47,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define CHECK(x) /* Don't know how to check */
#endif
-#ifndef THINK_C
+#ifndef macintosh
extern double fmod PROTO((double, double));
extern double pow PROTO((double, double));
#endif
@@ -77,12 +77,31 @@ double
getfloatvalue(op)
object *op;
{
- if (!is_floatobject(op)) {
+ number_methods *nb;
+ floatobject *fo;
+ double val;
+
+ if (op && is_floatobject(op))
+ return GETFLOATVALUE((floatobject*) op);
+
+ if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL ||
+ nb->nb_float == NULL) {
err_badarg();
return -1;
}
- else
- return ((floatobject *)op) -> ob_fval;
+
+ fo = (floatobject*) (*nb->nb_float) (op);
+ if (fo == NULL)
+ return -1;
+ if (!is_floatobject(fo)) {
+ err_setstr(TypeError, "nb_float should return float object");
+ return -1;
+ }
+
+ val = GETFLOATVALUE(fo);
+ DECREF(fo);
+
+ return val;
}
/* Methods */
@@ -156,7 +175,17 @@ float_hash(v)
/* This is designed so that Python numbers with the same
value hash to the same value, otherwise comparisons
of mapping keys will turn out weird */
+
+#ifdef MPW /* MPW C modf expects pointer to extended as second argument */
+{
+ extended e;
+ fractpart = modf(v->ob_fval, &e);
+ intpart = e;
+}
+#else
fractpart = modf(v->ob_fval, &intpart);
+#endif
+
if (fractpart == 0.0) {
if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
/* Convert to long int and use its hash... */
@@ -372,27 +401,27 @@ float_float(v)
static number_methods float_as_number = {
- float_add, /*nb_add*/
- float_sub, /*nb_subtract*/
- float_mul, /*nb_multiply*/
- float_div, /*nb_divide*/
- float_rem, /*nb_remainder*/
- float_divmod, /*nb_divmod*/
- float_pow, /*nb_power*/
- float_neg, /*nb_negative*/
- float_pos, /*nb_positive*/
- float_abs, /*nb_absolute*/
- float_nonzero, /*nb_nonzero*/
+ (binaryfunc)float_add, /*nb_add*/
+ (binaryfunc)float_sub, /*nb_subtract*/
+ (binaryfunc)float_mul, /*nb_multiply*/
+ (binaryfunc)float_div, /*nb_divide*/
+ (binaryfunc)float_rem, /*nb_remainder*/
+ (binaryfunc)float_divmod, /*nb_divmod*/
+ (binaryfunc)float_pow, /*nb_power*/
+ (unaryfunc)float_neg, /*nb_negative*/
+ (unaryfunc)float_pos, /*nb_positive*/
+ (unaryfunc)float_abs, /*nb_absolute*/
+ (inquiry)float_nonzero, /*nb_nonzero*/
0, /*nb_invert*/
0, /*nb_lshift*/
0, /*nb_rshift*/
0, /*nb_and*/
0, /*nb_xor*/
0, /*nb_or*/
- float_coerce, /*nb_coerce*/
- float_int, /*nb_int*/
- float_long, /*nb_long*/
- float_float, /*nb_float*/
+ (coercion)float_coerce, /*nb_coerce*/
+ (unaryfunc)float_int, /*nb_int*/
+ (unaryfunc)float_long, /*nb_long*/
+ (unaryfunc)float_float, /*nb_float*/
0, /*nb_oct*/
0, /*nb_hex*/
};
@@ -403,14 +432,14 @@ typeobject Floattype = {
"float",
sizeof(floatobject),
0,
- float_dealloc, /*tp_dealloc*/
- float_print, /*tp_print*/
+ (destructor)float_dealloc, /*tp_dealloc*/
+ (printfunc)float_print, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- float_compare, /*tp_compare*/
- float_repr, /*tp_repr*/
+ (cmpfunc)float_compare, /*tp_compare*/
+ (reprfunc)float_repr, /*tp_repr*/
&float_as_number, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
- float_hash, /*tp_hash */
+ (hashfunc)float_hash, /*tp_hash*/
};
diff --git a/Objects/xxobject.c b/Objects/xxobject.c
index 64e0228..e135d3f 100644
--- a/Objects/xxobject.c
+++ b/Objects/xxobject.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -42,7 +42,7 @@ typedef struct {
object *x_attr; /* Attributes dictionary */
} xxobject;
-extern typeobject Xxtype; /* Really static, forward */
+staticforward typeobject Xxtype;
#define is_xxobject(v) ((v)->ob_type == &Xxtype)
@@ -80,7 +80,7 @@ xx_demo(self, args)
}
static struct methodlist xx_methods[] = {
- {"demo", xx_demo},
+ {"demo", (method)xx_demo},
{NULL, NULL} /* sentinel */
};
@@ -125,13 +125,13 @@ static typeobject Xxtype = {
OB_HEAD_INIT(&Typetype)
0, /*ob_size*/
"xx", /*tp_name*/
- sizeof(xxobject), /*tp_size*/
+ sizeof(xxobject), /*tp_basicsize*/
0, /*tp_itemsize*/
/* methods */
- xx_dealloc, /*tp_dealloc*/
+ (destructor)xx_dealloc, /*tp_dealloc*/
0, /*tp_print*/
- xx_getattr, /*tp_getattr*/
- xx_setattr, /*tp_setattr*/
+ (getattrfunc)xx_getattr, /*tp_getattr*/
+ (setattrfunc)xx_setattr, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
diff --git a/Parser/Makefile.in b/Parser/Makefile.in
index b5649aa..4c1e1fa 100644
--- a/Parser/Makefile.in
+++ b/Parser/Makefile.in
@@ -9,17 +9,17 @@ VPATH= @srcdir@
CC= @CC@
RANLIB= @RANLIB@
+AR= @AR@
+
DEFS= @DEFS@
# === Other things that are customizable but not by configure ===
-TOP= ..
-INCLDIR= $(TOP)/Py
-OPT= -g
-CFLAGS= $(OPT) -I$(INCLDIR) $(DEFS)
+INCLDIR= $(srcdir)/../Include
+OPT= -O
+CFLAGS= $(OPT) -I$(INCLDIR) -I.. $(DEFS)
-AR= ar
MKDEP= mkdep
SHELL= /bin/sh
@@ -34,13 +34,7 @@ PARSEROBJS= acceler.o grammar1.o \
PGENOBJS= pgenmain.o
-PARSERSRCS= acceler.c fgetsintr.c grammar1.c \
- intrcheck.c listnode.c myreadline.c node.c parser.c \
- parsetok.c tokenizer.c bitset.c \
- firstsets.c grammar.c metagrammar.c pgen.c \
- printgrammar.c
-
-PGENSRCS= pgenmain.c
+OBJS= $(PGENOBJS) $(PARSEROBJS)
PGEN= pgen
@@ -64,11 +58,32 @@ clean:
clobber: clean
-rm -f $(PGEN) *.a tags TAGS
-Makefile: Makefile.in $(TOP)/config.status
- CONFIG_FILES=Makefile $(SHELL) $(TOP)/config.status
-
-depend: $(PARSERSRCS) $(PGENSRCS)
- $(MKDEP) $(CFLAGS) $(PARSERSRCS) $(PGENSRCS)
+Makefile: $(srcdir)/Makefile.in ../config.status
+ (cd ..; CONFIG_FILES=Parser/Makefile CONFIG_HEADERS= \
+ $(SHELL) config.status)
+
+depend:
+ $(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \
+ sed 's|\(.*\)\.o|$(srcdir)/\1.c|'`
+
+.PRECIOUS: Makefile
+
+acceler.o: acceler.c
+grammar1.o: grammar1.c
+intrcheck.o: intrcheck.c
+listnode.o: listnode.c
+myreadline.o: myreadline.c
+node.o: node.c
+parser.o: parser.c
+parsetok.o: parsetok.c
+tokenizer.o: tokenizer.c
+bitset.o: bitset.c
+firstsets.o: firstsets.c
+grammar.o: grammar.c
+metagrammar.o: metagrammar.c
+pgen.o: pgen.c
+printgrammar.o: printgrammar.c
+pgenmain.o: pgenmain.c
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/Parser/assert.h b/Parser/assert.h
index dbce369..d007eca 100644
--- a/Parser/assert.h
+++ b/Parser/assert.h
@@ -5,7 +5,7 @@ extern "C" {
#endif
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -28,7 +28,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+#ifdef MPW /* This is for MPW's File command */
+
+#define assert(e) { if (!(e)) { printf("### Python: Assertion failed:\n\
+ File %s; Line %d\n", __FILE__, __LINE__); abort(); } }
+#else
#define assert(e) { if (!(e)) { printf("Assertion failed\n"); abort(); } }
+#endif
#ifdef __cplusplus
}
diff --git a/Parser/myreadline.c b/Parser/myreadline.c
index 870333c..18f8b1d 100644
--- a/Parser/myreadline.c
+++ b/Parser/myreadline.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -32,12 +32,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- a malloc'ed string ending in \n normally
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <string.h>
+#include <errno.h>
+#include "myproto.h"
#include "mymalloc.h"
+#include "intrcheck.h"
-#ifdef HAVE_READLINE
+#ifdef WITH_READLINE
extern char *readline();
@@ -54,7 +61,44 @@ onintr(sig)
longjmp(jbuf, 1);
}
-#endif /* HAVE_READLINE */
+#else /* !WITH_READLINE */
+
+/* This function restarts a fgets() after an EINTR error occurred
+ except if intrcheck() returns true. */
+
+static int
+my_fgets(buf, len, fp)
+ char *buf;
+ int len;
+ FILE *fp;
+{
+ char *p;
+ for (;;) {
+ errno = 0;
+ p = fgets(buf, len, fp);
+ if (p != NULL)
+ return 0; /* No error */
+ if (feof(fp)) {
+ return -1; /* EOF */
+ }
+#ifdef EINTR
+ if (errno == EINTR) {
+ if (intrcheck()) {
+ return 1; /* Interrupt */
+ }
+ continue;
+ }
+#endif
+ if (intrcheck()) {
+ return 1; /* Interrupt */
+ }
+ return -2; /* Error */
+ }
+ /* NOTREACHED */
+}
+
+#endif /* WITH_READLINE */
+
char *
my_readline(prompt)
@@ -62,7 +106,7 @@ my_readline(prompt)
{
int n;
char *p;
-#ifdef HAVE_READLINE
+#ifdef WITH_READLINE
RETSIGTYPE (*old_inthandler)();
static int been_here;
if (!been_here) {
@@ -92,28 +136,41 @@ my_readline(prompt)
p[n+1] = '\0';
}
return p;
-#else /* !HAVE_READLINE */
+#else /* !WITH_READLINE */
n = 100;
if ((p = malloc(n)) == NULL)
return NULL;
if (prompt)
fprintf(stderr, "%s", prompt);
- if (fgets(p, n, stdin) == NULL)
- *p = '\0';
- if (intrcheck()) {
+ switch (my_fgets(p, n, stdin)) {
+ case 0: /* Normal case */
+ break;
+ case 1: /* Interrupt */
free(p);
return NULL;
+ case -1: /* EOF */
+ case -2: /* Error */
+ default: /* Shouldn't happen */
+ *p = '\0';
+ break;
}
+#ifdef MPW
+ /* Hack for MPW C where the prompt comes right back in the input */
+ /* XXX (Actually this would be rather nice on most systems...) */
+ n = strlen(prompt);
+ if (strncmp(p, prompt, n) == 0)
+ memmove(p, p + n, strlen(p) - n + 1);
+#endif
n = strlen(p);
while (n > 0 && p[n-1] != '\n') {
int incr = n+2;
p = realloc(p, n + incr);
if (p == NULL)
return NULL;
- if (fgets(p+n, incr, stdin) == NULL)
+ if (my_fgets(p+n, incr, stdin) != 0)
break;
n += strlen(p+n);
}
return realloc(p, n+1);
-#endif /* !HAVE_READLINE */
+#endif /* !WITH_READLINE */
}
diff --git a/Python/Makefile.in b/Python/Makefile.in
index 7340ed4..732ea86 100644
--- a/Python/Makefile.in
+++ b/Python/Makefile.in
@@ -9,19 +9,20 @@ VPATH= @srcdir@
CC= @CC@
RANLIB= @RANLIB@
+AR= @AR@
+
DEFS= @DEFS@
LIBOBJS= @LIBOBJS@
LIBS= @LIBS@
+DLINCLDIR= @DLINCLDIR@
# === Other things that are customizable but not by configure ===
-TOP= ..
-INCLDIR= $(TOP)/Py
-OPT= -g
-CFLAGS= $(OPT) -I$(INCLDIR) $(DEFS)
+INCLDIR= $(srcdir)/../Include
+OPT= -O
+CFLAGS= $(OPT) -I$(INCLDIR) -I.. $(DEFS)
-AR= ar
MKDEP= mkdep
SHELL= /bin/sh
@@ -29,52 +30,77 @@ SHELL= /bin/sh
# === Fixed definitions ===
OBJS= \
- arraymodule.o \
bltinmodule.o \
ceval.o cgensupport.o compile.o \
errors.o \
frozenmain.o \
getmtime.o graminit.o \
import.o \
- marshal.o mathmodule.o modsupport.o \
- parsermodule.o posixmodule.o pythonmain.o pythonrun.o \
- regexmodule.o regexpr.o \
- stropmodule.o structmember.o structmodule.o sysmodule.o \
- timemodule.o traceback.o \
+ marshal.o modsupport.o mystrtoul.o \
+ pythonmain.o pythonrun.o \
+ sigcheck.o structmember.o sysmodule.o \
+ traceback.o \
version.o \
$(LIBOBJS)
LIB= libPython.a
-MYLIBS= $(LIB) ../Objects/libObjects.a ../Parser/libParser.a
-
SYSLIBS= -lm
# === Rules ===
-all: $(LIB) python
+all: $(LIB)
$(LIB): $(OBJS)
$(AR) cr $(LIB) $(OBJS)
$(RANLIB) $(LIB)
-python: config.o $(MYLIBS)
- $(CC) config.o $(MYLIBS) $(LIBS) $(SYSLIBS) -o python
-
-config.o: Makefile
-
clean:
-rm -f *.o core *~ [@,#]* *.old *.orig *.rej
clobber: clean
- -rm -f *.a python tags TAGS
-
-Makefile: Makefile.in $(TOP)/config.status
- CONFIG_FILES=Makefile $(SHELL) $(TOP)/config.status
-
-depend: $(SRCS)
- $(MKDEP) $(CFLAGS) $(SRCS) $(PGENSRCS)
+ -rm -f *.a tags TAGS
+
+Makefile: $(srcdir)/Makefile.in ../config.status
+ (cd ..; CONFIG_FILES=Python/Makefile CONFIG_HEADERS= \
+ $(SHELL) config.status)
+
+import.o: import.c
+ $(CC) $(CFLAGS) -I$(DLINCLDIR) -c $(srcdir)/import.c
+
+depend:
+ $(MKDEP) $(CFLAGS) `echo $(OBJS) | tr ' ' '\012' | \
+ sed 's|\(.*\)\.o|$(srcdir)/\1.c|'`
+
+.PRECIOUS: Makefile
+
+bltinmodule.o: bltinmodule.c
+ceval.o: ceval.c
+cgensupport.o: cgensupport.c
+compile.o: compile.c
+dup2.o: dup2.c
+errors.o: errors.c
+fmod.o: fmod.c
+frozenmain.o: frozenmain.c
+getcwd.o: getcwd.c
+getmtime.o: getmtime.c
+graminit.o: graminit.c
+import.o: import.c
+marshal.o: marshal.c
+memmove.o: memmove.c
+modsupport.o: modsupport.c
+mystrtoul.o: mystrtoul.c
+pythonmain.o: pythonmain.c
+pythonrun.o: pythonrun.c
+sigcheck.o: sigcheck.c
+strerror.o: strerror.c
+strtod.o: strtod.c
+structmember.o: structmember.c
+sysmodule.o: sysmodule.c
+thread.o: thread.c
+traceback.o: traceback.c
+version.o: version.c
# DO NOT DELETE THIS LINE -- mkdep uses it.
# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
diff --git a/Python/dup2.c b/Python/dup2.c
index 85ec5d5..ee1a7ad 100644
--- a/Python/dup2.c
+++ b/Python/dup2.c
@@ -20,12 +20,17 @@ dup2(fd1, fd2)
int fd1, fd2;
{
if (fd1 != fd2) {
+#ifdef MPW
+ close (fd2); /* XXX RJW MPW does not implement F_GETFL but it does have dup */
+ fd2 = dup(fd1);
+#else
if (fcntl(fd1, F_GETFL) < 0)
return BADEXIT;
if (fcntl(fd2, F_GETFL) >= 0)
close(fd2);
if (fcntl(fd1, F_DUPFD, fd2) < 0)
return BADEXIT;
+#endif
}
return fd2;
}
diff --git a/Python/getmtime.c b/Python/getmtime.c
index 931da64..fa2fd02 100644
--- a/Python/getmtime.c
+++ b/Python/getmtime.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -26,8 +26,16 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* (A separate file because this may be OS dependent) */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef macintosh
+#include "stat.h"
+#else
#include <sys/types.h>
#include <sys/stat.h>
+#endif
long
getmtime(path)
diff --git a/Python/memmove.c b/Python/memmove.c
index e812751..143e642 100644
--- a/Python/memmove.c
+++ b/Python/memmove.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c
index 965421b..6b2a06f 100644
--- a/Python/mystrtoul.c
+++ b/Python/mystrtoul.c
@@ -1,5 +1,5 @@
/***********************************************************
-Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
Amsterdam, The Netherlands.
All Rights Reserved
@@ -22,6 +22,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+/* strtol and strtoul, renamed to avoid conflicts */
+
/*
** strtoul
** This is a general purpose routine for converting
@@ -40,7 +46,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <errno.h>
unsigned long
-strtoul(str, ptr, base)
+mystrtoul(str, ptr, base)
register char * str;
char ** ptr;
int base;
@@ -108,8 +114,10 @@ int base;
}
temp = result;
result = result * base + c;
+#ifndef MPW
if ((result - c) / base != temp) /* overflow */
ovf = 1;
+#endif
str++;
}
@@ -125,7 +133,7 @@ int base;
}
long
-strtol(str, ptr, base)
+mystrtol(str, ptr, base)
char * str;
char ** ptr;
int base;
@@ -140,7 +148,7 @@ int base;
if (sign == '+' || sign == '-')
str++;
- result = (long) strtoul(str, ptr, base);
+ result = (long) mystrtoul(str, ptr, base);
/* Signal overflow if the result appears negative,
except for the largest negative integer */