summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1993-11-03 15:01:26 (GMT)
committerGuido van Rossum <guido@python.org>1993-11-03 15:01:26 (GMT)
commite77a757094f68351f336044654cd91575c677896 (patch)
tree0c0f8f78c180d4a88c9c5ff8c26e2457b6722e28
parent78ed420314876083b4cc1739d7dbf04e4f012c03 (diff)
downloadcpython-e77a757094f68351f336044654cd91575c677896.zip
cpython-e77a757094f68351f336044654cd91575c677896.tar.gz
cpython-e77a757094f68351f336044654cd91575c677896.tar.bz2
* nismodule.c: database keys and values can contain null bytes. be more
careful about these. * arraymodule.c: added 8 byte swap; added 'i' format character; added reverse() method; rename read/write to fromfile/tofile. * config.c: Set version to 0.9.9++. * rotormodule.c (r_rand): declare k1..k5 as unsigned longs so the shifts will have a well-defined effect independent of word size. * bltinmodule.c: renamed bagof() to filter().
-rw-r--r--Modules/arraymodule.c92
-rw-r--r--Modules/config.c.in4
-rw-r--r--Modules/nismodule.c26
-rw-r--r--Modules/rotormodule.c5
-rw-r--r--Python/bltinmodule.c10
5 files changed, 101 insertions, 36 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 00f2477..3f7e163 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -144,6 +144,28 @@ h_setitem(ap, i, v)
}
static object *
+i_getitem(ap, i)
+ arrayobject *ap;
+ int i;
+{
+ return newintobject((long) ((int *)ap->ob_item)[i]);
+}
+
+static int
+i_setitem(ap, i, v)
+ arrayobject *ap;
+ int i;
+ object *v;
+{
+ int x;
+ if (!getargs(v, "i;array item must be integer", &x))
+ return -1;
+ if (i >= 0)
+ ((int *)ap->ob_item)[i] = x;
+ return 0;
+}
+
+static object *
l_getitem(ap, i)
arrayobject *ap;
int i;
@@ -214,11 +236,13 @@ static struct arraydescr descriptors[] = {
{'c', sizeof(char), c_getitem, c_setitem},
{'b', sizeof(char), b_getitem, b_setitem},
{'h', sizeof(short), h_getitem, h_setitem},
+ {'i', sizeof(int), i_getitem, i_setitem},
{'l', sizeof(long), l_getitem, l_setitem},
{'f', sizeof(float), f_getitem, f_setitem},
{'d', sizeof(double), d_getitem, d_setitem},
{'\0', 0, 0, 0} /* Sentinel */
};
+/* If we ever allow items larger than double, we must change reverse()! */
object *
@@ -239,7 +263,7 @@ newarrayobject(size, descr)
if (nbytes / descr->itemsize != size) {
return err_nomem();
}
- op = (arrayobject *) malloc(sizeof(arrayobject));
+ op = NEW(arrayobject, 1);
if (op == NULL) {
return err_nomem();
}
@@ -247,9 +271,9 @@ newarrayobject(size, descr)
op->ob_item = NULL;
}
else {
- op->ob_item = malloc(nbytes);
+ op->ob_item = NEW(char, nbytes);
if (op->ob_item == NULL) {
- free((ANY *)op);
+ DEL(op);
return err_nomem();
}
}
@@ -355,8 +379,8 @@ array_dealloc(op)
{
int i;
if (op->ob_item != NULL)
- free((ANY *)op->ob_item);
- free((ANY *)op);
+ DEL(op->ob_item);
+ DEL(op);
}
static int
@@ -644,6 +668,22 @@ array_byteswap(self, args)
p[3] = p0;
}
break;
+ case 8:
+ for (p = self->ob_item, i = self->ob_size; --i >= 0; p += 8) {
+ char p0 = p[0];
+ char p1 = p[1];
+ char p2 = p[2];
+ char p3 = p[3];
+ p[0] = p[7];
+ p[1] = p[6];
+ p[2] = p[5];
+ p[3] = p[4];
+ p[4] = p3;
+ p[5] = p2;
+ p[6] = p1;
+ p[7] = p0;
+ }
+ break;
default:
err_setstr(RuntimeError,
"don't know how to byteswap this array type");
@@ -653,33 +693,37 @@ array_byteswap(self, args)
return None;
}
-#if 0
static object *
array_reverse(self, args)
arrayobject *self;
object *args;
{
- register object **p, **q;
- register object *tmp;
-
+ register int itemsize = self->ob_descr->itemsize;
+ register char *p, *q;
+ char tmp[sizeof(double)]; /* Assume that's the max item size */
+
if (args != NULL) {
err_badarg();
return NULL;
}
if (self->ob_size > 1) {
- for (p = self->ob_item, q = self->ob_item + self->ob_size - 1;
- p < q; p++, q--) {
- tmp = *p;
- *p = *q;
- *q = tmp;
+ for (p = self->ob_item,
+ q = self->ob_item + (self->ob_size - 1)*itemsize;
+ p < q;
+ p += itemsize, q -= itemsize) {
+ memmove(tmp, p, itemsize);
+ memmove(p, q, itemsize);
+ memmove(q, tmp, itemsize);
}
}
INCREF(None);
return None;
}
-#endif
+
+/* The following routines were adapted from listobject.c but not converted.
+ To make them work you will have to work! */
#if 0
static object *
@@ -750,7 +794,7 @@ array_remove(self, args)
#endif
static object *
-array_read(self, args)
+array_fromfile(self, args)
arrayobject *self;
object *args;
{
@@ -790,7 +834,7 @@ array_read(self, args)
}
static object *
-array_write(self, args)
+array_tofile(self, args)
arrayobject *self;
object *args;
{
@@ -921,17 +965,19 @@ static struct methodlist array_methods[] = {
{"append", array_append},
{"byteswap", array_byteswap},
/* {"count", array_count},*/
+ {"fromfile", array_fromfile},
+ {"fromlist", array_fromlist},
+ {"fromstring", array_fromstring},
/* {"index", array_index},*/
{"insert", array_insert},
-/* {"sort", array_sort},*/
+ {"read", array_fromfile},
/* {"remove", array_remove},*/
-/* {"reverse", array_reverse},*/
- {"read", array_read},
- {"write", array_write},
- {"fromlist", array_fromlist},
+ {"reverse", array_reverse},
+/* {"sort", array_sort},*/
+ {"tofile", array_tofile},
{"tolist", array_tolist},
- {"fromstring", array_fromstring},
{"tostring", array_tostring},
+ {"write", array_tofile},
{NULL, NULL} /* sentinel */
};
diff --git a/Modules/config.c.in b/Modules/config.c.in
index fc80362..c9f56ac 100644
--- a/Modules/config.c.in
+++ b/Modules/config.c.in
@@ -62,12 +62,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "patchlevel.h"
-#define VERSION "0.9.%d (%s)"
+#define VERSION "0.9.%d++ (%s)"
#ifdef __DATE__
#define DATE __DATE__
#else
-#define DATE ">= 29 Jul 1993"
+#define DATE ">= 3 Nov 1993"
#endif
char version[80];
diff --git a/Modules/nismodule.c b/Modules/nismodule.c
index 9234127..5db26f4 100644
--- a/Modules/nismodule.c
+++ b/Modules/nismodule.c
@@ -67,9 +67,23 @@ nis_foreach (instatus, inkey, inkeylen, inval, invallen, indata)
object *indata;
{
if (instatus == YP_TRUE) {
- inkey[inkeylen]=0;
- inval[invallen]=0;
- dictinsert (indata, inkey, newstringobject (inval));
+ object *key = newsizedstringobject(inkey, inkeylen);
+ object *val = newsizedstringobject(inval, invallen);
+ int err;
+ if (key == NULL || val == NULL) {
+ /* XXX error -- don't know how to handle */
+ err_clear();
+ XDECREF(key);
+ XDECREF(val);
+ return 1;
+ }
+ err = mappinginsert(indata, key, val);
+ DECREF(key);
+ DECREF(val);
+ if (err != 0) {
+ err_clear();
+ return 1;
+ }
return 0;
}
return 1;
@@ -82,18 +96,18 @@ nis_match (self, args)
{
char *match;
char *domain;
- int len;
+ int keylen, len;
char *key, *map;
int err;
object *res;
- if (!getargs(args, "(ss)", &key, &map))
+ if (!getargs(args, "(s#s)", &key, &keylen, &map))
return NULL;
if ((err = yp_get_default_domain(&domain)) != 0)
return nis_error(err);
BGN_SAVE
map = nis_mapname (map);
- err = yp_match (domain, map, key, strlen (key), &match, &len);
+ err = yp_match (domain, map, key, keylen, &match, &len);
END_SAVE
if (err != 0)
return nis_error(err);
diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c
index f01c5fe..d397e2c 100644
--- a/Modules/rotormodule.c
+++ b/Modules/rotormodule.c
@@ -154,7 +154,12 @@ static void set_key(r, key)
rotorobject *r;
char *key;
{
+#ifdef BUGGY_CODE_BW_COMPAT
+ /* See comments below */
int k1=995, k2=576, k3=767, k4=671, k5=463;
+#else
+ unsigned long k1=995, k2=576, k3=767, k4=671, k5=463;
+#endif
int i;
int len=strlen(key);
for (i=0;i<len;i++) {
diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c
index 5183069..9210bd1 100644
--- a/Python/bltinmodule.c
+++ b/Python/bltinmodule.c
@@ -67,7 +67,7 @@ builtin_apply(self, args)
}
static object *
-builtin_bagof(self, args)
+builtin_filter(self, args)
object *self;
object *args;
{
@@ -101,7 +101,7 @@ builtin_bagof(self, args)
if ((sqf = seq->ob_type->tp_as_sequence) == NULL) {
err_setstr(TypeError,
- "argument 2 to bagof() must be a sequence type");
+ "argument 2 to filter() must be a sequence type");
goto Fail_2;
}
@@ -1121,7 +1121,6 @@ builtin_type(self, v)
static struct methodlist builtin_methods[] = {
{"abs", builtin_abs},
{"apply", builtin_apply},
- {"bagof", builtin_bagof},
{"chr", builtin_chr},
{"cmp", builtin_cmp},
{"coerce", builtin_coerce},
@@ -1130,6 +1129,7 @@ static struct methodlist builtin_methods[] = {
{"divmod", builtin_divmod},
{"eval", builtin_eval},
{"execfile", builtin_execfile},
+ {"filter", builtin_filter},
{"float", builtin_float},
{"getattr", builtin_getattr},
{"hasattr", builtin_hasattr},
@@ -1271,7 +1271,7 @@ coerce(pv, pw)
}
-/* Helper for bagof(): filter a tuple through a function */
+/* Helper for filter(): filter a tuple through a function */
static object *
filtertuple(func, tuple)
@@ -1324,7 +1324,7 @@ Fail_1:
}
-/* Helper for bagof(): filter a string through a function */
+/* Helper for filter(): filter a string through a function */
static object *
filterstring(func, strobj)