mirror of https://github.com/python/cpython
* Changed all copyright messages to include 1993.
* Stubs for faster implementation of local variables (not yet finished) * Added function name to code object. Print it for code and function objects. THIS MAKES THE .PYC FILE FORMAT INCOMPATIBLE (the version number has changed accordingly) * Print address of self for built-in methods * New internal functions getattro and setattro (getattr/setattr with string object arg) * Replaced "dictobject" with more powerful "mappingobject" * New per-type functio tp_hash to implement arbitrary object hashing, and hashobject() to interface to it * Added built-in functions hash(v) and hasattr(v, 'name') * classobject: made some functions static that accidentally weren't; added __hash__ special instance method to implement hash() * Added proper comparison for built-in methods and functions
This commit is contained in:
parent
4b1302bd1d
commit
9bfef44d97
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -28,7 +28,9 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* An intermediate code fragment contains:
|
/* An intermediate code fragment contains:
|
||||||
- a string that encodes the instructions,
|
- a string that encodes the instructions,
|
||||||
- a list of the constants,
|
- a list of the constants,
|
||||||
- and a list of the names used. */
|
- a list of the names used,
|
||||||
|
- the filename from which it was compiled,
|
||||||
|
- the name of the object for which it was compiled. */
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
OB_HEAD
|
OB_HEAD
|
||||||
|
@ -36,6 +38,7 @@ typedef struct {
|
||||||
object *co_consts; /* list of immutable constant objects */
|
object *co_consts; /* list of immutable constant objects */
|
||||||
object *co_names; /* list of stringobjects */
|
object *co_names; /* list of stringobjects */
|
||||||
object *co_filename; /* string */
|
object *co_filename; /* string */
|
||||||
|
object *co_name; /* string */
|
||||||
} codeobject;
|
} codeobject;
|
||||||
|
|
||||||
extern typeobject Codetype;
|
extern typeobject Codetype;
|
||||||
|
@ -46,4 +49,5 @@ extern typeobject Codetype;
|
||||||
/* Public interface */
|
/* Public interface */
|
||||||
struct _node; /* Declare the existence of this type */
|
struct _node; /* Declare the existence of this type */
|
||||||
codeobject *compile PROTO((struct _node *, char *));
|
codeobject *compile PROTO((struct _node *, char *));
|
||||||
codeobject *newcodeobject PROTO((object *, object *, object *, object *));
|
codeobject *newcodeobject
|
||||||
|
PROTO((object *, object *, object *, object *, object *));
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -22,28 +22,23 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
******************************************************************/
|
******************************************************************/
|
||||||
|
|
||||||
/*
|
/* All in the sake of backward compatibility... */
|
||||||
Dictionary object type -- mapping from char * to object.
|
|
||||||
NB: the key is given as a char *, not as a stringobject.
|
|
||||||
These functions set errno for errors. Functions dictremove() and
|
|
||||||
dictinsert() return nonzero for errors, getdictsize() returns -1,
|
|
||||||
the others NULL. A successful call to dictinsert() calls INCREF()
|
|
||||||
for the inserted item.
|
|
||||||
*/
|
|
||||||
|
|
||||||
extern typeobject Dicttype;
|
#include "mappingobject.h"
|
||||||
|
|
||||||
#define is_dictobject(op) ((op)->ob_type == &Dicttype)
|
#define is_dictobject(op) is_mappingobject(op)
|
||||||
|
|
||||||
|
#define newdictobject newmappingobject
|
||||||
|
|
||||||
extern object *newdictobject PROTO((void));
|
|
||||||
extern object *dictlookup PROTO((object *dp, char *key));
|
extern object *dictlookup PROTO((object *dp, char *key));
|
||||||
extern int dictinsert PROTO((object *dp, char *key, object *item));
|
extern int dictinsert PROTO((object *dp, char *key, object *item));
|
||||||
extern int dictremove PROTO((object *dp, char *key));
|
extern int dictremove PROTO((object *dp, char *key));
|
||||||
extern int getdictsize PROTO((object *dp));
|
|
||||||
extern char *getdictkey PROTO((object *dp, int i));
|
extern char *getdictkey PROTO((object *dp, int i));
|
||||||
extern object *getdictkeys PROTO((object *dp));
|
|
||||||
|
|
||||||
extern object *getdict2key PROTO((object *dp, int i));
|
#define getdictsize getmappingsize
|
||||||
extern object *dict2lookup PROTO((object *dp, object *key));
|
#define getdictkeys getmappingkeys
|
||||||
extern int dict2insert PROTO((object *dp, object *key, object *item));
|
|
||||||
extern int dict2remove PROTO((object *dp, object *key));
|
#define getdict2key getmappingkey
|
||||||
|
#define dict2lookup mappinglookup
|
||||||
|
#define dict2insert mappinginsert
|
||||||
|
#define dict2remove mappingremove
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -188,6 +188,10 @@ typedef struct _typeobject {
|
||||||
number_methods *tp_as_number;
|
number_methods *tp_as_number;
|
||||||
sequence_methods *tp_as_sequence;
|
sequence_methods *tp_as_sequence;
|
||||||
mapping_methods *tp_as_mapping;
|
mapping_methods *tp_as_mapping;
|
||||||
|
|
||||||
|
/* More standard operations (at end for binary compatibility) */
|
||||||
|
|
||||||
|
long (*tp_hash) FPROTO((object *));
|
||||||
} typeobject;
|
} typeobject;
|
||||||
|
|
||||||
extern typeobject Typetype; /* The type of type objects */
|
extern typeobject Typetype; /* The type of type objects */
|
||||||
|
@ -199,7 +203,9 @@ extern int printobject PROTO((object *, FILE *, int));
|
||||||
extern object * reprobject PROTO((object *));
|
extern object * reprobject PROTO((object *));
|
||||||
extern int cmpobject PROTO((object *, object *));
|
extern int cmpobject PROTO((object *, object *));
|
||||||
extern object *getattr PROTO((object *, char *));
|
extern object *getattr PROTO((object *, char *));
|
||||||
extern int setattr PROTO((object *, char *, object *));
|
extern object *getattro PROTO((object *, object *));
|
||||||
|
extern int setattro PROTO((object *, object *, object *));
|
||||||
|
extern long hashobject PROTO((object *));
|
||||||
|
|
||||||
/* Flag bits for printing: */
|
/* Flag bits for printing: */
|
||||||
#define PRINT_RAW 1 /* No string quotes etc. */
|
#define PRINT_RAW 1 /* No string quotes etc. */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -113,6 +113,10 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
#define LOAD_LOCAL 115 /* Index in name list */
|
#define LOAD_LOCAL 115 /* Index in name list */
|
||||||
#define LOAD_GLOBAL 116 /* Index in name list */
|
#define LOAD_GLOBAL 116 /* Index in name list */
|
||||||
|
|
||||||
|
#define LOAD_FAST 117 /* Local variable number */
|
||||||
|
#define STORE_FAST 118 /* Local variable number */
|
||||||
|
#define RESERVE_FAST 119 /* Number of local variables */
|
||||||
|
|
||||||
#define SETUP_LOOP 120 /* Target address (absolute) */
|
#define SETUP_LOOP 120 /* Target address (absolute) */
|
||||||
#define SETUP_EXCEPT 121 /* "" */
|
#define SETUP_EXCEPT 121 /* "" */
|
||||||
#define SETUP_FINALLY 122 /* "" */
|
#define SETUP_FINALLY 122 /* "" */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/**********************************************************
|
/**********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -62,12 +62,12 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
#include "patchlevel.h"
|
#include "patchlevel.h"
|
||||||
|
|
||||||
#define VERSION "0.9.%d (%s)"
|
#define VERSION "0.9.%d BETA (%s)"
|
||||||
|
|
||||||
#ifdef __DATE__
|
#ifdef __DATE__
|
||||||
#define DATE __DATE__
|
#define DATE __DATE__
|
||||||
#else
|
#else
|
||||||
#define DATE ">= 11 Jan 1993"
|
#define DATE ">= 27 Mar 1993"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_STDWIN
|
#ifdef USE_STDWIN
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -58,7 +58,7 @@ static imgfile_error(str)
|
||||||
{
|
{
|
||||||
err_setstr(ImgfileError, str);
|
err_setstr(ImgfileError, str);
|
||||||
error_called = 1;
|
error_called = 1;
|
||||||
return; /* To imglib, which will return a failure indictaor */
|
return; /* To imglib, which will return a failure indicator */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -261,7 +261,7 @@ instance_setattr(inst, name, v)
|
||||||
return dictinsert(inst->in_attr, name, v);
|
return dictinsert(inst->in_attr, name, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
object *
|
static object *
|
||||||
instance_repr(inst)
|
instance_repr(inst)
|
||||||
instanceobject *inst;
|
instanceobject *inst;
|
||||||
{
|
{
|
||||||
|
@ -280,7 +280,7 @@ instance_repr(inst)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
instance_compare(inst, other)
|
instance_compare(inst, other)
|
||||||
instanceobject *inst, *other;
|
instanceobject *inst, *other;
|
||||||
{
|
{
|
||||||
|
@ -311,7 +311,43 @@ instance_compare(inst, other)
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static long
|
||||||
|
instance_hash(inst)
|
||||||
|
instanceobject *inst;
|
||||||
|
{
|
||||||
|
object *func;
|
||||||
|
object *res;
|
||||||
|
int outcome;
|
||||||
|
|
||||||
|
func = instance_getattr(inst, "__hash__");
|
||||||
|
if (func == NULL) {
|
||||||
|
/* If there is no __cmp__ method, we hash on the address.
|
||||||
|
If a __cmp__ method exists, there must be a __hash__. */
|
||||||
|
err_clear();
|
||||||
|
func = instance_getattr(inst, "__cmp__");
|
||||||
|
if (func == NULL)
|
||||||
|
return (long)inst;
|
||||||
|
err_setstr(TypeError, "unhashable instance");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
res = call_object(func, (object *)NULL);
|
||||||
|
DECREF(func);
|
||||||
|
if (res == NULL)
|
||||||
|
return -1;
|
||||||
|
if (is_intobject(res)) {
|
||||||
|
outcome = getintvalue(res);
|
||||||
|
if (outcome == -1)
|
||||||
|
outcome = -2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
err_setstr(TypeError, "__hash__() should return an int");
|
||||||
|
outcome = -1;
|
||||||
|
}
|
||||||
|
DECREF(res);
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
instance_length(inst)
|
instance_length(inst)
|
||||||
instanceobject *inst;
|
instanceobject *inst;
|
||||||
{
|
{
|
||||||
|
@ -339,7 +375,7 @@ instance_length(inst)
|
||||||
return outcome;
|
return outcome;
|
||||||
}
|
}
|
||||||
|
|
||||||
object *
|
static object *
|
||||||
instance_subscript(inst, key)
|
instance_subscript(inst, key)
|
||||||
instanceobject *inst;
|
instanceobject *inst;
|
||||||
object *key;
|
object *key;
|
||||||
|
@ -362,7 +398,7 @@ instance_subscript(inst, key)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
static int
|
||||||
instance_ass_subscript(inst, key, value)
|
instance_ass_subscript(inst, key, value)
|
||||||
instanceobject*inst;
|
instanceobject*inst;
|
||||||
object *key;
|
object *key;
|
||||||
|
@ -395,7 +431,7 @@ instance_ass_subscript(inst, key, value)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping_methods instance_as_mapping = {
|
static mapping_methods instance_as_mapping = {
|
||||||
instance_length, /*mp_length*/
|
instance_length, /*mp_length*/
|
||||||
instance_subscript, /*mp_subscript*/
|
instance_subscript, /*mp_subscript*/
|
||||||
instance_ass_subscript, /*mp_ass_subscript*/
|
instance_ass_subscript, /*mp_ass_subscript*/
|
||||||
|
@ -612,7 +648,7 @@ UNARY(instance_neg, "__neg__")
|
||||||
UNARY(instance_pos, "__pos__")
|
UNARY(instance_pos, "__pos__")
|
||||||
UNARY(instance_abs, "__abs__")
|
UNARY(instance_abs, "__abs__")
|
||||||
|
|
||||||
int
|
static int
|
||||||
instance_nonzero(self)
|
instance_nonzero(self)
|
||||||
instanceobject *self;
|
instanceobject *self;
|
||||||
{
|
{
|
||||||
|
@ -739,9 +775,10 @@ typeobject Instancetype = {
|
||||||
&instance_as_number, /*tp_as_number*/
|
&instance_as_number, /*tp_as_number*/
|
||||||
&instance_as_sequence, /*tp_as_sequence*/
|
&instance_as_sequence, /*tp_as_sequence*/
|
||||||
&instance_as_mapping, /*tp_as_mapping*/
|
&instance_as_mapping, /*tp_as_mapping*/
|
||||||
|
instance_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
||||||
object *
|
static object *
|
||||||
instance_convert(inst, methodname)
|
instance_convert(inst, methodname)
|
||||||
object *inst;
|
object *inst;
|
||||||
char *methodname;
|
char *methodname;
|
||||||
|
@ -837,6 +874,20 @@ instancemethod_compare(a, b)
|
||||||
return cmp;
|
return cmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
instancemethod_hash(a)
|
||||||
|
instancemethodobject *a;
|
||||||
|
{
|
||||||
|
long x, y;
|
||||||
|
x = hashobject(a->im_self);
|
||||||
|
if (x == -1)
|
||||||
|
return -1;
|
||||||
|
y = hashobject(a->im_func);
|
||||||
|
if (y == -1)
|
||||||
|
return -1;
|
||||||
|
return x ^ y;
|
||||||
|
}
|
||||||
|
|
||||||
typeobject Instancemethodtype = {
|
typeobject Instancemethodtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
OB_HEAD_INIT(&Typetype)
|
||||||
0,
|
0,
|
||||||
|
@ -852,4 +903,5 @@ typeobject Instancemethodtype = {
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
0, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
instancemethod_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,8 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* Mapping object implementation; using a hash table */
|
/* Mapping object implementation; using a hash table */
|
||||||
|
|
||||||
|
/* This file should really be called "dictobject.c", since "mapping"
|
||||||
|
is the generic name for objects with an unorderred arbitrary key
|
||||||
|
set (just like lists are sequences), but since it improves (and was
|
||||||
|
originally derived from) a file by that name I had to change its
|
||||||
|
name. For the user these objects are still called "dictionaries". */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "mappingobject.h"
|
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -593,7 +598,7 @@ mapping_getattr(mp, name)
|
||||||
typeobject Mappingtype = {
|
typeobject Mappingtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
OB_HEAD_INIT(&Typetype)
|
||||||
0,
|
0,
|
||||||
"mapping",
|
"dictionary",
|
||||||
sizeof(mappingobject),
|
sizeof(mappingobject),
|
||||||
0,
|
0,
|
||||||
mapping_dealloc, /*tp_dealloc*/
|
mapping_dealloc, /*tp_dealloc*/
|
||||||
|
|
|
@ -145,6 +145,38 @@ float_compare(v, w)
|
||||||
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
float_hash(v)
|
||||||
|
floatobject *v;
|
||||||
|
{
|
||||||
|
double intpart, fractpart;
|
||||||
|
int expo;
|
||||||
|
long x;
|
||||||
|
/* This is designed so that Python numbers with the same
|
||||||
|
value hash to the same value, otherwise comparisons
|
||||||
|
of mapping keys will turn out weird */
|
||||||
|
fractpart = modf(v->ob_fval, &intpart);
|
||||||
|
if (fractpart == 0.0) {
|
||||||
|
if (intpart > 0x7fffffffL || -intpart > 0x7fffffffL) {
|
||||||
|
/* Convert to long int and use its hash... */
|
||||||
|
object *w = dnewlongobject(v->ob_fval);
|
||||||
|
if (w == NULL)
|
||||||
|
return -1;
|
||||||
|
x = hashobject(w);
|
||||||
|
DECREF(w);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
x = (long)intpart;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fractpart = frexp(fractpart, &expo);
|
||||||
|
x = (long) (intpart + fractpart) ^ expo; /* Rather arbitrary */
|
||||||
|
}
|
||||||
|
if (x == -1)
|
||||||
|
x = -2;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
float_add(v, w)
|
float_add(v, w)
|
||||||
floatobject *v;
|
floatobject *v;
|
||||||
|
@ -378,4 +410,5 @@ typeobject Floattype = {
|
||||||
&float_as_number, /*tp_as_number*/
|
&float_as_number, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
0, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
float_hash, /*tp_hash */
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
/* Function object implementation */
|
/* Function object implementation */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
|
#include "compile.h"
|
||||||
#include "structmember.h"
|
#include "structmember.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -98,6 +98,17 @@ func_dealloc(op)
|
||||||
DEL(op);
|
DEL(op);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static object*
|
||||||
|
func_repr(op)
|
||||||
|
funcobject *op;
|
||||||
|
{
|
||||||
|
char buf[140];
|
||||||
|
sprintf(buf, "<function %.100s at %lx>",
|
||||||
|
getstringvalue(((codeobject*)(op->func_code))->co_name),
|
||||||
|
(long)op);
|
||||||
|
return newstringobject(buf);
|
||||||
|
}
|
||||||
|
|
||||||
typeobject Functype = {
|
typeobject Functype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
OB_HEAD_INIT(&Typetype)
|
||||||
0,
|
0,
|
||||||
|
@ -109,5 +120,5 @@ typeobject Functype = {
|
||||||
func_getattr, /*tp_getattr*/
|
func_getattr, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
0, /*tp_compare*/
|
0, /*tp_compare*/
|
||||||
0, /*tp_repr*/
|
func_repr, /*tp_repr*/
|
||||||
};
|
};
|
||||||
|
|
|
@ -144,6 +144,16 @@ int_compare(v, w)
|
||||||
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
return (i < j) ? -1 : (i > j) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
int_hash(v)
|
||||||
|
intobject *v;
|
||||||
|
{
|
||||||
|
long x = v -> ob_ival;
|
||||||
|
if (x == -1)
|
||||||
|
x = -2;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_add(v, w)
|
int_add(v, w)
|
||||||
intobject *v;
|
intobject *v;
|
||||||
|
@ -413,7 +423,7 @@ int_or(v, w)
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_int(v)
|
int_int(v)
|
||||||
object *v;
|
intobject *v;
|
||||||
{
|
{
|
||||||
INCREF(v);
|
INCREF(v);
|
||||||
return v;
|
return v;
|
||||||
|
@ -421,26 +431,24 @@ int_int(v)
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_long(v)
|
int_long(v)
|
||||||
object *v;
|
intobject *v;
|
||||||
{
|
{
|
||||||
long x = getintvalue(v);
|
return newlongobject((v -> ob_ival));
|
||||||
return newlongobject(x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_float(v)
|
int_float(v)
|
||||||
object *v;
|
intobject *v;
|
||||||
{
|
{
|
||||||
long x = getintvalue(v);
|
return newfloatobject((double)(v -> ob_ival));
|
||||||
return newfloatobject((double)x);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_oct(v)
|
int_oct(v)
|
||||||
object *v;
|
intobject *v;
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
long x = getintvalue(v);
|
long x = v -> ob_ival;
|
||||||
if (x == 0)
|
if (x == 0)
|
||||||
strcpy(buf, "0");
|
strcpy(buf, "0");
|
||||||
else if (x > 0)
|
else if (x > 0)
|
||||||
|
@ -452,10 +460,10 @@ int_oct(v)
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
int_hex(v)
|
int_hex(v)
|
||||||
object *v;
|
intobject *v;
|
||||||
{
|
{
|
||||||
char buf[20];
|
char buf[20];
|
||||||
long x = getintvalue(v);
|
long x = v -> ob_ival;
|
||||||
if (x >= 0)
|
if (x >= 0)
|
||||||
sprintf(buf, "0x%lx", x);
|
sprintf(buf, "0x%lx", x);
|
||||||
else
|
else
|
||||||
|
@ -463,7 +471,6 @@ int_hex(v)
|
||||||
return newstringobject(buf);
|
return newstringobject(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static number_methods int_as_number = {
|
static number_methods int_as_number = {
|
||||||
int_add, /*nb_add*/
|
int_add, /*nb_add*/
|
||||||
int_sub, /*nb_subtract*/
|
int_sub, /*nb_subtract*/
|
||||||
|
@ -505,4 +512,5 @@ typeobject Inttype = {
|
||||||
&int_as_number, /*tp_as_number*/
|
&int_as_number, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
0, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
&int_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
|
@ -555,6 +555,7 @@ static void long_dealloc PROTO((object *));
|
||||||
static int long_print PROTO((object *, FILE *, int));
|
static int long_print PROTO((object *, FILE *, int));
|
||||||
static object *long_repr PROTO((object *));
|
static object *long_repr PROTO((object *));
|
||||||
static int long_compare PROTO((longobject *, longobject *));
|
static int long_compare PROTO((longobject *, longobject *));
|
||||||
|
static long long_hash PROTO((longobject *));
|
||||||
|
|
||||||
static object *long_add PROTO((longobject *, longobject *));
|
static object *long_add PROTO((longobject *, longobject *));
|
||||||
static object *long_sub PROTO((longobject *, longobject *));
|
static object *long_sub PROTO((longobject *, longobject *));
|
||||||
|
@ -615,6 +616,35 @@ long_compare(a, b)
|
||||||
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
|
return sign < 0 ? -1 : sign > 0 ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
long_hash(v)
|
||||||
|
longobject *v;
|
||||||
|
{
|
||||||
|
long x;
|
||||||
|
int i, sign;
|
||||||
|
|
||||||
|
/* This is designed so that Python ints and longs with the
|
||||||
|
same value hash to the same value, otherwise comparisons
|
||||||
|
of mapping keys will turn out weird */
|
||||||
|
i = v->ob_size;
|
||||||
|
sign = 1;
|
||||||
|
x = 0;
|
||||||
|
if (i < 0) {
|
||||||
|
sign = -1;
|
||||||
|
i = -(i);
|
||||||
|
}
|
||||||
|
while (--i >= 0) {
|
||||||
|
/* Force a 32-bit circular shift */
|
||||||
|
x = ((x << SHIFT) & ~MASK) | ((x >> (32-SHIFT)) & MASK);
|
||||||
|
x += v->ob_digit[i];
|
||||||
|
}
|
||||||
|
x = x * sign;
|
||||||
|
if (x == -1)
|
||||||
|
x = -2;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Add the absolute values of two long integers. */
|
/* Add the absolute values of two long integers. */
|
||||||
|
|
||||||
static longobject *x_add PROTO((longobject *, longobject *));
|
static longobject *x_add PROTO((longobject *, longobject *));
|
||||||
|
@ -1346,4 +1376,6 @@ typeobject Longtype = {
|
||||||
&long_as_number,/*tp_as_number*/
|
&long_as_number,/*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
0, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
(long (*) FPROTO((object *)))
|
||||||
|
long_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
|
@ -24,8 +24,13 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
/* Mapping object implementation; using a hash table */
|
/* Mapping object implementation; using a hash table */
|
||||||
|
|
||||||
|
/* This file should really be called "dictobject.c", since "mapping"
|
||||||
|
is the generic name for objects with an unorderred arbitrary key
|
||||||
|
set (just like lists are sequences), but since it improves (and was
|
||||||
|
originally derived from) a file by that name I had to change its
|
||||||
|
name. For the user these objects are still called "dictionaries". */
|
||||||
|
|
||||||
#include "allobjects.h"
|
#include "allobjects.h"
|
||||||
#include "mappingobject.h"
|
|
||||||
#include "modsupport.h"
|
#include "modsupport.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -593,7 +598,7 @@ mapping_getattr(mp, name)
|
||||||
typeobject Mappingtype = {
|
typeobject Mappingtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
OB_HEAD_INIT(&Typetype)
|
||||||
0,
|
0,
|
||||||
"mapping",
|
"dictionary",
|
||||||
sizeof(mappingobject),
|
sizeof(mappingobject),
|
||||||
0,
|
0,
|
||||||
mapping_dealloc, /*tp_dealloc*/
|
mapping_dealloc, /*tp_dealloc*/
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -108,11 +108,41 @@ meth_repr(m)
|
||||||
sprintf(buf, "<built-in function '%.80s'>", m->m_name);
|
sprintf(buf, "<built-in function '%.80s'>", m->m_name);
|
||||||
else
|
else
|
||||||
sprintf(buf,
|
sprintf(buf,
|
||||||
"<built-in method '%.80s' of some %.80s object>",
|
"<built-in method '%.80s' of %.80s object at %lx>",
|
||||||
m->m_name, m->m_self->ob_type->tp_name);
|
m->m_name, m->m_self->ob_type->tp_name,
|
||||||
|
(long)m->m_self);
|
||||||
return newstringobject(buf);
|
return newstringobject(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
meth_compare(a, b)
|
||||||
|
methodobject *a, *b;
|
||||||
|
{
|
||||||
|
if (a->m_self != b->m_self)
|
||||||
|
return cmpobject(a->m_self, b->m_self);
|
||||||
|
if (a->m_meth == b->m_meth)
|
||||||
|
return 0;
|
||||||
|
if (strcmp(a->m_name, b->m_name) < 0)
|
||||||
|
return -1;
|
||||||
|
else
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
meth_hash(a)
|
||||||
|
methodobject *a;
|
||||||
|
{
|
||||||
|
long x, y;
|
||||||
|
if (a->m_self == NULL)
|
||||||
|
x = 0;
|
||||||
|
else {
|
||||||
|
x = hashobject(a->m_self);
|
||||||
|
if (x == -1)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return x ^ (long) a->m_meth;
|
||||||
|
}
|
||||||
|
|
||||||
typeobject Methodtype = {
|
typeobject Methodtype = {
|
||||||
OB_HEAD_INIT(&Typetype)
|
OB_HEAD_INIT(&Typetype)
|
||||||
0,
|
0,
|
||||||
|
@ -123,11 +153,12 @@ typeobject Methodtype = {
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
0, /*tp_compare*/
|
meth_compare, /*tp_compare*/
|
||||||
meth_repr, /*tp_repr*/
|
meth_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*/
|
||||||
|
meth_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
||||||
object *listmethods PROTO((struct methodlist *)); /* Forward */
|
object *listmethods PROTO((struct methodlist *)); /* Forward */
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -165,6 +165,20 @@ cmpobject(v, w)
|
||||||
return (*tp->tp_compare)(v, w);
|
return (*tp->tp_compare)(v, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
long
|
||||||
|
hashobject(v)
|
||||||
|
object *v;
|
||||||
|
{
|
||||||
|
typeobject *tp = v->ob_type;
|
||||||
|
if (tp->tp_hash != NULL)
|
||||||
|
return (*tp->tp_hash)(v);
|
||||||
|
if (tp->tp_compare == NULL)
|
||||||
|
return (long) v; /* Use address as hash value */
|
||||||
|
/* If there's a cmp but no hash defined, the object can't be hashed */
|
||||||
|
err_setstr(TypeError, "unhashable type");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
object *
|
object *
|
||||||
getattr(v, name)
|
getattr(v, name)
|
||||||
object *v;
|
object *v;
|
||||||
|
@ -229,6 +243,7 @@ static typeobject Notype = {
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
0, /*tp_as_sequence*/
|
0, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
0, /*tp_hash */
|
||||||
};
|
};
|
||||||
|
|
||||||
object NoObject = {
|
object NoObject = {
|
||||||
|
|
|
@ -293,6 +293,21 @@ string_compare(a, b)
|
||||||
return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
|
return (len_a < len_b) ? -1 : (len_a > len_b) ? 1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
string_hash(a)
|
||||||
|
stringobject *a;
|
||||||
|
{
|
||||||
|
register int len = a->ob_size;
|
||||||
|
register unsigned char *p = (unsigned char *) a->ob_sval;
|
||||||
|
register long x = *p << 7;
|
||||||
|
while (--len >= 0)
|
||||||
|
x = (x + x + x) ^ *p++;
|
||||||
|
x ^= a->ob_size;
|
||||||
|
if (x == -1)
|
||||||
|
x = -2;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static sequence_methods string_as_sequence = {
|
static sequence_methods string_as_sequence = {
|
||||||
string_length, /*sq_length*/
|
string_length, /*sq_length*/
|
||||||
string_concat, /*sq_concat*/
|
string_concat, /*sq_concat*/
|
||||||
|
@ -318,6 +333,7 @@ typeobject Stringtype = {
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
&string_as_sequence, /*tp_as_sequence*/
|
&string_as_sequence, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
string_hash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -179,6 +179,27 @@ tuplecompare(v, w)
|
||||||
return v->ob_size - w->ob_size;
|
return v->ob_size - w->ob_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static long
|
||||||
|
tuplehash(v)
|
||||||
|
tupleobject *v;
|
||||||
|
{
|
||||||
|
register long x, y;
|
||||||
|
register int len = v->ob_size;
|
||||||
|
register object **p;
|
||||||
|
x = 0x345678L;
|
||||||
|
p = v->ob_item;
|
||||||
|
while (--len >= 0) {
|
||||||
|
y = hashobject(*p++);
|
||||||
|
if (y == -1)
|
||||||
|
return -1;
|
||||||
|
x = (x + x + x) ^ y;
|
||||||
|
}
|
||||||
|
x ^= v->ob_size;
|
||||||
|
if (x == -1)
|
||||||
|
x = -2;
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tuplelength(a)
|
tuplelength(a)
|
||||||
tupleobject *a;
|
tupleobject *a;
|
||||||
|
@ -329,4 +350,5 @@ typeobject Tupletype = {
|
||||||
0, /*tp_as_number*/
|
0, /*tp_as_number*/
|
||||||
&tuple_as_sequence, /*tp_as_sequence*/
|
&tuple_as_sequence, /*tp_as_sequence*/
|
||||||
0, /*tp_as_mapping*/
|
0, /*tp_as_mapping*/
|
||||||
|
tuplehash, /*tp_hash*/
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -281,10 +281,28 @@ builtin_getattr(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *v;
|
object *v;
|
||||||
char *name;
|
object *name;
|
||||||
if (!getargs(args, "(Os)", &v, &name))
|
if (!getargs(args, "(OS)", &v, &name))
|
||||||
return NULL;
|
return NULL;
|
||||||
return getattr(v, name);
|
return getattro(v, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
static object *
|
||||||
|
builtin_hasattr(self, args)
|
||||||
|
object *self;
|
||||||
|
object *args;
|
||||||
|
{
|
||||||
|
object *v;
|
||||||
|
object *name;
|
||||||
|
if (!getargs(args, "(OS)", &v, &name))
|
||||||
|
return NULL;
|
||||||
|
v = getattro(v, name);
|
||||||
|
if (v == NULL) {
|
||||||
|
err_clear();
|
||||||
|
return newintobject(0L);
|
||||||
|
}
|
||||||
|
DECREF(v);
|
||||||
|
return newintobject(1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
|
@ -293,16 +311,31 @@ builtin_setattr(self, args)
|
||||||
object *args;
|
object *args;
|
||||||
{
|
{
|
||||||
object *v;
|
object *v;
|
||||||
char *name;
|
object *name;
|
||||||
object *value;
|
object *value;
|
||||||
if (!getargs(args, "(OsO)", &v, &name, &value))
|
if (!getargs(args, "(OSO)", &v, &name, &value))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (setattr(v, name, value) != 0)
|
if (setattro(v, name, value) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
INCREF(None);
|
INCREF(None);
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static object *
|
||||||
|
builtin_hash(self, args)
|
||||||
|
object *self;
|
||||||
|
object *args;
|
||||||
|
{
|
||||||
|
object *v;
|
||||||
|
long x;
|
||||||
|
if (!getargs(args, "O", &v))
|
||||||
|
return NULL;
|
||||||
|
x = hashobject(v);
|
||||||
|
if (x == -1)
|
||||||
|
return NULL;
|
||||||
|
return newintobject(x);
|
||||||
|
}
|
||||||
|
|
||||||
static object *
|
static object *
|
||||||
builtin_hex(self, v)
|
builtin_hex(self, v)
|
||||||
object *self;
|
object *self;
|
||||||
|
@ -687,6 +720,8 @@ static struct methodlist builtin_methods[] = {
|
||||||
{"execfile", builtin_execfile},
|
{"execfile", builtin_execfile},
|
||||||
{"float", builtin_float},
|
{"float", builtin_float},
|
||||||
{"getattr", builtin_getattr},
|
{"getattr", builtin_getattr},
|
||||||
|
{"hasattr", builtin_hasattr},
|
||||||
|
{"hash", builtin_hash},
|
||||||
{"hex", builtin_hex},
|
{"hex", builtin_hex},
|
||||||
{"input", builtin_input},
|
{"input", builtin_input},
|
||||||
{"int", builtin_int},
|
{"int", builtin_int},
|
||||||
|
|
|
@ -173,6 +173,7 @@ eval_code(co, globals, locals, arg)
|
||||||
register object *u;
|
register object *u;
|
||||||
register object *t;
|
register object *t;
|
||||||
register frameobject *f; /* Current frame */
|
register frameobject *f; /* Current frame */
|
||||||
|
register listobject *fastlocals = NULL;
|
||||||
object *trace = NULL; /* Trace function or NULL */
|
object *trace = NULL; /* Trace function or NULL */
|
||||||
object *retval; /* Return value iff why == WHY_RETURN */
|
object *retval; /* Return value iff why == WHY_RETURN */
|
||||||
char *name; /* Name used by some instructions */
|
char *name; /* Name used by some instructions */
|
||||||
|
@ -911,19 +912,18 @@ eval_code(co, globals, locals, arg)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STORE_ATTR:
|
case STORE_ATTR:
|
||||||
name = GETNAME(oparg);
|
w = GETNAMEV(oparg);
|
||||||
v = POP();
|
v = POP();
|
||||||
u = POP();
|
u = POP();
|
||||||
err = setattr(v, name, u); /* v.name = u */
|
err = setattro(v, w, u); /* v.w = u */
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
DECREF(u);
|
DECREF(u);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DELETE_ATTR:
|
case DELETE_ATTR:
|
||||||
name = GETNAME(oparg);
|
w = GETNAMEV(oparg);
|
||||||
v = POP();
|
v = POP();
|
||||||
err = setattr(v, name, (object *)NULL);
|
err = setattro(v, w, (object *)NULL); /* del v.w */
|
||||||
/* del v.name */
|
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -993,6 +993,22 @@ eval_code(co, globals, locals, arg)
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case RESERVE_FAST:
|
||||||
|
if (oparg > 0) {
|
||||||
|
XDECREF(fastlocals);
|
||||||
|
x = newlistobject(oparg);
|
||||||
|
fastlocals = (listobject *) x;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LOAD_FAST:
|
||||||
|
/* NYI */
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STORE_FAST:
|
||||||
|
/* NYI */
|
||||||
|
break;
|
||||||
|
|
||||||
case BUILD_TUPLE:
|
case BUILD_TUPLE:
|
||||||
x = newtupleobject(oparg);
|
x = newtupleobject(oparg);
|
||||||
if (x != NULL) {
|
if (x != NULL) {
|
||||||
|
@ -1025,9 +1041,9 @@ eval_code(co, globals, locals, arg)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOAD_ATTR:
|
case LOAD_ATTR:
|
||||||
name = GETNAME(oparg);
|
w = GETNAMEV(oparg);
|
||||||
v = POP();
|
v = POP();
|
||||||
x = getattr(v, name);
|
x = getattro(v, w);
|
||||||
DECREF(v);
|
DECREF(v);
|
||||||
PUSH(x);
|
PUSH(x);
|
||||||
break;
|
break;
|
||||||
|
@ -1284,6 +1300,8 @@ eval_code(co, globals, locals, arg)
|
||||||
current_frame = f->f_back;
|
current_frame = f->f_back;
|
||||||
DECREF(f);
|
DECREF(f);
|
||||||
|
|
||||||
|
XDECREF(fastlocals);
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
@ -50,6 +50,7 @@ static struct memberlist code_memberlist[] = {
|
||||||
{"co_consts", T_OBJECT, OFF(co_consts), READONLY},
|
{"co_consts", T_OBJECT, OFF(co_consts), READONLY},
|
||||||
{"co_names", T_OBJECT, OFF(co_names), READONLY},
|
{"co_names", T_OBJECT, OFF(co_names), READONLY},
|
||||||
{"co_filename", T_OBJECT, OFF(co_filename), READONLY},
|
{"co_filename", T_OBJECT, OFF(co_filename), READONLY},
|
||||||
|
{"co_name", T_OBJECT, OFF(co_name), READONLY},
|
||||||
{NULL} /* Sentinel */
|
{NULL} /* Sentinel */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -69,6 +70,7 @@ code_dealloc(co)
|
||||||
XDECREF(co->co_consts);
|
XDECREF(co->co_consts);
|
||||||
XDECREF(co->co_names);
|
XDECREF(co->co_names);
|
||||||
XDECREF(co->co_filename);
|
XDECREF(co->co_filename);
|
||||||
|
XDECREF(co->co_name);
|
||||||
DEL(co);
|
DEL(co);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,12 +82,15 @@ code_repr(co)
|
||||||
int lineno = -1;
|
int lineno = -1;
|
||||||
char *p = GETSTRINGVALUE(co->co_code);
|
char *p = GETSTRINGVALUE(co->co_code);
|
||||||
char *filename = "???";
|
char *filename = "???";
|
||||||
|
char *name = "???";
|
||||||
if (*p == SET_LINENO)
|
if (*p == SET_LINENO)
|
||||||
lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8);
|
lineno = (p[1] & 0xff) | ((p[2] & 0xff) << 8);
|
||||||
if (co->co_filename && is_stringobject(co->co_filename))
|
if (co->co_filename && is_stringobject(co->co_filename))
|
||||||
filename = getstringvalue(co->co_filename);
|
filename = getstringvalue(co->co_filename);
|
||||||
sprintf(buf, "<code object at %lx, file \"%.400s\", line %d>",
|
if (co->co_name && is_stringobject(co->co_name))
|
||||||
(long)co, filename, lineno);
|
name = getstringvalue(co->co_name);
|
||||||
|
sprintf(buf, "<code object %.100s at %lx, file \"%.300s\", line %d>",
|
||||||
|
name, (long)co, filename, lineno);
|
||||||
return newstringobject(buf);
|
return newstringobject(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,18 +112,20 @@ typeobject Codetype = {
|
||||||
};
|
};
|
||||||
|
|
||||||
codeobject *
|
codeobject *
|
||||||
newcodeobject(code, consts, names, filename)
|
newcodeobject(code, consts, names, filename, name)
|
||||||
object *code;
|
object *code;
|
||||||
object *consts;
|
object *consts;
|
||||||
object *names;
|
object *names;
|
||||||
object *filename;
|
object *filename;
|
||||||
|
object *name;
|
||||||
{
|
{
|
||||||
codeobject *co;
|
codeobject *co;
|
||||||
int i;
|
int i;
|
||||||
/* Check argument types */
|
/* Check argument types */
|
||||||
if (code == NULL || !is_stringobject(code) ||
|
if (code == NULL || !is_stringobject(code) ||
|
||||||
consts == NULL || !is_listobject(consts) ||
|
consts == NULL || !is_listobject(consts) ||
|
||||||
names == NULL || !is_listobject(names)) {
|
names == NULL || !is_listobject(names) ||
|
||||||
|
name == NULL || !is_stringobject(name)) {
|
||||||
err_badcall();
|
err_badcall();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -140,6 +147,8 @@ newcodeobject(code, consts, names, filename)
|
||||||
co->co_names = names;
|
co->co_names = names;
|
||||||
INCREF(filename);
|
INCREF(filename);
|
||||||
co->co_filename = filename;
|
co->co_filename = filename;
|
||||||
|
INCREF(name);
|
||||||
|
co->co_name = name;
|
||||||
}
|
}
|
||||||
return co;
|
return co;
|
||||||
}
|
}
|
||||||
|
@ -162,6 +171,7 @@ struct compiling {
|
||||||
int c_block[MAXBLOCKS]; /* stack of block types */
|
int c_block[MAXBLOCKS]; /* stack of block types */
|
||||||
int c_nblocks; /* current block stack level */
|
int c_nblocks; /* current block stack level */
|
||||||
char *c_filename; /* filename of current node */
|
char *c_filename; /* filename of current node */
|
||||||
|
char *c_name; /* name of object (e.g. function) */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -232,6 +242,7 @@ com_init(c, filename)
|
||||||
c->c_begin = 0;
|
c->c_begin = 0;
|
||||||
c->c_nblocks = 0;
|
c->c_nblocks = 0;
|
||||||
c->c_filename = filename;
|
c->c_filename = filename;
|
||||||
|
c->c_name = "?";
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
fail_0:
|
fail_0:
|
||||||
|
@ -2020,6 +2031,8 @@ compile_funcdef(c, n)
|
||||||
{
|
{
|
||||||
node *ch;
|
node *ch;
|
||||||
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
|
REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */
|
||||||
|
c->c_name = STR(CHILD(n, 1));
|
||||||
|
com_addoparg(c, RESERVE_FAST, 0); /* Patched up later */
|
||||||
ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */
|
ch = CHILD(n, 2); /* parameters: '(' [varargslist] ')' */
|
||||||
ch = CHILD(ch, 1); /* ')' | varargslist */
|
ch = CHILD(ch, 1); /* ')' | varargslist */
|
||||||
if (TYPE(ch) == RPAR)
|
if (TYPE(ch) == RPAR)
|
||||||
|
@ -2089,6 +2102,8 @@ compile_node(c, n)
|
||||||
|
|
||||||
/* Optimization for local and global variables.
|
/* Optimization for local and global variables.
|
||||||
|
|
||||||
|
XXX Need to update this text for LOAD_FAST stuff...
|
||||||
|
|
||||||
Attempt to replace all LOAD_NAME instructions that refer to a local
|
Attempt to replace all LOAD_NAME instructions that refer to a local
|
||||||
variable with LOAD_LOCAL instructions, and all that refer to a global
|
variable with LOAD_LOCAL instructions, and all that refer to a global
|
||||||
variable with LOAD_GLOBAL instructions.
|
variable with LOAD_GLOBAL instructions.
|
||||||
|
@ -2187,17 +2202,21 @@ compile(n, filename)
|
||||||
{
|
{
|
||||||
struct compiling sc;
|
struct compiling sc;
|
||||||
codeobject *co;
|
codeobject *co;
|
||||||
object *v;
|
|
||||||
if (!com_init(&sc, filename))
|
if (!com_init(&sc, filename))
|
||||||
return NULL;
|
return NULL;
|
||||||
compile_node(&sc, n);
|
compile_node(&sc, n);
|
||||||
com_done(&sc);
|
com_done(&sc);
|
||||||
if (sc.c_errors == 0 && (v = newstringobject(filename)) != NULL) {
|
|
||||||
co = newcodeobject(sc.c_code, sc.c_consts, sc.c_names, v);
|
|
||||||
DECREF(v);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
co = NULL;
|
co = NULL;
|
||||||
|
if (sc.c_errors == 0) {
|
||||||
|
object *v, *w;
|
||||||
|
v = newstringobject(sc.c_filename);
|
||||||
|
w = newstringobject(sc.c_name);
|
||||||
|
if (v != NULL && w != NULL)
|
||||||
|
co = newcodeobject(sc.c_code, sc.c_consts,
|
||||||
|
sc.c_names, v, w);
|
||||||
|
XDECREF(v);
|
||||||
|
XDECREF(w);
|
||||||
|
}
|
||||||
com_free(&sc);
|
com_free(&sc);
|
||||||
if (co != NULL && filename[0] != '<')
|
if (co != NULL && filename[0] != '<')
|
||||||
optimizer(co);
|
optimizer(co);
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -52,9 +52,9 @@ extern int verbose; /* Defined in pythonmain.c */
|
||||||
extern char *argv0;
|
extern char *argv0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Magic word to reject pre-0.9.4 .pyc files */
|
/* Magic word to reject pre-0.9.9 .pyc files */
|
||||||
|
|
||||||
#define MAGIC 0x949494L
|
#define MAGIC 0x99BE2AL
|
||||||
|
|
||||||
static object *modules;
|
static object *modules;
|
||||||
|
|
||||||
|
|
|
@ -195,6 +195,7 @@ w_object(v, p)
|
||||||
w_object(co->co_consts, p);
|
w_object(co->co_consts, p);
|
||||||
w_object(co->co_names, p);
|
w_object(co->co_names, p);
|
||||||
w_object(co->co_filename, p);
|
w_object(co->co_filename, p);
|
||||||
|
w_object(co->co_name, p);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
w_byte(TYPE_UNKNOWN, p);
|
w_byte(TYPE_UNKNOWN, p);
|
||||||
|
@ -384,9 +385,10 @@ r_object(p)
|
||||||
object *consts = r_object(p);
|
object *consts = r_object(p);
|
||||||
object *names = r_object(p);
|
object *names = r_object(p);
|
||||||
object *filename = r_object(p);
|
object *filename = r_object(p);
|
||||||
|
object *name = r_object(p);
|
||||||
if (!err_occurred()) {
|
if (!err_occurred()) {
|
||||||
v = (object *) newcodeobject(code,
|
v = (object *) newcodeobject(code,
|
||||||
consts, names, filename);
|
consts, names, filename, name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
v = NULL;
|
v = NULL;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/***********************************************************
|
/***********************************************************
|
||||||
Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
|
Copyright 1991, 1992, 1993 by Stichting Mathematisch Centrum,
|
||||||
Netherlands.
|
Amsterdam, The Netherlands.
|
||||||
|
|
||||||
All Rights Reserved
|
All Rights Reserved
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue