]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Added separate main program for the Mac: macmain.c
authorGuido van Rossum <guido@python.org>
Thu, 21 Jan 1993 16:07:51 +0000 (16:07 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 21 Jan 1993 16:07:51 +0000 (16:07 +0000)
stdwinmodule.c: wsetfont can now return an error
Makefile: add CL_USE and CL_LIB*S; config.c: move CL part around
New things in imgfile; also in Makefile.
longobject.c: fix comparison of negative long ints...  [REAL BUG!]
marshal.c: add dumps() and loads() to read/write strings
timemodule.c: make sure there's always a floatsleep()
posixmodule.c: rationalize struct returned by times()
Makefile: add test target, disable imgfile by default
thread.c: Improved coexistance with dl module (sjoerd)
stdwinmodule.c: Change include stdwin.h if macintosh
rotormodule.c: added missing last argument to RTR_?_region calls
confic.c: merged with configmac.c, added 1993 to copyright message
fileobject.c: int compared to NULL in writestring(); change fopenRF ifdef
timemodule.c: simplify times() using mkvalue; include myselect.h
  earlier (for sequent).
posixmodule: for sequent, include unistd.h instead of explicit
  extern definitions and don't define rename()
Makefile: change misleading/wrong MD5 comments

Modules/config.c.in
Modules/posixmodule.c
Modules/rotormodule.c
Modules/stdwinmodule.c
Modules/timemodule.c
Objects/fileobject.c
Objects/longobject.c
Python/marshal.c

index 1d840202bde1e7af074791dd37b612eaaaa67baf..11e2cdd7e16ea635d4704f7e632470fba4e86398 100644 (file)
@@ -25,15 +25,30 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 /* Configurable Python configuration file */
 
 /* These modules are normally always included, but *may* be taken out */
-#define USE_GRP                1       /* Use together with pwd */
 #define USE_MARSHAL    1       /* This is linked anyway */
 #define USE_MATH       1
-#define USE_PWD                1       /* Use together with grp */
+#define USE_STRUCT     1
+#define USE_STROP      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_ROTOR      1
+#define USE_STDWIN     1       /* You may turn this off */
+#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
-#define USE_STRUCT     1
-#define USE_TIME       1
+#endif
+
+#include <stdio.h>
 
 #include "PROTO.h"
 #include "mymalloc.h"
@@ -45,18 +60,20 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #ifdef __DATE__
 #define DATE __DATE__
 #else
-#define DATE ">= 8 Jan 1993"
+#define DATE ">= 11 Jan 1993"
 #endif
 
-#include <stdio.h>
-
 #ifdef USE_STDWIN
-#include <stdwin.h>
-#endif
+#ifdef macintosh
+#include ":::src:stdwin:H:stdwin.h"
+#else /* !macintosh */
+#include "stdwin.h"
+#endif /* !macintosh */
+#endif /* USE_STDWIN */
 
 char version[80];
 
-char *argv0;
+char *argv0; /* For dynamic loading in import.c */
 
 /*ARGSUSED*/
 void
@@ -69,13 +86,16 @@ initargs(p_argc, p_argv)
        argv0 = **p_argv;
 
 #ifdef USE_STDWIN
-       wargs(p_argc, p_argv);
+#ifdef THINK_C_3_0
+       wsetstdio(1);
 #endif
+       wargs(p_argc, p_argv);
+#endif /* USE_STDWIN */
        if (*p_argc < 2 && isatty(0) && isatty(1))
        {
                printf("Python %s.\n", version);
                printf(
-"Copyright 1990, 1991, 1992 Stichting Mathematisch Centrum, Amsterdam\n");
+"Copyright 1990, 1991, 1992, 1993 Stichting Mathematisch Centrum, Amsterdam\n");
        }
 }
 
@@ -96,14 +116,22 @@ donecalls()
 }
 
 #ifndef PYTHONPATH
+#ifdef macintosh
+/* On the Mac, the search path is a space-separated list of directories */
+#define PYTHONPATH ": :lib :demo"
+#else /* !macintosh */
 #define PYTHONPATH ".:/usr/local/lib/python"
-#endif
+#endif /* !macintosh */
+#endif /* !PYTHONPATH */
 
 extern char *getenv();
 
 char *
 getpythonpath()
 {
+#ifdef macintosh
+       return PYTHONPATH;
+#else /* !macintosh */
        char *path = getenv("PYTHONPATH");
        char *defpath = PYTHONPATH;
        char *buf;
@@ -119,6 +147,7 @@ getpythonpath()
        strcat(buf, ":");
        strcat(buf, defpath);
        return buf;
+#endif /* !macintosh */
 }
 
 
@@ -142,6 +171,9 @@ extern void initaudioop();
 #ifdef USE_CD
 extern void initcd();
 #endif
+#ifdef USE_CL
+extern void initcl();
+#endif
 #ifdef USE_DBM
 extern void initdbm();
 #endif
@@ -166,6 +198,9 @@ extern void initimgfile();
 #ifdef USE_JPEG
 extern void initjpeg();
 #endif
+#ifdef USE_MAC
+extern void initmac();
+#endif
 #ifdef USE_MARSHAL
 extern void initmarshal();
 #endif
@@ -217,9 +252,6 @@ extern void initthread();
 #ifdef USE_SV
 extern void initsv();
 #endif
-#ifdef USE_CL
-extern void initcl();
-#endif
 #ifdef USE_TIME
 extern void inittime();
 #endif
@@ -259,6 +291,10 @@ struct {
        {"cd",          initcd},
 #endif
 
+#ifdef USE_CL
+       {"cl",          initcl},
+#endif
+
 #ifdef USE_DBM
        {"dbm",         initdbm},
 #endif
@@ -291,6 +327,10 @@ struct {
        {"jpeg",        initjpeg},
 #endif
 
+#ifdef USE_MAC
+       {"mac", initmac},
+#endif
+
 #ifdef USE_MARSHAL
        {"marshal",     initmarshal},
 #endif
@@ -355,10 +395,6 @@ struct {
        {"sv",          initsv},
 #endif
 
-#ifdef USE_CL
-       {"cl",          initcl},
-#endif
-
 #ifdef USE_THREAD
        {"thread",      initthread},
 #endif
index bab0c5976919f8e082c411471a047f6d96fd9b74..a6001151fb98a991ad3a5d57531f194a19102833 100644 (file)
@@ -75,6 +75,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "modsupport.h"
 #include "ceval.h"
 
+#ifdef _SEQUENT_
+#include <unistd.h>
+#else /* _SEQUENT_ */
 /* XXX Aren't these always declared in unistd.h? */
 extern char *strerror PROTO((int));
 extern int chmod PROTO((const char *, mode_t));
@@ -87,6 +90,7 @@ extern int rmdir PROTO((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
@@ -375,7 +379,7 @@ posix_nice(self, args)
 }
 #endif
 
-#ifdef i386
+#if i386 && ! _SEQUENT_
 int
 rename(from, to)
        char *from;
@@ -388,7 +392,7 @@ rename(from, to)
                return status;
        return unlink(from);
 }
-#endif /* i386 */
+#endif /* i386 && ! _SEQUENT_ */
 
 static object *
 posix_rename(self, args)
@@ -833,7 +837,6 @@ posix_times(self, args)
 {
        struct tms t;
        clock_t c;
-       object *tuple;
        if (!getnoarg(args))
                return NULL;
        errno = 0;
@@ -842,18 +845,11 @@ posix_times(self, args)
                err_errno(PosixError);
                return NULL;
        }
-       tuple = newtupleobject(4);
-       if (tuple == NULL)
-               return NULL;
-       settupleitem(tuple, 0, newfloatobject((double)t.tms_utime / HZ));
-       settupleitem(tuple, 1, newfloatobject((double)t.tms_stime / HZ));
-       settupleitem(tuple, 2, newfloatobject((double)t.tms_cutime / HZ));
-       settupleitem(tuple, 3, newfloatobject((double)t.tms_cstime / HZ));
-       if (err_occurred()) {
-               DECREF(tuple);
-               return NULL;
-       }
-       return tuple;
+       return mkvalue("dddd",
+                      (double)t.tms_utime / HZ,
+                      (double)t.tms_stime / HZ,
+                      (double)t.tms_cutime / HZ,
+                      (double)t.tms_cstime / HZ);
 }
 
 #endif /* DO_TIMES */
index e8fec0748321d492762557125f4bf845286e1a55..f16acd03c5f45888a32c2d824ae750bac3e52f69 100644 (file)
@@ -590,7 +590,7 @@ static void encrypt_region(r, region, len)
        unsigned char *region;
        int len;
 {
-       RTR_e_region(r,region,len);
+       RTR_e_region(r,region,len,TRUE);
 }
 
 /*(defun decrypt-region (beg end key)
@@ -602,7 +602,7 @@ static void decrypt_region(r, region, len)
        unsigned char *region;
        int len;
 {
-       RTR_d_region(r,region,len);
+       RTR_d_region(r,region,len,TRUE);
 }
 
 /* Rotor methods */
index a33366d3d339eb62d4417bdc4e6cb499556470f4..62e9b47941bc11389f29f9e40c168ce3da9410da 100644 (file)
@@ -1,6 +1,6 @@
 /***********************************************************
-Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
+Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
 
                         All Rights Reserved
 
@@ -66,7 +66,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include "modsupport.h"
 #include "ceval.h"
 
+#ifdef macintosh
+#include ":::src:stdwin:H:stdwin.h"
+#else /* !macintosh */
 #include "stdwin.h"
+#endif /* !macintosh */
 
 #ifdef USE_THREAD
 
@@ -585,8 +589,12 @@ drawing_setfont(self, args)
                                return NULL;
                }
        }
-       if (font != NULL)
-               wsetfont(font);
+       if (font != NULL) {
+               if (!wsetfont(font)) {
+                       err_setstr(StdwinError, "font not found");
+                       return NULL;
+               }
+       }
        if (size != 0)
                wsetsize(size);
        switch (style) {
index 89d889c7c43bf0dc519b705eea55751f4f5ff7ae..b8b22e34c2e911424112554f3a3730175d2fa825 100644 (file)
@@ -35,6 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 #ifdef BSD_TIME
 #define HAVE_GETTIMEOFDAY
+#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
 #endif
 
 #ifdef macintosh
@@ -70,6 +71,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #include <time.h>
 #endif /* !unix */
 
+/* XXX This is bogus -- times() is defined in posixmodule.c */
 #ifdef DO_TIMES
 #include <sys/times.h>
 #include <sys/param.h>
@@ -215,7 +217,6 @@ time_times(self, args)
 {
        struct tms t;
        clock_t c;
-       object *tuple;
        if (!getnoarg(args))
                return NULL;
        errno = 0;
@@ -224,18 +225,11 @@ time_times(self, args)
                err_errno(IOError);
                return NULL;
        }
-       tuple = newtupleobject(4);
-       if (tuple == NULL)
-               return NULL;
-       settupleitem(tuple, 0, newfloatobject((double)t.tms_utime / HZ));
-       settupleitem(tuple, 1, newfloatobject((double)t.tms_stime / HZ));
-       settupleitem(tuple, 2, newfloatobject((double)t.tms_cutime / HZ));
-       settupleitem(tuple, 3, newfloatobject((double)t.tms_cstime / HZ));
-       if (err_occurred()) {
-               DECREF(tuple);
-               return NULL;
-       }
-       return tuple;
+       return mkvalue("dddd",
+                      (double)t.tms_utime / HZ,
+                      (double)t.tms_stime / HZ,
+                      (double)t.tms_cutime / HZ,
+                      (double)t.tms_cstime / HZ);
 }
 
 #endif
@@ -285,7 +279,7 @@ floatsleep(secs)
 {
        register long deadline;
        
-       deadline = MacTicks + long(secs * 60.0);
+       deadline = MacTicks + (long)(secs * 60.0);
        while (MacTicks < deadline) {
                if (intrcheck())
                        sleep_catcher(SIGINT);
@@ -301,9 +295,9 @@ millitimer()
 #endif /* macintosh */
 
 
-#ifdef BSD_TIME
+#ifdef unix
 
-#include "myselect.h" /* Implies <sys/types.h>, <sys/time.h>, <sys/param.h> */
+#ifdef BSD_TIME
 
 long
 millitimer()
@@ -329,7 +323,17 @@ floatsleep(secs)
        (void) select(0, (fd_set *)0, (fd_set *)0, (fd_set *)0, &t);
 }
 
-#endif /* BSD_TIME */
+#else /* !BSD_TIME */
+
+floatsleep(secs)
+       double secs;
+{
+       sleep((int)secs);
+}
+
+#endif /* !BSD_TIME */
+
+#endif /* unix */
 
 
 #ifdef TURBO_C /* Maybe also for MS-DOS? */
@@ -338,14 +342,13 @@ floatsleep(secs)
 #define CLOCKS_PER_SEC 55      /* 54.945 msec per tick (18.2 HZ clock) */
 #endif
 
-static
 floatsleep(secs)
        double secs;
 {
        delay(long(secs/1000.0));
 }
 
-static long
+long
 millitimer()
 {
        clock_t ticks;
index b84819e3fbad74559810a9aaf9ba70551a18df2a..1c0598bf56618fc486ebe451cf2feacb20da29cd 100644 (file)
@@ -86,7 +86,7 @@ newfileobject(name, mode)
        f = (fileobject *) newopenfileobject((FILE *)NULL, name, mode, fclose);
        if (f == NULL)
                return NULL;
-#ifdef THINK_C
+#ifdef USE_FOPENRF
        if (*mode == '*') {
                FILE *fopenRF();
                f->f_fp = fopenRF(name, mode+1);
@@ -670,7 +670,7 @@ writestring(s, f)
                        err_clear();
                }
                else {
-                       if (writeobject(v, f, PRINT_RAW) != NULL)
+                       if (writeobject(v, f, PRINT_RAW) != 0)
                                err_clear();
                        DECREF(v);
                }
index 84fc5525b5a2040a3d61d55d2b48ce03dd264666..85d1c661459620be1924f24fdaa96451153081f3 100644 (file)
@@ -606,8 +606,11 @@ long_compare(a, b)
                        ;
                if (i < 0)
                        sign = 0;
-               else
+               else {
                        sign = (int)a->ob_digit[i] - (int)b->ob_digit[i];
+                       if (a->ob_size < 0)
+                               sign = -sign;
+               }
        }
        return sign < 0 ? -1 : sign > 0 ? 1 : 0;
 }
index 8e68e286f5e63f8634ece4b33b242ac9875c4824..268db00691872cd49a30c2263003d9521c705e1c 100644 (file)
@@ -1,6 +1,6 @@
 /***********************************************************
-Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
-Netherlands.
+Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
+Amsterdam, The Netherlands.
 
                         All Rights Reserved
 
@@ -48,86 +48,133 @@ extern int errno;
 #define TYPE_CODE      'C'
 #define TYPE_UNKNOWN   '?'
 
-#define wr_byte(c, fp) putc((c), (fp))
+typedef struct {
+       FILE *fp;
+       /* If fp == NULL, the following are valid: */
+       object *str;
+       char *ptr;
+       char *end;
+} WFILE;
 
-void
-wr_short(x, fp)
+#define w_byte(c, p) if (((p)->fp)) putc((c), (p)->fp); \
+                     else if ((p)->ptr != (p)->end) *(p)->ptr++ = (c); \
+                          else w_more(c, p)
+
+static void
+w_more(c, p)
+       char c;
+       WFILE *p;
+{
+       int size, newsize;
+       if (p->str == NULL)
+               return; /* An error already occurred */
+       size = getstringsize(p->str);
+       newsize = size + 1024;
+       if (resizestring(&p->str, newsize) != 0) {
+               p->ptr = p->end = NULL;
+       }
+       else {
+               p->ptr = GETSTRINGVALUE((stringobject *)p->str) + size;
+               p->end = GETSTRINGVALUE((stringobject *)p->str) + newsize;
+               *p->ptr++ = c;
+       }
+}
+
+static void
+w_string(s, n, p)
+       char *s;
+       int n;
+       WFILE *p;
+{
+       if (p->fp != NULL) {
+               fwrite(s, 1, n, p->fp);
+       }
+       else {
+               while (--n >= 0) {
+                       w_byte(*s, p);
+                       s++;
+               }
+       }
+}
+
+static void
+w_short(x, p)
        int x;
-       FILE *fp;
+       WFILE *p;
 {
-       wr_byte( x      & 0xff, fp);
-       wr_byte((x>> 8) & 0xff, fp);
+       w_byte( x      & 0xff, p);
+       w_byte((x>> 8) & 0xff, p);
 }
 
-void
-wr_long(x, fp)
+static void
+w_long(x, p)
        long x;
-       FILE *fp;
+       WFILE *p;
 {
-       wr_byte((int)( x      & 0xff), fp);
-       wr_byte((int)((x>> 8) & 0xff), fp);
-       wr_byte((int)((x>>16) & 0xff), fp);
-       wr_byte((int)((x>>24) & 0xff), fp);
+       w_byte((int)( x      & 0xff), p);
+       w_byte((int)((x>> 8) & 0xff), p);
+       w_byte((int)((x>>16) & 0xff), p);
+       w_byte((int)((x>>24) & 0xff), p);
 }
 
-void
-wr_object(v, fp)
+static void
+w_object(v, p)
        object *v;
-       FILE *fp;
+       WFILE *p;
 {
        long i, n;
        
        if (v == NULL)
-               wr_byte(TYPE_NULL, fp);
+               w_byte(TYPE_NULL, p);
        else if (v == None)
-               wr_byte(TYPE_NONE, fp);
+               w_byte(TYPE_NONE, p);
        else if (is_intobject(v)) {
-               wr_byte(TYPE_INT, fp);
-               wr_long(getintvalue(v), fp);
+               w_byte(TYPE_INT, p);
+               w_long(getintvalue(v), p);
        }
        else if (is_longobject(v)) {
                longobject *ob = (longobject *)v;
-               wr_byte(TYPE_LONG, fp);
+               w_byte(TYPE_LONG, p);
                n = ob->ob_size;
-               wr_long((long)n, fp);
+               w_long((long)n, p);
                if (n < 0)
                        n = -n;
                for (i = 0; i < n; i++)
-                       wr_short(ob->ob_digit[i], fp);
+                       w_short(ob->ob_digit[i], p);
        }
        else if (is_floatobject(v)) {
                extern void float_buf_repr PROTO((char *, floatobject *));
                char buf[256]; /* Plenty to format any double */
                float_buf_repr(buf, (floatobject *)v);
                n = strlen(buf);
-               wr_byte(TYPE_FLOAT, fp);
-               wr_byte((int)n, fp);
-               fwrite(buf, 1, (int)n, fp);
+               w_byte(TYPE_FLOAT, p);
+               w_byte((int)n, p);
+               w_string(buf, (int)n, p);
        }
        else if (is_stringobject(v)) {
-               wr_byte(TYPE_STRING, fp);
+               w_byte(TYPE_STRING, p);
                n = getstringsize(v);
-               wr_long(n, fp);
-               fwrite(getstringvalue(v), 1, (int)n, fp);
+               w_long(n, p);
+               w_string(getstringvalue(v), (int)n, p);
        }
        else if (is_tupleobject(v)) {
-               wr_byte(TYPE_TUPLE, fp);
+               w_byte(TYPE_TUPLE, p);
                n = gettuplesize(v);
-               wr_long(n, fp);
+               w_long(n, p);
                for (i = 0; i < n; i++) {
-                       wr_object(gettupleitem(v, (int)i), fp);
+                       w_object(gettupleitem(v, (int)i), p);
                }
        }
        else if (is_listobject(v)) {
-               wr_byte(TYPE_LIST, fp);
+               w_byte(TYPE_LIST, p);
                n = getlistsize(v);
-               wr_long(n, fp);
+               w_long(n, p);
                for (i = 0; i < n; i++) {
-                       wr_object(getlistitem(v, (int)i), fp);
+                       w_object(getlistitem(v, (int)i), p);
                }
        }
        else if (is_dictobject(v)) {
-               wr_byte(TYPE_DICT, fp);
+               w_byte(TYPE_DICT, p);
                /* This one is NULL object terminated! */
                n = getdictsize(v);
                for (i = 0; i < n; i++) {
@@ -135,58 +182,96 @@ wr_object(v, fp)
                        key = getdict2key(v, (int)i);
                        if (key != NULL) {
                                val = dict2lookup(v, key); /* Can't be NULL */
-                               wr_object(key, fp);
-                               wr_object(val, fp);
+                               w_object(key, p);
+                               w_object(val, p);
                        }
                }
-               wr_object((object *)NULL, fp);
+               w_object((object *)NULL, p);
        }
        else if (is_codeobject(v)) {
                codeobject *co = (codeobject *)v;
-               wr_byte(TYPE_CODE, fp);
-               wr_object((object *)co->co_code, fp);
-               wr_object(co->co_consts, fp);
-               wr_object(co->co_names, fp);
-               wr_object(co->co_filename, fp);
+               w_byte(TYPE_CODE, p);
+               w_object((object *)co->co_code, p);
+               w_object(co->co_consts, p);
+               w_object(co->co_names, p);
+               w_object(co->co_filename, p);
        }
        else {
-               wr_byte(TYPE_UNKNOWN, fp);
+               w_byte(TYPE_UNKNOWN, p);
        }
 }
 
-#define rd_byte(fp) getc(fp)
+void
+wr_long(x, fp)
+       long x;
+       FILE *fp;
+{
+       WFILE wf;
+       wf.fp = fp;
+       w_long(x, &wf);
+}
 
-int
-rd_short(fp)
+void
+wr_object(x, fp)
+       object *x;
        FILE *fp;
+{
+       WFILE wf;
+       wf.fp = fp;
+       w_object(x, &wf);
+}
+
+typedef WFILE RFILE; /* Same struct with different invariants */
+
+#define r_byte(p) ((p)->fp ? getc((p)->fp) \
+                         : ((p)->ptr != (p)->end) ? *(p)->ptr++ : EOF)
+
+static int
+r_string(s, n, p)
+       char *s;
+       int n;
+       RFILE *p;
+{
+       if (p->fp != NULL)
+               return fread(s, 1, n, p->fp);
+       if (p->end - p->ptr < n)
+               n = p->end - p->ptr;
+       memcpy(s, p->ptr, n);
+       p->ptr += n;
+       return n;
+}
+
+static int
+r_short(p)
+       RFILE *p;
 {
        register short x;
-       x = rd_byte(fp);
-       x |= rd_byte(fp) << 8;
+       x = r_byte(p);
+       x |= r_byte(p) << 8;
        /* XXX If your short is > 16 bits, add sign-extension here!!! */
        return x;
 }
 
-long
-rd_long(fp)
-       FILE *fp;
+static long
+r_long(p)
+       RFILE *p;
 {
        register long x;
-       x = rd_byte(fp);
-       x |= (long)rd_byte(fp) << 8;
-       x |= (long)rd_byte(fp) << 16;
-       x |= (long)rd_byte(fp) << 24;
+       x = r_byte(p);
+       x |= (long)r_byte(p) << 8;
+       x |= (long)r_byte(p) << 16;
+       x |= (long)r_byte(p) << 24;
        /* XXX If your long is > 32 bits, add sign-extension here!!! */
        return x;
 }
 
-object *
-rd_object(fp)
-       FILE *fp;
+static object *
+r_object(p)
+       RFILE *p;
 {
        object *v;
        long i, n;
-       int type = rd_byte(fp);
+       int type = r_byte(p);
        
        switch (type) {
        
@@ -202,20 +287,20 @@ rd_object(fp)
                return None;
        
        case TYPE_INT:
-               return newintobject(rd_long(fp));
+               return newintobject(r_long(p));
        
        case TYPE_LONG:
                {
                        int size;
                        longobject *ob;
-                       n = rd_long(fp);
+                       n = r_long(p);
                        size = n<0 ? -n : n;
                        ob = alloclongobject(size);
                        if (ob == NULL)
                                return NULL;
                        ob->ob_size = n;
                        for (i = 0; i < size; i++)
-                               ob->ob_digit[i] = rd_short(fp);
+                               ob->ob_digit[i] = r_short(p);
                        return (object *)ob;
                }
        
@@ -225,8 +310,8 @@ rd_object(fp)
                        char buf[256];
                        double res;
                        char *end;
-                       n = rd_byte(fp);
-                       if (fread(buf, 1, (int)n, fp) != n) {
+                       n = r_byte(p);
+                       if (r_string(buf, (int)n, p) != n) {
                                err_setstr(EOFError,
                                        "EOF read where object expected");
                                return NULL;
@@ -247,10 +332,10 @@ rd_object(fp)
                }
        
        case TYPE_STRING:
-               n = rd_long(fp);
+               n = r_long(p);
                v = newsizedstringobject((char *)NULL, n);
                if (v != NULL) {
-                       if (fread(getstringvalue(v), 1, (int)n, fp) != n) {
+                       if (r_string(getstringvalue(v), (int)n, p) != n) {
                                DECREF(v);
                                v = NULL;
                                err_setstr(EOFError,
@@ -260,21 +345,21 @@ rd_object(fp)
                return v;
        
        case TYPE_TUPLE:
-               n = rd_long(fp);
+               n = r_long(p);
                v = newtupleobject((int)n);
                if (v == NULL)
                        return v;
                for (i = 0; i < n; i++)
-                       settupleitem(v, (int)i, rd_object(fp));
+                       settupleitem(v, (int)i, r_object(p));
                return v;
        
        case TYPE_LIST:
-               n = rd_long(fp);
+               n = r_long(p);
                v = newlistobject((int)n);
                if (v == NULL)
                        return v;
                for (i = 0; i < n; i++)
-                       setlistitem(v, (int)i, rd_object(fp));
+                       setlistitem(v, (int)i, r_object(p));
                return v;
        
        case TYPE_DICT:
@@ -283,10 +368,10 @@ rd_object(fp)
                        return NULL;
                for (;;) {
                        object *key, *val;
-                       key = rd_object(fp);
+                       key = r_object(p);
                        if (key == NULL)
                                break;
-                       val = rd_object(fp);
+                       val = r_object(p);
                        dict2insert(v, key, val);
                        DECREF(key);
                        XDECREF(val);
@@ -295,10 +380,10 @@ rd_object(fp)
        
        case TYPE_CODE:
                {
-                       object *code = rd_object(fp);
-                       object *consts = rd_object(fp);
-                       object *names = rd_object(fp);
-                       object *filename = rd_object(fp);
+                       object *code = r_object(p);
+                       object *consts = r_object(p);
+                       object *names = r_object(p);
+                       object *filename = r_object(p);
                        if (!err_occurred()) {
                                v = (object *) newcodeobject(code,
                                                consts, names, filename);
@@ -320,39 +405,113 @@ rd_object(fp)
        }
 }
 
+long
+rd_long(fp)
+       FILE *fp;
+{
+       RFILE rf;
+       rf.fp = fp;
+       return r_long(&rf);
+}
+
+object *
+rd_object(fp)
+       FILE *fp;
+{
+       RFILE rf;
+       rf.fp = fp;
+       return r_object(&rf);
+}
+
 /* And an interface for Python programs... */
 
 static object *
-dump(self, args)
+marshal_dump(self, args)
        object *self;
        object *args;
 {
+       WFILE wf;
+       object *x;
        object *f;
-       if (args == NULL || !is_tupleobject(args) || gettuplesize(args) != 2) {
-               err_badarg();
+       if (!getargs(args, "(OO)", &x, &f))
                return NULL;
-       }
-       f = gettupleitem(args, 1);
-       if (f == NULL || !is_fileobject(f)) {
-               err_badarg();
+       if (!is_fileobject(f)) {
+               err_setstr(TypeError, "marshal.dump() 2nd arg must be file");
                return NULL;
        }
-       wr_object(gettupleitem(args, 0), getfilefile(f));
+       wf.fp = getfilefile(f);
+       wf.str = NULL;
+       wf.ptr = wf.end = NULL;
+       w_object(x, &wf);
        INCREF(None);
        return None;
 }
 
 static object *
-load(self, f)
+marshal_load(self, args)
        object *self;
-       object *f;
+       object *args;
 {
+       RFILE rf;
+       object *f;
        object *v;
-       if (f == NULL || !is_fileobject(f)) {
-               err_badarg();
+       if (!getargs(args, "O", &f))
+               return NULL;
+       if (!is_fileobject(f)) {
+               err_setstr(TypeError, "marshal.load() arg must be file");
                return NULL;
        }
-       v = rd_object(getfilefile(f));
+       rf.fp = getfilefile(f);
+       rf.str = NULL;
+       rf.ptr = rf.end = NULL;
+       err_clear();
+       v = r_object(&rf);
+       if (err_occurred()) {
+               XDECREF(v);
+               v = NULL;
+       }
+       return v;
+}
+
+static object *
+marshal_dumps(self, args)
+       object *self;
+       object *args;
+{
+       WFILE wf;
+       object *x;
+       if (!getargs(args, "O", &x))
+               return NULL;
+       wf.fp = NULL;
+       wf.str = newsizedstringobject((char *)NULL, 50);
+       if (wf.str == NULL)
+               return NULL;
+       wf.ptr = GETSTRINGVALUE((stringobject *)wf.str);
+       wf.end = wf.ptr + getstringsize(wf.str);
+       w_object(x, &wf);
+       if (wf.str != NULL)
+               resizestring(&wf.str,
+                   (int) (wf.ptr - GETSTRINGVALUE((stringobject *)wf.str)));
+       return wf.str;
+}
+
+static object *
+marshal_loads(self, args)
+       object *self;
+       object *args;
+{
+       RFILE rf;
+       object *v;
+       char *s;
+       int n;
+       if (!getargs(args, "s#", &s, &n))
+               return NULL;
+       rf.fp = NULL;
+       rf.str = args;
+       rf.ptr = s;
+       rf.end = s + n;
+       err_clear();
+       v = r_object(&rf);
        if (err_occurred()) {
                XDECREF(v);
                v = NULL;
@@ -361,8 +520,10 @@ load(self, f)
 }
 
 static struct methodlist marshal_methods[] = {
-       {"dump",        dump},
-       {"load",        load},
+       {"dump",        marshal_dump},
+       {"load",        marshal_load},
+       {"dumps",       marshal_dumps},
+       {"loads",       marshal_loads},
        {NULL,          NULL}           /* sentinel */
 };