Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d5735e

Browse files
committed
Merge back to main trunk
1 parent 013142a commit 1d5735e

37 files changed

Lines changed: 676 additions & 826 deletions

Modules/cgensupport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************
2-
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
33
Amsterdam, The Netherlands.
44
55
All Rights Reserved

Objects/dictobject.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************
2-
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
33
Amsterdam, The Netherlands.
44
55
All Rights Reserved
@@ -38,16 +38,18 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3838
Table of primes suitable as keys, in ascending order.
3939
The first line are the largest primes less than some powers of two,
4040
the second line is the largest prime less than 6000,
41-
and the third line is a selection from Knuth, Vol. 3, Sec. 6.1, Table 1.
42-
The final value is a sentinel and should cause the memory allocation
43-
of that many entries to fail (if none of the earlier values cause such
44-
failure already).
41+
the third line is a selection from Knuth, Vol. 3, Sec. 6.1, Table 1,
42+
and the next three lines were suggested by Steve Kirsch.
43+
The final value is a sentinel.
4544
*/
46-
static unsigned int primes[] = {
45+
static long primes[] = {
4746
3, 7, 13, 31, 61, 127, 251, 509, 1021, 2017, 4093,
4847
5987,
4948
9551, 15683, 19609, 31397,
50-
0xffffffff /* All bits set -- truncation OK */
49+
65521L, 131071L, 262139L, 524287L, 1048573L, 2097143L,
50+
4194301L, 8388593L, 16777213L, 33554393L, 67108859L,
51+
134217689L, 268435399L, 536870909L, 1073741789L,
52+
0
5153
};
5254

5355
/* Object used as dummy key to fill deleted entries */
@@ -207,8 +209,18 @@ mappingresize(mp)
207209
register int i;
208210
newsize = mp->ma_size;
209211
for (i = 0; ; i++) {
212+
if (primes[i] <= 0) {
213+
/* Ran out of primes */
214+
err_nomem();
215+
return -1;
216+
}
210217
if (primes[i] > mp->ma_used*2) {
211218
newsize = primes[i];
219+
if (newsize != primes[i]) {
220+
/* Integer truncation */
221+
err_nomem();
222+
return -1;
223+
}
212224
break;
213225
}
214226
}
@@ -406,15 +418,6 @@ mapping_print(mp, fp, flags)
406418
return 0;
407419
}
408420

409-
static void
410-
js(pv, w)
411-
object **pv;
412-
object *w;
413-
{
414-
joinstring(pv, w);
415-
XDECREF(w);
416-
}
417-
418421
static object *
419422
mapping_repr(mp)
420423
mappingobject *mp;
@@ -428,16 +431,16 @@ mapping_repr(mp)
428431
sepa = newstringobject(", ");
429432
colon = newstringobject(": ");
430433
any = 0;
431-
for (i = 0, ep = mp->ma_table; i < mp->ma_size; i++, ep++) {
434+
for (i = 0, ep = mp->ma_table; i < mp->ma_size && v; i++, ep++) {
432435
if (ep->me_value != NULL) {
433436
if (any++)
434437
joinstring(&v, sepa);
435-
js(&v, reprobject(ep->me_key));
438+
joinstring_decref(&v, reprobject(ep->me_key));
436439
joinstring(&v, colon);
437-
js(&v, reprobject(ep->me_value));
440+
joinstring_decref(&v, reprobject(ep->me_value));
438441
}
439442
}
440-
js(&v, newstringobject("}"));
443+
joinstring_decref(&v, newstringobject("}"));
441444
XDECREF(sepa);
442445
XDECREF(colon);
443446
return v;
@@ -483,9 +486,9 @@ mapping_ass_sub(mp, v, w)
483486
}
484487

485488
static mapping_methods mapping_as_mapping = {
486-
mapping_length, /*mp_length*/
487-
mapping_subscript, /*mp_subscript*/
488-
mapping_ass_sub, /*mp_ass_subscript*/
489+
(inquiry)mapping_length, /*mp_length*/
490+
(binaryfunc)mapping_subscript, /*mp_subscript*/
491+
(objobjargproc)mapping_ass_sub, /*mp_ass_subscript*/
489492
};
490493

491494
static object *
@@ -607,7 +610,7 @@ getmappingitems(mp)
607610
err_badcall();
608611
return NULL;
609612
}
610-
return mapping_values((mappingobject *)mp, (object *)NULL);
613+
return mapping_items((mappingobject *)mp, (object *)NULL);
611614
}
612615

613616
static int
@@ -702,10 +705,10 @@ mapping_has_key(mp, args)
702705
}
703706

704707
static struct methodlist mapp_methods[] = {
705-
{"has_key", mapping_has_key},
706-
{"items", mapping_items},
707-
{"keys", mapping_keys},
708-
{"values", mapping_values},
708+
{"has_key", (method)mapping_has_key},
709+
{"items", (method)mapping_items},
710+
{"keys", (method)mapping_keys},
711+
{"values", (method)mapping_values},
709712
{NULL, NULL} /* sentinel */
710713
};
711714

@@ -723,12 +726,12 @@ typeobject Mappingtype = {
723726
"dictionary",
724727
sizeof(mappingobject),
725728
0,
726-
mapping_dealloc, /*tp_dealloc*/
727-
mapping_print, /*tp_print*/
728-
mapping_getattr, /*tp_getattr*/
729+
(destructor)mapping_dealloc, /*tp_dealloc*/
730+
(printfunc)mapping_print, /*tp_print*/
731+
(getattrfunc)mapping_getattr, /*tp_getattr*/
729732
0, /*tp_setattr*/
730-
mapping_compare, /*tp_compare*/
731-
mapping_repr, /*tp_repr*/
733+
(cmpfunc)mapping_compare, /*tp_compare*/
734+
(reprfunc)mapping_repr, /*tp_repr*/
732735
0, /*tp_as_number*/
733736
0, /*tp_as_sequence*/
734737
&mapping_as_mapping, /*tp_as_mapping*/

Objects/frameobject.c

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/***********************************************************
2-
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
2+
Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
33
Amsterdam, The Netherlands.
44
55
All Rights Reserved
@@ -34,15 +34,16 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3434
#define OFF(x) offsetof(frameobject, x)
3535

3636
static struct memberlist frame_memberlist[] = {
37-
{"f_back", T_OBJECT, OFF(f_back)},
38-
{"f_code", T_OBJECT, OFF(f_code)},
39-
{"f_globals", T_OBJECT, OFF(f_globals)},
40-
{"f_locals", T_OBJECT, OFF(f_locals)},
41-
{"f_owner", T_OBJECT, OFF(f_owner)},
42-
/* {"f_fastlocals",T_OBJECT, OFF(f_fastlocals)}, /* XXX Unsafe */
43-
{"f_localmap", T_OBJECT, OFF(f_localmap)},
44-
{"f_lasti", T_INT, OFF(f_lasti)},
45-
{"f_lineno", T_INT, OFF(f_lineno)},
37+
{"f_back", T_OBJECT, OFF(f_back), RO},
38+
{"f_code", T_OBJECT, OFF(f_code), RO},
39+
{"f_globals", T_OBJECT, OFF(f_globals), RO},
40+
{"f_locals", T_OBJECT, OFF(f_locals), RO},
41+
{"f_owner", T_OBJECT, OFF(f_owner), RO},
42+
/* {"f_fastlocals",T_OBJECT, OFF(f_fastlocals),RO}, /* XXX Unsafe */
43+
{"f_localmap", T_OBJECT, OFF(f_localmap),RO},
44+
{"f_lasti", T_INT, OFF(f_lasti), RO},
45+
{"f_lineno", T_INT, OFF(f_lineno), RO},
46+
{"f_trace", T_OBJECT, OFF(f_trace)},
4647
{NULL} /* Sentinel */
4748
};
4849

@@ -51,9 +52,20 @@ frame_getattr(f, name)
5152
frameobject *f;
5253
char *name;
5354
{
55+
if (strcmp(name, "f_locals") == 0)
56+
fast_2_locals(f);
5457
return getmember((char *)f, frame_memberlist, name);
5558
}
5659

60+
static int
61+
frame_setattr(f, name, value)
62+
frameobject *f;
63+
char *name;
64+
object *value;
65+
{
66+
return setmember((char *)f, frame_memberlist, name, value);
67+
}
68+
5769
/* Stack frames are allocated and deallocated at a considerable rate.
5870
In an attempt to improve the speed of function calls, we maintain a
5971
separate free list of stack frames (just like integers are
@@ -88,6 +100,7 @@ frame_dealloc(f)
88100
XDECREF(f->f_owner);
89101
XDECREF(f->f_fastlocals);
90102
XDECREF(f->f_localmap);
103+
XDECREF(f->f_trace);
91104
f->f_back = free_list;
92105
free_list = f;
93106
}
@@ -98,10 +111,10 @@ typeobject Frametype = {
98111
"frame",
99112
sizeof(frameobject),
100113
0,
101-
frame_dealloc, /*tp_dealloc*/
114+
(destructor)frame_dealloc, /*tp_dealloc*/
102115
0, /*tp_print*/
103-
frame_getattr, /*tp_getattr*/
104-
0, /*tp_setattr*/
116+
(getattrfunc)frame_getattr, /*tp_getattr*/
117+
(setattrfunc)frame_setattr, /*tp_setattr*/
105118
0, /*tp_compare*/
106119
0, /*tp_repr*/
107120
0, /*tp_as_number*/
@@ -167,6 +180,7 @@ newframeobject(back, code, globals, locals, owner, nvalues, nblocks)
167180
f->f_iblock = 0;
168181
f->f_lasti = 0;
169182
f->f_lineno = -1;
183+
f->f_trace = NULL;
170184
if (f->f_valuestack == NULL || f->f_blockstack == NULL) {
171185
err_nomem();
172186
DECREF(f);
@@ -225,3 +239,74 @@ pop_block(f)
225239
b = &f->f_blockstack[--f->f_iblock];
226240
return b;
227241
}
242+
243+
/* Convert between "fast" version of locals and dictionary version */
244+
245+
void
246+
fast_2_locals(f)
247+
frameobject *f;
248+
{
249+
/* Merge f->f_fastlocals into f->f_locals */
250+
object *locals, *fast, *map;
251+
object *error_type, *error_value;
252+
int j;
253+
if (f == NULL)
254+
return;
255+
locals = f->f_locals;
256+
fast = f->f_fastlocals;
257+
map = f->f_localmap;
258+
if (locals == NULL || fast == NULL || map == NULL)
259+
return;
260+
if (!is_dictobject(locals) || !is_listobject(fast) ||
261+
!is_tupleobject(map))
262+
return;
263+
err_get(&error_type, &error_value);
264+
for (j = gettuplesize(map); --j >= 0; ) {
265+
object *key = gettupleitem(map, j);
266+
object *value = getlistitem(fast, j);
267+
if (value == NULL) {
268+
err_clear();
269+
if (dict2remove(locals, key) != 0)
270+
err_clear();
271+
}
272+
else {
273+
if (dict2insert(locals, key, value) != 0)
274+
err_clear();
275+
}
276+
}
277+
err_setval(error_type, error_value);
278+
}
279+
280+
void
281+
locals_2_fast(f, clear)
282+
frameobject *f;
283+
int clear;
284+
{
285+
/* Merge f->f_locals into f->f_fastlocals */
286+
object *locals, *fast, *map;
287+
object *error_type, *error_value;
288+
int j;
289+
if (f == NULL)
290+
return;
291+
locals = f->f_locals;
292+
fast = f->f_fastlocals;
293+
map = f->f_localmap;
294+
if (locals == NULL || fast == NULL || map == NULL)
295+
return;
296+
if (!is_dictobject(locals) || !is_listobject(fast) ||
297+
!is_tupleobject(map))
298+
return;
299+
err_get(&error_type, &error_value);
300+
for (j = gettuplesize(map); --j >= 0; ) {
301+
object *key = gettupleitem(map, j);
302+
object *value = dict2lookup(locals, key);
303+
if (value == NULL)
304+
err_clear();
305+
else
306+
INCREF(value);
307+
if (value != NULL || clear)
308+
if (setlistitem(fast, j, value) != 0)
309+
err_clear();
310+
}
311+
err_setval(error_type, error_value);
312+
}

0 commit comments

Comments
 (0)