]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Another bulky set of minor changes.
authorGuido van Rossum <guido@python.org>
Mon, 2 Jan 1995 19:30:30 +0000 (19:30 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 2 Jan 1995 19:30:30 +0000 (19:30 +0000)
Note addition of gethostbyaddr() and improved repr() for sockets,
renaming of md5.md5() to md5.new(), and fixing of leaks in threads.

18 files changed:
Modules/Makefile.pre.in
Modules/_tkinter.c
Modules/arraymodule.c
Modules/audioop.c
Modules/config.c.in
Modules/imageop.c
Modules/makesetup
Modules/mathmodule.c
Modules/md5module.c
Modules/mpzmodule.c
Modules/parsermodule.c
Modules/posixmodule.c
Modules/rgbimgmodule.c
Modules/rotormodule.c
Modules/signalmodule.c
Modules/socketmodule.c
Modules/threadmodule.c
Modules/timemodule.c

index ae6e8deab73c35d37781e45a07c321150e04f643..5662ea5aa624678d3d6a70f84ebbba871ccccf7d 100644 (file)
@@ -8,8 +8,8 @@
 
 # === Variables set by makesetup ===
 
-MODOBJS=       @MODOBJS@
-MODLIBS=       @MODLIBS@
+MODOBJS=       _MODOBJS_
+MODLIBS=       _MODLIBS_
 
 # === Definitions added by makesetup ===
 
@@ -30,15 +30,18 @@ LIBC=               @LIBC@
 # Machine-dependent subdirectories
 MACHDEP=       @MACHDEP@
 
-# Install prefix, may be changed by configure
-prefix=                /usr/local
+# Install prefix for architecture-independent files
+prefix=                @prefix@
+
+# Install prefix for architecture-dependent files
+exec_prefix=   @exec_prefix@
 
 # Symbols used for using shared libraries
 SO=            @SO@
 LDSHARED=      @LDSHARED@
 CCSHARED=      @CCSHARED@
 LINKFORSHARED= @LINKFORSHARED@
-DESTSHARED=    $(prefix)/lib/python/$(MACHDEP)
+DESTSHARED=    $(exec_prefix)/lib/python/$(MACHDEP)
 
 
 # === Variables that are customizable by hand ===
@@ -150,6 +153,7 @@ yuvconvert.o: yuvconvert.c
 # Rules to build and install all shared modules
 sharedmods:    $(SHAREDMODS)
 sharedinstall: $(SHAREDMODS)
-               for i in $(SHAREDMODS); do mv $$i $(DESTSHARED)/$$i; done
+               for i in dummy $(SHAREDMODS); do \
+                   if test -f $$i; then mv $$i $(DESTSHARED)/$$i; fi; done
 
 # Stuff is appended here by makesetup and make depend
index 6104960d8c7df73249d1abdcc4d7f867d07de06f..77b1809f46c10e90adfa1f62c893ae143a66614b 100644 (file)
@@ -41,6 +41,7 @@ static int quitMainLoop = 0;
 static int errorInCmd = 0;
 static PyObject *excInCmd;
 static PyObject *valInCmd;
+static PyObject *trbInCmd;
 
 static PyObject *
 Tkinter_Error (v)
@@ -55,7 +56,7 @@ PythonCmd_Error (interp)
      Tcl_Interp *interp;
 {
   errorInCmd = 1;
-  PyErr_GetAndClear (&excInCmd, &valInCmd);
+  PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
   return TCL_ERROR;
 }
 
@@ -759,7 +760,7 @@ FileHandler (clientData, mask)
   if (res == NULL)
     {
       errorInCmd = 1;
-      PyErr_GetAndClear (&excInCmd, &valInCmd);
+      PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
     }
   Py_XDECREF (res);
 }
@@ -964,9 +965,10 @@ TimerHandler (clientData)
   if (res == NULL)
     {
       errorInCmd = 1;
-      PyErr_GetAndClear (&excInCmd, &valInCmd);
+      PyErr_Fetch (&excInCmd, &valInCmd, &trbInCmd);
     }
-  Py_DECREF (res);
+  else
+    Py_DECREF (res);
 }
 
 static PyObject *
@@ -1020,7 +1022,8 @@ Tkapp_MainLoop (self, args)
   if (errorInCmd)
     {
       errorInCmd = 0;
-      PyErr_SetObject (excInCmd, valInCmd);
+      PyErr_Restore (excInCmd, valInCmd, trbInCmd);
+      excInCmd = valInCmd = trbInCmd = NULL;
       return NULL;
     }
   Py_INCREF (Py_None);
@@ -1173,7 +1176,8 @@ EventHook ()
   if (errorInCmd)              /* XXX Reset tty */
     {
       errorInCmd = 0;
-      PyErr_SetObject (excInCmd, valInCmd);
+      PyErr_Restore (excInCmd, valInCmd, trbInCmd);
+      excInCmd = valInCmd = trbInCmd = NULL;
       PyErr_Print ();
      }
   if (tk_NumMainWindows > 0)
index 0dfe4f617349ad8d6d1e1cfee46c0c450070b5d2..2584b03aa1c8bb60e365426c417f1a40581e81f9 100644 (file)
@@ -239,10 +239,8 @@ newarrayobject(size, descr)
        int size;
        struct arraydescr *descr;
 {
-       int i;
        arrayobject *op;
        size_t nbytes;
-       int itemsize;
        if (size < 0) {
                err_badcall();
                return NULL;
@@ -308,7 +306,6 @@ ins1(self, where, v)
        int where;
        object *v;
 {
-       int i;
        char *items;
        if (v == NULL) {
                err_badcall();
@@ -366,7 +363,6 @@ static void
 array_dealloc(op)
        arrayobject *op;
 {
-       int i;
        if (op->ob_item != NULL)
                DEL(op->ob_item);
        DEL(op);
@@ -422,7 +418,6 @@ array_slice(a, ilow, ihigh)
        int ilow, ihigh;
 {
        arrayobject *np;
-       int i;
        if (ilow < 0)
                ilow = 0;
        else if (ilow > a->ob_size)
@@ -447,7 +442,6 @@ array_concat(a, bb)
        object *bb;
 {
        int size;
-       int i;
        arrayobject *np;
        if (!is_arrayobject(bb)) {
                err_badarg();
@@ -475,7 +469,7 @@ array_repeat(a, n)
        arrayobject *a;
        int n;
 {
-       int i, j;
+       int i;
        int size;
        arrayobject *np;
        char *p;
@@ -504,7 +498,6 @@ array_ass_slice(a, ilow, ihigh, v)
        char *item;
        int n; /* Size of replacement array */
        int d; /* Change in size */
-       int k; /* Loop index */
 #define b ((arrayobject *)v)
        if (v == NULL)
                n = 0;
index e3297a3c44018261a858033e840ba6a2d80c3e9b..22e309dc7ab9a78f98bfa73d415ac5fddc2d2e08 100644 (file)
@@ -136,9 +136,6 @@ int sample;
     }
 /* End of code taken from sox */
 
-/* ADPCM-3 step variation table */
-static float newstep[5] = { 0.8, 0.9, 1.0, 1.75, 1.75 };
-
 /* Intel ADPCM step variation table */
 static int indexTable[16] = {
     -1, -1, -1, -1, 2, 4, 6, 8,
@@ -603,7 +600,7 @@ audioop_cross(self, args)
     signed char *cp;
     int len, size, val;
     int i;
-    int cross, prevval, ncross;
+    int prevval, ncross;
 
     if ( !getargs(args, "(s#i)", &cp, &len, &size) )
       return 0;
@@ -1117,7 +1114,7 @@ audioop_adpcm2lin(self, args)
 {
     signed char *cp;
     signed char *ncp;
-    int len, size, val, valpred, step, delta, index, sign, vpdiff;
+    int len, size, valpred, step, delta, index, sign, vpdiff;
     object *rv, *str, *state;
     int i, inputbuffer, bufferstep;
 
index fb8b49bc930979813f86cb931d81d0581418455e..2be3e37154f2ea94dfd65058dc1eb1128a4753fc 100644 (file)
@@ -182,6 +182,7 @@ getpythonpath()
 /* -- ADDMODULE MARKER 1 -- */
 
 extern void initmarshal();
+extern void initimp();
 
 struct {
        char *name;
@@ -193,6 +194,9 @@ struct {
        /* This module "lives in" with marshal.c */
        {"marshal", initmarshal},
 
+       /* This lives it with import.c */
+       {"imp", initimp},
+
        /* These entries are here for sys.builtin_module_names */
        {"__main__", NULL},
        {"__builtin__", NULL},
index 77da52e78e5437db81d2106b6fb546a59130fefd..d3d14e4362ebff1a8c3f65cdb31b62dc6e76accd 100644 (file)
@@ -133,7 +133,7 @@ imageop_tovideo(self, args)
 {
     int maxx, maxy, x, y, len;
     int i;
-    unsigned char *cp, *ncp, cdata;
+    unsigned char *cp, *ncp;
     int width;
     object *rv;
    
@@ -404,9 +404,8 @@ imageop_mono2grey(self, args)
 {
     int v0, v1, x, y, len, nlen;
     unsigned char *cp, *ncp;
-    unsigned char ovalue;
     object *rv;
-    int i, bit, value;
+    int i, bit;
     
     if ( !getargs(args, "(s#iiii)", &cp, &len, &x, &y, &v0, &v1) )
       return 0;
@@ -444,7 +443,6 @@ imageop_grey22grey(self, args)
 {
     int x, y, len, nlen;
     unsigned char *cp, *ncp;
-    unsigned char ovalue;
     object *rv;
     int i, pos, value, nvalue;
     
@@ -482,7 +480,6 @@ imageop_grey42grey(self, args)
 {
     int x, y, len, nlen;
     unsigned char *cp, *ncp;
-    unsigned char ovalue;
     object *rv;
     int i, pos, value, nvalue;
     
index 0da94651b9fc8cb3d17ac201c6d7599862e5f3d5..1feae60df423a79dd87a05aa923642141d2e07e9 100755 (executable)
@@ -28,9 +28,9 @@
 #
 # Copying Makefile.pre to Makefile:
 # - insert an identifying comment at the start
-# - replace @MODOBJS@ by the list of objects from Setup (except for
+# - 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
+# - replace _MODLIBS_ by the list of libraries from Setup
 # - for each object file mentioned in Setup, append a rule
 #   '<file>.o: <file>.c; <build commands>' to the end of the Makefile
 # - for each module mentioned in Setup, append a rule
@@ -227,8 +227,8 @@ sed -e 's/[         ]*#.*//' -e '/^[        ]*$/d' |
                echo "1i\\" >$sedf
                str="# Generated automatically from $makepre by makesetup."
                echo "$str" >>$sedf
-               echo "s%@MODOBJS@%$OBJS%" >>$sedf
-               echo "s%@MODLIBS@%$LIBS%" >>$sedf
+               echo "s%_MODOBJS_%$OBJS%" >>$sedf
+               echo "s%_MODLIBS_%$LIBS%" >>$sedf
                echo "/Definitions added by makesetup/a$NL$NL$DEFS" >>$sedf
                sed -f $sedf $makepre >Makefile
                cat $rulesf >>Makefile
index 5663ba2294156434b639bb4e7d790dc5ab07aaa6..a1357dac8694f7fdcc9cf477498cca2b3d75f273 100644 (file)
@@ -121,7 +121,9 @@ FUNC1(math_exp, exp)
 FUNC1(math_fabs, fabs)
 FUNC1(math_floor, floor)
 FUNC2(math_fmod, fmod)
+#ifdef HAVE_HYPOT
 FUNC2(math_hypot, hypot)
+#endif
 FUNC1(math_log, log)
 FUNC1(math_log10, log10)
 #ifdef MPW_3_1 /* This hack is needed for MPW 3.1 but not for 3.2 ... */
@@ -215,7 +217,9 @@ static struct methodlist math_methods[] = {
        {"floor", math_floor},
        {"fmod", math_fmod},
        {"frexp", math_frexp},
+#ifdef HAVE_HYPOT
        {"hypot", math_hypot},
+#endif
        {"ldexp", math_ldexp},
        {"log", math_log},
        {"log10", math_log10},
index 68d52f46dc93894ab1f2a232f8a414d34f89680e..9909d2cb4a9f956957dcc4540e655243df648d0b 100644 (file)
@@ -161,7 +161,7 @@ static typeobject MD5type = {
 /* MD5 functions */
 
 static object *
-MD5_md5(self, args)
+MD5_new(self, args)
        object *self;
        object *args;
 {
@@ -188,7 +188,8 @@ MD5_md5(self, args)
 /* List of functions exported by this module */
 
 static struct methodlist md5_functions[] = {
-       {"md5",                 (method)MD5_md5},
+       {"new",                 (method)MD5_new},
+       {"md5",                 (method)MD5_new}, /* Backward compatibility */
        {NULL,                  NULL}            /* Sentinel */
 };
 
index 9d0bdb086b3d92def01ac7427cf8fa1d4daefb94..0067397452004749dd02927a92b42b6650615495 100644 (file)
@@ -35,6 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 #include "allobjects.h"
 #include "modsupport.h"                /* For getargs() etc. */
+#include "rename1.h"
 #include <assert.h>
 #include <sys/types.h>         /* For size_t */
 
@@ -573,14 +574,26 @@ mpz_div_and_mod(a, b)
 } /* mpz_div_and_mod() */
 
 static object *
-mpz_power(a, b)
+mpz_power(a, b, m)
        mpzobject *a;
        mpzobject *b;
+        mpzobject *m;
 {
        mpzobject *z;
        int cmpres;
        long int longtmp1, longtmp2;
 
+       if ((object *)m!=Py_None)
+         {
+           mpzobject *z2;
+           INCREF(Py_None);
+           z=mpz_power(a, b, (mpzobject *)Py_None);
+           DECREF(Py_None);
+           if (z==NULL) return(z);
+           z2=mpz_remainder(z, m);
+           DECREF(z);
+           return((object *)z2);
+         }         
 
        if ((cmpres = mpz_cmp_ui(&b->mpz, (unsigned long int)0)) == 0) {
                /* the gnu-mp lib sets pow(0,0) to 0, we to 1 */
@@ -1607,6 +1620,7 @@ mpz_repr(v)
 
 #define UF (unaryfunc)
 #define BF (binaryfunc)
+#define TF (ternaryfunc)
 #define IF (inquiry)
 #define CF (coercion)
 
@@ -1617,7 +1631,7 @@ static number_methods mpz_as_number = {
        BF mpz_divide,          /*nb_divide*/
        BF mpz_remainder,       /*nb_remainder*/
        BF mpz_div_and_mod,     /*nb_divmod*/
-       BF mpz_power,           /*nb_power*/
+       TF mpz_power,           /*nb_power*/
        UF mpz_negative,        /*nb_negative*/
        UF mpz_positive,        /*tp_positive*/
        UF mpz_absolute,        /*tp_absolute*/
@@ -1779,15 +1793,15 @@ initmpz()
 
        /* create some frequently used constants */
        if ((mpz_value_zero = newmpzobject()) == NULL)
-               fatal("initmpz: can't initialize mpz contstants");
+               fatal("initmpz: can't initialize mpz constants");
        mpz_set_ui(&mpz_value_zero->mpz, (unsigned long int)0);
 
        if ((mpz_value_one = newmpzobject()) == NULL)
-               fatal("initmpz: can't initialize mpz contstants");
+               fatal("initmpz: can't initialize mpz constants");
        mpz_set_ui(&mpz_value_one->mpz, (unsigned long int)1);
 
        if ((mpz_value_mone = newmpzobject()) == NULL)
-               fatal("initmpz: can't initialize mpz contstants");
+               fatal("initmpz: can't initialize mpz constants");
        mpz_set_si(&mpz_value_mone->mpz, (long)-1);
 
 } /* initmpz() */
index 04db26ee6fe2c895b2b49ee8dfad177d7c22ad6f..8e3d96bf58e470a45145d686870e823f0c0ac507 100644 (file)
@@ -78,7 +78,6 @@ parser_parsefile(self, args)
        char *filename;
        FILE *fp;
        node *n = NULL;
-       int err;
        object *res;
        if (!getargs(args, "s", &filename))
                return NULL;
index c2678eb5b21ade925cd2125ffea665f8eca54574..3e3f9ccc349c4e9fc6b77a0b080cbbbea63ffe8e 100644 (file)
@@ -97,23 +97,22 @@ extern int symlink();
 #define MAXPATHLEN 1024
 #endif /* MAXPATHLEN */
 
-/* unistd.h defines _POSIX_VERSION on POSIX.1 systems.  */
-#if defined(DIRENT) || defined(_POSIX_VERSION)
+#ifdef HAVE_DIRENT_H
 #include <dirent.h>
-#define NLENGTH(dirent) (strlen((dirent)->d_name))
-#else /* not (DIRENT or _POSIX_VERSION) */
+#define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
 #define dirent direct
-#define NLENGTH(dirent) ((dirent)->d_namlen)
-#ifdef SYSNDIR
+#define NAMLEN(dirent) (dirent)->d_namlen
+#ifdef HAVE_SYS_NDIR_H
 #include <sys/ndir.h>
-#endif /* SYSNDIR */
-#ifdef SYSDIR
+#endif
+#ifdef HAVE_SYS_DIR_H
 #include <sys/dir.h>
-#endif /* SYSDIR */
-#ifdef NDIR
+#endif
+#ifdef HAVE_NDIR_H
 #include <ndir.h>
-#endif /* NDIR */
-#endif /* not (DIRENT or _POSIX_VERSION) */
+#endif
+#endif
 
 #ifdef NT
 #include <direct.h>
@@ -406,7 +405,7 @@ posix_listdir(self, args)
                return NULL;
        }
        while ((ep = readdir(dirp)) != NULL) {
-               v = newstringobject(ep->d_name);
+               v = newsizedstringobject(ep->d_name, NAMLEN(ep));
                if (v == NULL) {
                        DECREF(d);
                        d = NULL;
index de888eb96cff226a32d4710d76feb92715f21b16..62e9e0b35b7a8ffd535bfac7e58114df9d7294a5 100644 (file)
@@ -270,7 +270,7 @@ longimagedata(self, args)
     long *starttab, *lengthtab;
     FILE *inf;
     IMAGE image;
-    int y, z, pos, len, tablen;
+    int y, z, tablen;
     int xsize, ysize, zsize;
     int bpp, rle, cur, badorder;
     int rlebuflen;
index a7529a3a0c6344f11a1ece3acd82a78dd69235b9..cb70612a33b573c2b3532f9c3eb74bb21368e568 100644 (file)
@@ -588,6 +588,7 @@ static void RTR_d_region(r, beg, len, doinit)
     (list k1 (logior 1 k2) k3 k4 k5)))*/
 /* This is done in set_key() above */
 
+#if 0
 /*(defun encrypt-region (beg end key)
   "Interactivly encrypt the region"
   (interactive "r\nsKey:")
@@ -611,6 +612,7 @@ static void decrypt_region(r, region, len)
 {
        RTR_d_region(r,region,len,TRUE);
 }
+#endif
 
 /* Rotor methods */
 
@@ -726,7 +728,6 @@ PyRotor_SetKey(self, args)
        PyRotorObject *self;
        PyObject * args;
 {
-       char *key;
        char *string;
 
        if (PyArg_Parse(args,"s",&string))
index bbb077f9769a361f06f71c6d6637aa1c1f57ebc8..cf921a74612acf2ccfe593371dcc7ac55aeb0da4 100644 (file)
@@ -22,7 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 ******************************************************************/
 
-/* Signal module -- many thanks to Lance Ellinghouse */
+/* Signal module -- many thanks to Lance Ellinghaus */
 
 #include "Python.h"
 #include "intrcheck.h"
@@ -34,6 +34,11 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 #define SIG_ERR ((RETSIGTYPE (*)())-1)
 #endif
 
+#ifndef NSIG
+#define NSIG (_SIGMAX + 1)     /* For QNX */
+#endif
+
+
 /*
    NOTES ON THE INTERACTION BETWEEN SIGNALS AND THREADS
 
@@ -119,7 +124,6 @@ PySignal_Alarm(self, args)
        PyObject *args;
 {
        int t;
-       int rtn;
        if (!PyArg_Parse(args, "i", &t))
                return (PyObject *)NULL;
        /* alarm() returns the number of seconds remaining */
@@ -218,7 +222,6 @@ void
 initsignal()
 {
        PyObject *m, *d, *x;
-       PyObject *b_dict;
        int i;
 
 #ifdef WITH_THREAD
index bda7bf1569e4e792d50e12992cde006e083826d7..39aa81e6490e3b5bc3e80972b688bae23e8133a1 100644 (file)
@@ -38,6 +38,7 @@ Interface:
 
 - socket.gethostname() --> host name (string)
 - socket.gethostbyname(hostname) --> host IP address (string: 'dd.dd.dd.dd')
+- socket.gethostbyaddr(IP address) --> (hostname, [alias, ...], [IP addr, ...])
 - socket.getservbyname(servername, protocolname) --> port number
 - socket.socket(family, type [, proto]) --> new socket object
 - family and type constants from <socket.h> are accessed as socket.AF_INET etc.
@@ -66,6 +67,7 @@ Socket methods:
 - s.setblocking(1 | 0) --> Py_None
 - s.shutdown(how) --> Py_None
 - s.close() --> Py_None
+- repr(s) --> "<socket object, fd=%d, family=%d, type=%d, protocol=%d>"
 
 */
 
@@ -89,6 +91,11 @@ Socket methods:
 #undef AF_UNIX
 #endif
 
+#ifndef O_NDELAY
+#define O_NDELAY O_NONBLOCK    /* For QNX only? */
+#endif
+
+
 /* Here we have some hacks to choose between K&R or ANSI style function
    definitions.  For NT to build this as an extension module (ie, DLL)
    it must be compiled by the C++ compiler, as it takes the address of
@@ -177,6 +184,12 @@ typedef struct {
        int sock_family;        /* Address family, e.g., AF_INET */
        int sock_type;          /* Socket type, e.g., SOCK_STREAM */
        int sock_proto;         /* Protocol type, usually 0 */
+       union sock_addr {
+               struct sockaddr_in in;
+#ifdef AF_UNIX
+               struct sockaddr_un un;
+#endif
+       } sock_addr;
 } PySocketSockObject;
 
 
@@ -194,7 +207,7 @@ staticforward PyTypeObject PySocketSock_Type;
    in NEWOBJ()). */
 
 static PySocketSockObject *
-BUILD_FUNC_DEF_4(PySocketSock_New, int, fd, int, family, int, type, int, proto)
+BUILD_FUNC_DEF_4(PySocketSock_New,int,fd, int,family, int,type, int,proto)
 {
        PySocketSockObject *s;
        s = PyObject_NEW(PySocketSockObject, &PySocketSock_Type);
@@ -215,11 +228,17 @@ BUILD_FUNC_DEF_4(PySocketSock_New, int, fd, int, family, int, type, int, proto)
    an error occurred; then an exception is raised. */
 
 static int
-BUILD_FUNC_DEF_2(setipaddr, char*, name, struct sockaddr_in *, addr_ret)
+BUILD_FUNC_DEF_2(setipaddr, char*,name, struct sockaddr_in *,addr_ret)
 {
        struct hostent *hp;
        int d1, d2, d3, d4;
        char ch;
+#ifdef HAVE_GETHOSTBYNAME_R
+       struct hostent hp_allocated;
+       char buf[1001];
+       int buf_len = (sizeof buf) - 1;
+       int errnop;
+#endif /* HAVE_GETHOSTBYNAME_R */
 
        if (name[0] == '\0') {
                addr_ret->sin_addr.s_addr = INADDR_ANY;
@@ -237,11 +256,22 @@ BUILD_FUNC_DEF_2(setipaddr, char*, name, struct sockaddr_in *, addr_ret)
                        ((long) d3 << 8) | ((long) d4 << 0));
                return 4;
        }
+#ifdef HAVE_GETHOSTBYNAME_R
        Py_BEGIN_ALLOW_THREADS
-       hp = gethostbyname(name);
+       hp = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
        Py_END_ALLOW_THREADS
+#else /* not HAVE_GETHOSTBYNAME_R */
+       hp = gethostbyname(name);
+#endif /* HAVE_GETHOSTBYNAME_R */
+
        if (hp == NULL) {
+#ifndef NT
+               /* Let's get real error message to return */
+               extern int h_errno;
+               PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
+#else
                PyErr_SetString(PySocket_Error, "host not found");
+#endif
                return -1;
        }
        memcpy((char *) &addr_ret->sin_addr, hp->h_addr, hp->h_length);
@@ -272,7 +302,7 @@ BUILD_FUNC_DEF_1(makeipaddr, struct sockaddr_in *,addr)
 
 /*ARGSUSED*/
 static PyObject *
-BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *, addr, int, addrlen)
+BUILD_FUNC_DEF_2(makesockaddr,struct sockaddr *,addr, int,addrlen)
 {
        if (addrlen == 0) {
                /* No address -- may be recvfrom() from known socket */
@@ -323,36 +353,38 @@ getsockaddrarg,PySocketSockObject *,s, PyObject *,args, struct sockaddr **,addr_
 #ifdef AF_UNIX
        case AF_UNIX:
        {
-               static struct sockaddr_un addr;
+               struct sockaddr_un* addr;
                char *path;
                int len;
+               addr = (struct sockaddr_un* )&(s->sock_addr).un;
                if (!PyArg_Parse(args, "s#", &path, &len))
                        return 0;
-               if (len > sizeof addr.sun_path) {
+               if (len > sizeof addr->sun_path) {
                        PyErr_SetString(PySocket_Error, "AF_UNIX path too long");
                        return 0;
                }
-               addr.sun_family = AF_UNIX;
-               memcpy(addr.sun_path, path, len);
-               *addr_ret = (struct sockaddr *) &addr;
-               *len_ret = len + sizeof addr.sun_family;
+               addr->sun_family = AF_UNIX;
+               memcpy(addr->sun_path, path, len);
+               *addr_ret = (struct sockaddr *) addr;
+               *len_ret = len + sizeof addr->sun_family;
                return 1;
        }
 #endif /* AF_UNIX */
 
        case AF_INET:
        {
-               static struct sockaddr_in addr;
+               struct sockaddr_in* addr;
                char *host;
                int port;
+               addr=(struct sockaddr_in*)&(s->sock_addr).in;
                if (!PyArg_Parse(args, "(si)", &host, &port))
                        return 0;
-               if (setipaddr(host, &addr) < 0)
+               if (setipaddr(host, addr) < 0)
                        return 0;
-               addr.sin_family = AF_INET;
-               addr.sin_port = htons(port);
-               *addr_ret = (struct sockaddr *) &addr;
-               *len_ret = sizeof addr;
+               addr->sin_family = AF_INET;
+               addr->sin_port = htons(port);
+               *addr_ret = (struct sockaddr *) addr;
+               *len_ret = sizeof *addr;
                return 1;
        }
 
@@ -764,7 +796,7 @@ BUILD_FUNC_DEF_2(PySocketSock_recvfrom,PySocketSockObject *,s, PyObject *,args)
 #ifndef NT
                     (ANY *)addrbuf, &addrlen);
 #else
-                    (struct sockaddr *)addrbuf, &addrlen);
+                    (struct sockaddr *)addrbuf, &addrlen);
 #endif
        Py_END_ALLOW_THREADS
        if (n < 0)
@@ -854,7 +886,7 @@ static PyMethodDef PySocketSock_methods[] = {
        {"allowbroadcast",      (PyCFunction)PySocketSock_allowbroadcast},
 #endif
 #ifndef NT
-       {"setblocking",         (PyCFunction)PySocketSock_setblocking},
+       {"setblocking",         (PyCFunction)PySocketSock_setblocking},
 #endif
        {"setsockopt",          (PyCFunction)PySocketSock_setsockopt},
        {"getsockopt",          (PyCFunction)PySocketSock_getsockopt},
@@ -883,7 +915,7 @@ static PyMethodDef PySocketSock_methods[] = {
    First close the file description. */
 
 static void
-BUILD_FUNC_DEF_1(PySocketSock_dealloc, PySocketSockObject *,s)
+BUILD_FUNC_DEF_1(PySocketSock_dealloc,PySocketSockObject *,s)
 {
        (void) close(s->sock_fd);
        PyMem_DEL(s);
@@ -899,6 +931,22 @@ BUILD_FUNC_DEF_2(PySocketSock_getattr,PySocketSockObject *,s, char *,name)
 }
 
 
+static PyObject *
+BUILD_FUNC_DEF_1(PySocketSock_repr,PySocketSockObject *,s)
+{
+       PyObject *addro;
+       struct sockaddr *addr;
+       char buf[512];
+       object *t, *comma, *v;
+       int i, len;
+       sprintf(buf, 
+               "<socket object, fd=%d, family=%d, type=%d, protocol=%d>", 
+               s->sock_fd, s->sock_family, s->sock_type, s->sock_proto);
+       t = newstringobject(buf);
+       return t;
+}
+
+
 /* Type object for socket objects. */
 
 static PyTypeObject PySocketSock_Type = {
@@ -912,7 +960,7 @@ static PyTypeObject PySocketSock_Type = {
        (getattrfunc)PySocketSock_getattr, /*tp_getattr*/
        0,              /*tp_setattr*/
        0,              /*tp_compare*/
-       0,              /*tp_repr*/
+       (reprfunc)PySocketSock_repr, /*tp_repr*/
        0,              /*tp_as_number*/
        0,              /*tp_as_sequence*/
        0,              /*tp_as_mapping*/
@@ -954,6 +1002,65 @@ BUILD_FUNC_DEF_2(PySocket_gethostbyname,PyObject *,self, PyObject *,args)
        return makeipaddr(&addrbuf);
 }
 
+/* Python interface to gethostbyaddr(IP). */
+
+/*ARGSUSED*/
+static PyObject *
+BUILD_FUNC_DEF_2(PySocket_gethostbyaddr,PyObject *,self, PyObject *, args)
+{
+        struct sockaddr_in addr;
+       char *ip_num;
+       struct hostent *h;
+       int d1,d2,d3,d4;
+       char ch, **pch;
+       PyObject *rtn_tuple = (PyObject *)NULL;
+       PyObject *name_list = (PyObject *)NULL;
+       PyObject *addr_list = (PyObject *)NULL;
+       PyObject *tmp;
+
+       if (!PyArg_Parse(args, "s", &ip_num))
+               return NULL;
+       if (setipaddr(ip_num, &addr) < 0)
+               return NULL;
+       h = gethostbyaddr((char *)&addr.sin_addr,
+                         sizeof(addr.sin_addr),
+                         AF_INET);
+       if (h == NULL) {
+#ifndef NT
+               /* Let's get real error message to return */
+               extern int h_errno;
+               PyErr_SetString(PySocket_Error, (char *)hstrerror(h_errno));
+#else
+               PyErr_SetString(PySocket_Error, "host not found");
+#endif
+               return NULL;
+       }
+       if ((name_list = PyList_New(0)) == NULL)
+               goto err;
+       if ((addr_list = PyList_New(0)) == NULL)
+               goto err;
+       for (pch = h->h_aliases; *pch != NULL; pch++) {
+               tmp = PyString_FromString(*pch);
+               if (tmp == NULL)
+                       goto err;
+               PyList_Append(name_list, tmp);
+               Py_DECREF(tmp);
+       }
+       for (pch = h->h_addr_list; *pch != NULL; pch++) {
+               memcpy((char *) &addr.sin_addr, *pch, h->h_length);
+               tmp = makeipaddr(&addr);
+               if (tmp == NULL)
+                       goto err;
+               PyList_Append(addr_list, tmp);
+               Py_DECREF(tmp);
+       }
+       rtn_tuple = Py_BuildValue("sOO", h->h_name, name_list, addr_list);
+ err:
+       Py_XDECREF(name_list);
+       Py_XDECREF(addr_list);
+       return rtn_tuple;
+}
+
 
 /* Python interface to getservbyname(name).
    This only returns the port number, since the other info is already
@@ -984,7 +1091,7 @@ BUILD_FUNC_DEF_2(PySocket_getservbyname,PyObject *,self, PyObject *,args)
 
 /*ARGSUSED*/
 static PyObject *
-BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self,PyObject *,args)
+BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self, PyObject *,args)
 {
        PySocketSockObject *s;
        int fd, family, type, proto;
@@ -1019,7 +1126,7 @@ BUILD_FUNC_DEF_2(PySocket_socket,PyObject *,self,PyObject *,args)
 
 /*ARGSUSED*/
 static PyObject *
-BUILD_FUNC_DEF_2(PySocket_fromfd,PyObject *,self,PyObject *,args)
+BUILD_FUNC_DEF_2(PySocket_fromfd,PyObject *,self, PyObject *,args)
 {
        PySocketSockObject *s;
        int fd, family, type, proto;
@@ -1047,6 +1154,7 @@ BUILD_FUNC_DEF_2(PySocket_fromfd,PyObject *,self,PyObject *,args)
 
 static PyMethodDef PySocket_methods[] = {
        {"gethostbyname",       PySocket_gethostbyname},
+       {"gethostbyaddr",       PySocket_gethostbyaddr},
        {"gethostname",         PySocket_gethostname},
        {"getservbyname",       PySocket_getservbyname},
        {"socket",              PySocket_socket},
@@ -1061,7 +1169,7 @@ static PyMethodDef PySocket_methods[] = {
    For simplicity, errors (which are unlikely anyway) are ignored. */
 
 static void
-BUILD_FUNC_DEF_3(insint,PyObject *,d,char *,name,int,value)
+BUILD_FUNC_DEF_3(insint,PyObject *,d, char *,name, int,value)
 {
        PyObject *v = PyInt_FromLong((long) value);
        if (v == NULL) {
index 301f060ec8b18c1fd37b0e1c1466235b39be4f84..3e742f31f24b07add5837304dc73e21aac03efe2 100644 (file)
@@ -205,7 +205,9 @@ t_bootstrap(args_raw)
                fprintf(stderr, "Unhandled exception in thread:\n");
                print_error(); /* From pythonmain.c */
        }
-       (void) save_thread();
+       else
+               DECREF(res);
+       (void) save_thread(); /* Should always be NULL */
        exit_thread();
 }
 
@@ -236,9 +238,11 @@ thread_exit_thread(self, args)
        object *self; /* Not used */
        object *args;
 {
+       object *frame;
        if (!getnoarg(args))
                return NULL;
-       (void) save_thread();
+       frame = save_thread(); /* Should never be NULL */
+       DECREF(frame);
        exit_thread();
        for (;;) { } /* Should not be reached */
 }
index 8dc10cb5d4345bcf0b6e27600e242af1b04faaf3..ac50fb91f7068693fa8eebb46a0d600a7b133aec 100644 (file)
@@ -297,8 +297,13 @@ floattime()
 #ifdef HAVE_GETTIMEOFDAY
     {
        struct timeval t;
+#ifdef GETTIMEOFDAY_NO_TZ
+       if (gettimeofday(&t) == 0)
+               return (double)t.tv_sec + t.tv_usec*0.000001;
+#else /* !GETTIMEOFDAY_NO_TZ */
        if (gettimeofday(&t, (struct timezone *)NULL) == 0)
                return (double)t.tv_sec + t.tv_usec*0.000001;
+#endif /* !GETTIMEOFDAY_NO_TZ */
     }
 #endif /* !HAVE_GETTIMEOFDAY */
     {