summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Modules/Makefile.pre.in16
-rw-r--r--Modules/_tkinter.c16
-rw-r--r--Modules/arraymodule.c9
-rw-r--r--Modules/audioop.c7
-rw-r--r--Modules/config.c.in4
-rw-r--r--Modules/imageop.c7
-rwxr-xr-xModules/makesetup8
-rw-r--r--Modules/mathmodule.c4
-rw-r--r--Modules/md5module.c5
-rw-r--r--Modules/mpzmodule.c24
-rw-r--r--Modules/parsermodule.c1
-rw-r--r--Modules/posixmodule.c25
-rw-r--r--Modules/rgbimgmodule.c2
-rw-r--r--Modules/rotormodule.c3
-rw-r--r--Modules/signalmodule.c9
-rw-r--r--Modules/socketmodule.c154
-rw-r--r--Modules/threadmodule.c8
-rw-r--r--Modules/timemodule.c5
18 files changed, 222 insertions, 85 deletions
diff --git a/Modules/Makefile.pre.in b/Modules/Makefile.pre.in
index ae6e8de..5662ea5 100644
--- a/Modules/Makefile.pre.in
+++ b/Modules/Makefile.pre.in
@@ -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
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 6104960..77b1809 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -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)
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 0dfe4f6..2584b03 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -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;
diff --git a/Modules/audioop.c b/Modules/audioop.c
index e3297a3..22e309d 100644
--- a/Modules/audioop.c
+++ b/Modules/audioop.c
@@ -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;
diff --git a/Modules/config.c.in b/Modules/config.c.in
index fb8b49b..2be3e37 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -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},
diff --git a/Modules/imageop.c b/Modules/imageop.c
index 77da52e..d3d14e4 100644
--- a/Modules/imageop.c
+++ b/Modules/imageop.c
@@ -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;
diff --git a/Modules/makesetup b/Modules/makesetup
index 0da9465..1feae60 100755
--- a/Modules/makesetup
+++ b/Modules/makesetup
@@ -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
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index 5663ba2..a1357da 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -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},
diff --git a/Modules/md5module.c b/Modules/md5module.c
index 68d52f4..9909d2c 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -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 */
};
diff --git a/Modules/mpzmodule.c b/Modules/mpzmodule.c
index 9d0bdb0..0067397 100644
--- a/Modules/mpzmodule.c
+++ b/Modules/mpzmodule.c
@@ -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() */
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 04db26e..8e3d96b 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -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;
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index c2678eb..3e3f9cc 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -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;
diff --git a/Modules/rgbimgmodule.c b/Modules/rgbimgmodule.c
index de888eb..62e9e0b 100644
--- a/Modules/rgbimgmodule.c
+++ b/Modules/rgbimgmodule.c
@@ -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;
diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c
index a7529a3..cb70612 100644
--- a/Modules/rotormodule.c
+++ b/Modules/rotormodule.c
@@ -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))
diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index bbb077f..cf921a7 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -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
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index bda7bf1..39aa81e 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -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) {
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index 301f060..3e742f3 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -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 */
}
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 8dc10cb..ac50fb9 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -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 */
{