Commit 3bbc62e9 authored by Guido van Rossum's avatar Guido van Rossum

Another bulky set of minor changes.

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