Makefile.pre.in: add $(OPT) to link command

audioop.c: fix for MPW
config.c.in: save original argc/argv for Lance
rotormodule.c: new coding conventions
timemodule.c: add casts for Lance
This commit is contained in:
Guido van Rossum 1994-08-29 10:46:42 +00:00
parent 0e3da7ba50
commit 7b1e974b4b
5 changed files with 128 additions and 105 deletions

View file

@ -66,7 +66,7 @@ $(LIB): $(OBJS)
$(RANLIB) $(LIB) $(RANLIB) $(LIB)
../python: config.o $(MYLIBS) ../python: config.o $(MYLIBS)
$(CC) config.o \ $(CC) $(OPT) config.o \
$(MYLIBS) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python $(MYLIBS) $(MODLIBS) $(LIBS) $(SYSLIBS) -o python
mv python ../python mv python ../python

View file

@ -27,11 +27,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "allobjects.h" #include "allobjects.h"
#include "modsupport.h" #include "modsupport.h"
#if defined(__CHAR_UNSIGNED__) && defined(signed) #if defined(__CHAR_UNSIGNED__)
#if defined(signed)
!ERROR!; READ THE SOURCE FILE!; !ERROR!; READ THE SOURCE FILE!;
/* This module currently does not work on systems where only unsigned /* This module currently does not work on systems where only unsigned
characters are available. Take it out of Setup. Sorry. */ characters are available. Take it out of Setup. Sorry. */
#endif #endif
#endif
#include <math.h> #include <math.h>

View file

@ -53,10 +53,18 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
static char *argv0; static char *argv0;
/* These are made available for other modules that might need them.
This is rare, but it is needed by the secureware module. */
static char **orig_argv;
static int orig_argc;
main(argc, argv) main(argc, argv)
int argc; int argc;
char **argv; char **argv;
{ {
orig_argc = argc;
orig_argv = argv;
argv0 = argv[0]; argv0 = argv[0];
realmain(argc, argv); realmain(argc, argv);
} }
@ -67,6 +75,15 @@ getprogramname()
return argv0; return argv0;
} }
void
getargcargv(argc,argv)
int *argc;
char ***argv;
{
*argc = orig_argc;
*argv = orig_argv;
}
#endif #endif

View file

@ -75,8 +75,11 @@ NOTE: you MUST use the SAME key in rotor.newrotor()
#define TRUE 1 #define TRUE 1
#define FALSE 0 #define FALSE 0
/* This is temp until the renaming effort is done with Python */
#include "rename1.h"
typedef struct { typedef struct {
OB_HEAD PyObject_HEAD
int seed[3]; int seed[3];
short key[5]; short key[5];
int isinited; int isinited;
@ -87,18 +90,18 @@ typedef struct {
unsigned char *d_rotor; /* [num_rotors][size] */ unsigned char *d_rotor; /* [num_rotors][size] */
unsigned char *positions; /* [num_rotors] */ unsigned char *positions; /* [num_rotors] */
unsigned char *advances; /* [num_rotors] */ unsigned char *advances; /* [num_rotors] */
} rotorobject; } PyRotorObject;
staticforward typeobject Rotortype; staticforward PyTypeObject PyRotor_Type;
#define is_rotorobject(v) ((v)->ob_type == &Rotortype) #define PyRotor_Check(v) ((v)->ob_type == &PyRotor_Type)
/* /*
This defines the necessary routines to manage rotor objects This defines the necessary routines to manage rotor objects
*/ */
static void set_seed( r ) static void set_seed( r )
rotorobject *r; PyRotorObject *r;
{ {
r->seed[0] = r->key[0]; r->seed[0] = r->key[0];
r->seed[1] = r->key[1]; r->seed[1] = r->key[1];
@ -108,7 +111,7 @@ rotorobject *r;
/* Return the next random number in the range [0.0 .. 1.0) */ /* Return the next random number in the range [0.0 .. 1.0) */
static float r_random( r ) static float r_random( r )
rotorobject *r; PyRotorObject *r;
{ {
int x, y, z; int x, y, z;
float val, term; float val, term;
@ -142,7 +145,7 @@ rotorobject *r;
} }
static short r_rand(r,s) static short r_rand(r,s)
rotorobject *r; PyRotorObject *r;
short s; short s;
{ {
/*short tmp = (short)((int)(r_random(r) * (float)32768.0) % 32768);*/ /*short tmp = (short)((int)(r_random(r) * (float)32768.0) % 32768);*/
@ -151,7 +154,7 @@ short s;
} }
static void set_key(r, key) static void set_key(r, key)
rotorobject *r; PyRotorObject *r;
char *key; char *key;
{ {
#ifdef BUGGY_CODE_BW_COMPAT #ifdef BUGGY_CODE_BW_COMPAT
@ -194,13 +197,13 @@ char *key;
} }
/* These define the interface to a rotor object */ /* These define the interface to a rotor object */
static rotorobject * static PyRotorObject *
newrotorobject(num_rotors, key) PyRotor_New(num_rotors, key)
int num_rotors; int num_rotors;
char *key; char *key;
{ {
rotorobject *xp; PyRotorObject *xp;
xp = NEWOBJ(rotorobject, &Rotortype); xp = PyObject_NEW(PyRotorObject, &PyRotor_Type);
if (xp == NULL) if (xp == NULL)
return NULL; return NULL;
set_key(xp, key); set_key(xp, key);
@ -231,7 +234,7 @@ newrotorobject(num_rotors, key)
return xp; return xp;
fail: fail:
DECREF(xp); DECREF(xp);
return (rotorobject *)err_nomem(); return (PyRotorObject *)PyErr_NoMemory();
} }
/* These routines impliment the rotor itself */ /* These routines impliment the rotor itself */
@ -266,7 +269,7 @@ j'
(setq j (+ 1 j))) (setq j (+ 1 j)))
rotor))*/ rotor))*/
static void RTR_make_id_rotor(r, rtr) static void RTR_make_id_rotor(r, rtr)
rotorobject *r; PyRotorObject *r;
unsigned char *rtr; unsigned char *rtr;
{ {
register int j; register int j;
@ -289,7 +292,7 @@ static void RTR_make_id_rotor(r, rtr)
rv) rv)
"The current set of encryption rotors")*/ "The current set of encryption rotors")*/
static void RTR_e_rotors(r) static void RTR_e_rotors(r)
rotorobject *r; PyRotorObject *r;
{ {
int i; int i;
for (i=0;i<r->rotors;i++) { for (i=0;i<r->rotors;i++) {
@ -312,7 +315,7 @@ static void RTR_e_rotors(r)
rv) rv)
"The current set of decryption rotors")*/ "The current set of decryption rotors")*/
static void RTR_d_rotors(r) static void RTR_d_rotors(r)
rotorobject *r; PyRotorObject *r;
{ {
register int i, j; register int i, j;
for (i=0;i<r->rotors;i++) { for (i=0;i<r->rotors;i++) {
@ -325,7 +328,7 @@ static void RTR_d_rotors(r)
/*(defvar RTR-positions (make-vector RTR-number-of-rotors 1) /*(defvar RTR-positions (make-vector RTR-number-of-rotors 1)
"The positions of the rotors at this time")*/ "The positions of the rotors at this time")*/
static void RTR_positions(r) static void RTR_positions(r)
rotorobject *r; PyRotorObject *r;
{ {
int i; int i;
for (i=0;i<r->rotors;i++) { for (i=0;i<r->rotors;i++) {
@ -336,7 +339,7 @@ static void RTR_positions(r)
/*(defvar RTR-advances (make-vector RTR-number-of-rotors 1) /*(defvar RTR-advances (make-vector RTR-number-of-rotors 1)
"The number of positions to advance the rotors at a time")*/ "The number of positions to advance the rotors at a time")*/
static void RTR_advances(r) static void RTR_advances(r)
rotorobject *r; PyRotorObject *r;
{ {
int i; int i;
for (i=0;i<r->rotors;i++) { for (i=0;i<r->rotors;i++) {
@ -360,7 +363,7 @@ static void RTR_advances(r)
(aset e 0 (aref e 0)) ; don't forget e[0] and d[0] (aset e 0 (aref e 0)) ; don't forget e[0] and d[0]
(aset d (aref e 0) 0)))*/ (aset d (aref e 0) 0)))*/
static void RTR_permute_rotor(r, e, d) static void RTR_permute_rotor(r, e, d)
rotorobject *r; PyRotorObject *r;
unsigned char *e; unsigned char *e;
unsigned char *d; unsigned char *d;
{ {
@ -393,7 +396,7 @@ Set the advancement, position, and permutation of the rotors"
(RTR-permute-rotor (aref RTR-e-rotors i) (aref RTR-d-rotors i)) (RTR-permute-rotor (aref RTR-e-rotors i) (aref RTR-d-rotors i))
(setq i (+ 1 i)))))*/ (setq i (+ 1 i)))))*/
static void RTR_init(r) static void RTR_init(r)
rotorobject *r; PyRotorObject *r;
{ {
int i; int i;
set_seed(r); set_seed(r);
@ -431,7 +434,7 @@ static void RTR_init(r)
(+ 1 (aref RTR-positions (+ i 1))))) (+ 1 (aref RTR-positions (+ i 1)))))
(setq i (+ i 1))))))*/ (setq i (+ i 1))))))*/
static void RTR_advance(r) static void RTR_advance(r)
rotorobject *r; PyRotorObject *r;
{ {
register int i=0, temp=0; register int i=0, temp=0;
if (r->size_mask) { if (r->size_mask) {
@ -474,7 +477,7 @@ static void RTR_advance(r)
(RTR-advance) (RTR-advance)
p))*/ p))*/
static unsigned char RTR_e_char(r, p) static unsigned char RTR_e_char(r, p)
rotorobject *r; PyRotorObject *r;
unsigned char p; unsigned char p;
{ {
register int i=0; register int i=0;
@ -513,7 +516,7 @@ static unsigned char RTR_e_char(r, p)
(RTR-advance) (RTR-advance)
c))*/ c))*/
static unsigned char RTR_d_char(r, c) static unsigned char RTR_d_char(r, c)
rotorobject *r; PyRotorObject *r;
unsigned char c; unsigned char c;
{ {
register int i=r->rotors - 1; register int i=r->rotors - 1;
@ -545,7 +548,7 @@ static unsigned char RTR_d_char(r, c)
(insert-char (RTR-e-char fc) 1) (insert-char (RTR-e-char fc) 1)
(delete-char 1))))))*/ (delete-char 1))))))*/
static void RTR_e_region(r, beg, len, doinit) static void RTR_e_region(r, beg, len, doinit)
rotorobject *r; PyRotorObject *r;
unsigned char *beg; unsigned char *beg;
int len; int len;
int doinit; int doinit;
@ -568,8 +571,8 @@ static void RTR_e_region(r, beg, len, doinit)
(let ((fc (following-char))) (let ((fc (following-char)))
(insert-char (RTR-d-char fc) 1) (insert-char (RTR-d-char fc) 1)
(delete-char 1))))))*/ (delete-char 1))))))*/
void static RTR_d_region(r, beg, len, doinit) static void RTR_d_region(r, beg, len, doinit)
rotorobject *r; PyRotorObject *r;
unsigned char *beg; unsigned char *beg;
int len; int len;
int doinit; int doinit;
@ -606,7 +609,7 @@ void static RTR_d_region(r, beg, len, doinit)
(interactive "r\nsKey:") (interactive "r\nsKey:")
(RTR-e-region beg end (RTR-key-string-to-ints key)))*/ (RTR-e-region beg end (RTR-key-string-to-ints key)))*/
static void encrypt_region(r, region, len) static void encrypt_region(r, region, len)
rotorobject *r; PyRotorObject *r;
unsigned char *region; unsigned char *region;
int len; int len;
{ {
@ -618,7 +621,7 @@ static void encrypt_region(r, region, len)
(interactive "r\nsKey:") (interactive "r\nsKey:")
(RTR-d-region beg end (RTR-key-string-to-ints key)))*/ (RTR-d-region beg end (RTR-key-string-to-ints key)))*/
static void decrypt_region(r, region, len) static void decrypt_region(r, region, len)
rotorobject *r; PyRotorObject *r;
unsigned char *region; unsigned char *region;
int len; int len;
{ {
@ -628,184 +631,185 @@ static void decrypt_region(r, region, len)
/* Rotor methods */ /* Rotor methods */
static void static void
rotor_dealloc(xp) PyRotor_Dealloc(xp)
rotorobject *xp; PyRotorObject *xp;
{ {
XDEL(xp->e_rotor); PyMem_XDEL(xp->e_rotor);
XDEL(xp->d_rotor); PyMem_XDEL(xp->d_rotor);
XDEL(xp->positions); PyMem_XDEL(xp->positions);
XDEL(xp->advances); PyMem_XDEL(xp->advances);
DEL(xp); PyMem_DEL(xp);
} }
static object * static PyObject *
rotor_encrypt(self, args) PyRotor_Encrypt(self, args)
rotorobject *self; PyRotorObject *self;
object *args; PyObject *args;
{ {
char *string = (char *)NULL; char *string = (char *)NULL;
int len = 0; int len = 0;
object *rtn = (object *)NULL; PyObject *rtn = (PyObject *)NULL;
char *tmp; char *tmp;
if (!getargs(args,"s#",&string, &len)) if (!PyArg_Parse(args,"s#",&string, &len))
return NULL; return NULL;
if (!(tmp = (char *)malloc(len+5))) { if (!(tmp = (char *)malloc(len+5))) {
err_nomem(); PyErr_NoMemory();
return NULL; return NULL;
} }
memset(tmp,'\0',len+1); memset(tmp,'\0',len+1);
memcpy(tmp,string,len); memcpy(tmp,string,len);
RTR_e_region(self,(unsigned char *)tmp,len, TRUE); RTR_e_region(self,(unsigned char *)tmp,len, TRUE);
rtn = newsizedstringobject(tmp,len); rtn = PyString_FromStringAndSize(tmp,len);
free(tmp); free(tmp);
return(rtn); return(rtn);
} }
static object * static PyObject *
rotor_encryptmore(self, args) PyRotor_EncryptMore(self, args)
rotorobject *self; PyRotorObject *self;
object *args; PyObject *args;
{ {
char *string = (char *)NULL; char *string = (char *)NULL;
int len = 0; int len = 0;
object *rtn = (object *)NULL; PyObject *rtn = (PyObject *)NULL;
char *tmp; char *tmp;
if (!getargs(args,"s#",&string, &len)) if (!PyArg_Parse(args,"s#",&string, &len))
return NULL; return NULL;
if (!(tmp = (char *)malloc(len+5))) { if (!(tmp = (char *)malloc(len+5))) {
err_nomem(); PyErr_NoMemory();
return NULL; return NULL;
} }
memset(tmp,'\0',len+1); memset(tmp,'\0',len+1);
memcpy(tmp,string,len); memcpy(tmp,string,len);
RTR_e_region(self,(unsigned char *)tmp,len, FALSE); RTR_e_region(self,(unsigned char *)tmp,len, FALSE);
rtn = newsizedstringobject(tmp,len); rtn = PyString_FromStringAndSize(tmp,len);
free(tmp); free(tmp);
return(rtn); return(rtn);
} }
static object * static PyObject *
rotor_decrypt(self, args) PyRotor_Decrypt(self, args)
rotorobject *self; PyRotorObject *self;
object *args; PyObject *args;
{ {
char *string = (char *)NULL; char *string = (char *)NULL;
int len = 0; int len = 0;
object *rtn = (object *)NULL; PyObject *rtn = (PyObject *)NULL;
char *tmp; char *tmp;
if (!getargs(args,"s#",&string, &len)) if (!PyArg_Parse(args,"s#",&string, &len))
return NULL; return NULL;
if (!(tmp = (char *)malloc(len+5))) { if (!(tmp = (char *)malloc(len+5))) {
err_nomem(); PyErr_NoMemory();
return NULL; return NULL;
} }
memset(tmp,'\0',len+1); memset(tmp,'\0',len+1);
memcpy(tmp,string,len); memcpy(tmp,string,len);
RTR_d_region(self,(unsigned char *)tmp,len, TRUE); RTR_d_region(self,(unsigned char *)tmp,len, TRUE);
rtn = newsizedstringobject(tmp,len); rtn = PyString_FromStringAndSize(tmp,len);
free(tmp); free(tmp);
return(rtn); return(rtn);
} }
static object * static PyObject *
rotor_decryptmore(self, args) PyRotor_DecryptMore(self, args)
rotorobject *self; PyRotorObject *self;
object *args; PyObject *args;
{ {
char *string = (char *)NULL; char *string = (char *)NULL;
int len = 0; int len = 0;
object *rtn = (object *)NULL; PyObject *rtn = (PyObject *)NULL;
char *tmp; char *tmp;
if (!getargs(args,"s#",&string, &len)) if (!PyArg_Parse(args,"s#",&string, &len))
return NULL; return NULL;
if (!(tmp = (char *)malloc(len+5))) { if (!(tmp = (char *)malloc(len+5))) {
err_nomem(); PyErr_NoMemory();
return NULL; return NULL;
} }
memset(tmp,'\0',len+1); memset(tmp,'\0',len+1);
memcpy(tmp,string,len); memcpy(tmp,string,len);
RTR_d_region(self,(unsigned char *)tmp,len, FALSE); RTR_d_region(self,(unsigned char *)tmp,len, FALSE);
rtn = newsizedstringobject(tmp,len); rtn = PyString_FromStringAndSize(tmp,len);
free(tmp); free(tmp);
return(rtn); return(rtn);
} }
static object * static PyObject *
rotor_setkey(self, args) PyRotor_SetKey(self, args)
rotorobject *self; PyRotorObject *self;
object *args; PyObject *args;
{ {
char *key; char *key;
char *string; char *string;
if (getargs(args,"s",&string)) if (PyArg_Parse(args,"s",&string))
set_key(self,string); set_key(self,string);
INCREF(None); Py_INCREF(None);
return None; return None;
} }
static struct methodlist rotor_methods[] = { static PyMethodDef PyRotor_Methods[] = {
{"encrypt", (method)rotor_encrypt}, {"encrypt", (PyCFunction)PyRotor_Encrypt},
{"encryptmore", (method)rotor_encryptmore}, {"encryptmore", (PyCFunction)PyRotor_EncryptMore},
{"decrypt", (method)rotor_decrypt}, {"decrypt", (PyCFunction)PyRotor_Decrypt},
{"decryptmore", (method)rotor_decryptmore}, {"decryptmore", (PyCFunction)PyRotor_DecryptMore},
{"setkey", (method)rotor_setkey}, {"setkey", (PyCFunction)PyRotor_SetKey},
{NULL, NULL} /* sentinel */ {NULL, NULL} /* sentinel */
}; };
/* Return a rotor object's named attribute. */ /* Return a rotor object's named attribute. */
static object * static PyObject *
rotor_getattr(s, name) PyRotor_GetAttr(s, name)
rotorobject *s; PyRotorObject *s;
char *name; char *name;
{ {
return findmethod(rotor_methods, (object *) s, name); return Py_FindMethod(PyRotor_Methods, (PyObject *) s, name);
} }
static typeobject Rotortype = { static PyTypeObject PyRotor_Type = {
OB_HEAD_INIT(&Typetype) PyObject_HEAD_INIT(&Typetype)
0, /*ob_size*/ 0, /*ob_size*/
"rotor", /*tp_name*/ "rotor", /*tp_name*/
sizeof(rotorobject), /*tp_size*/ sizeof(PyRotorObject), /*tp_size*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
/* methods */ /* methods */
(destructor)rotor_dealloc, /*tp_dealloc*/ (destructor)PyRotor_Dealloc, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
(getattrfunc)rotor_getattr, /*tp_getattr*/ (getattrfunc)PyRotor_GetAttr, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
0, /*tp_compare*/ 0, /*tp_compare*/
0, /*tp_repr*/ 0, /*tp_repr*/
0, /*tp_hash*/
}; };
static object * static PyObject *
rotor_rotor(self, args) PyRotor_Rotor(self, args)
object *self; PyObject *self;
object *args; PyObject *args;
{ {
char *string; char *string;
rotorobject *r; PyRotorObject *r;
int len; int len;
int num_rotors; int num_rotors;
if (getargs(args,"s#", &string, &len)) { if (PyArg_Parse(args,"s#", &string, &len)) {
num_rotors = 6; num_rotors = 6;
} else { } else {
err_clear(); PyErr_Clear();
if (!getargs(args,"(s#i)", &string, &len, &num_rotors)) if (!PyArg_Parse(args,"(s#i)", &string, &len, &num_rotors))
return NULL; return NULL;
} }
r = newrotorobject(num_rotors, string); r = PyRotor_New(num_rotors, string);
return (object *)r; return (PyObject *)r;
} }
static struct methodlist rotor_rotor_methods[] = { static PyMethodDef PyRotor_Rotor_Methods[] = {
{"newrotor", rotor_rotor}, {"newrotor", (PyCFunction)PyRotor_Rotor},
{NULL, NULL} /* Sentinel */ {NULL, NULL} /* Sentinel */
}; };
@ -818,7 +822,7 @@ static struct methodlist rotor_rotor_methods[] = {
void void
initrotor() initrotor()
{ {
object *m; PyObject *m;
m = initmodule("rotor", rotor_rotor_methods); m = Py_InitModule("rotor", PyRotor_Rotor_Methods);
} }

View file

@ -305,7 +305,7 @@ floattime()
#ifdef HAVE_FTIME #ifdef HAVE_FTIME
struct timeb t; struct timeb t;
ftime(&t); ftime(&t);
return (double)t.time + t.millitm*0.001; return (double)t.time + (double)t.millitm * (double)0.001;
#else /* !HAVE_FTIME */ #else /* !HAVE_FTIME */
time_t secs; time_t secs;
time(&secs); time(&secs);