Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
7b5a604d
Commit
7b5a604d
authored
Nov 13, 2005
by
Neal Norwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Whoops, checkin consistent versions of *all* files to stop polluting
a bunch of names
parent
497b19a8
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
158 additions
and
79 deletions
+158
-79
Include/Python-ast.h
Include/Python-ast.h
+4
-0
Include/asdl.h
Include/asdl.h
+0
-7
Parser/asdl_c.py
Parser/asdl_c.py
+80
-6
Python/Python-ast.c
Python/Python-ast.c
+74
-0
Python/asdl.c
Python/asdl.c
+0
-66
No files found.
Include/Python-ast.h
View file @
7b5a604d
...
...
@@ -34,6 +34,7 @@ typedef struct _keyword *keyword_ty;
typedef
struct
_alias
*
alias_ty
;
struct
_mod
{
enum
{
Module_kind
=
1
,
Interactive_kind
=
2
,
Expression_kind
=
3
,
Suite_kind
=
4
}
kind
;
...
...
@@ -326,6 +327,7 @@ struct _alias {
identifier
asname
;
};
mod_ty
Module
(
asdl_seq
*
body
);
mod_ty
Interactive
(
asdl_seq
*
body
);
mod_ty
Expression
(
expr_ty
body
);
...
...
@@ -388,6 +390,7 @@ arguments_ty arguments(asdl_seq * args, identifier vararg, identifier kwarg,
asdl_seq
*
defaults
);
keyword_ty
keyword
(
identifier
arg
,
expr_ty
value
);
alias_ty
alias
(
identifier
name
,
identifier
asname
);
void
free_mod
(
mod_ty
);
void
free_stmt
(
stmt_ty
);
void
free_expr
(
expr_ty
);
...
...
@@ -402,3 +405,4 @@ void free_excepthandler(excepthandler_ty);
void
free_arguments
(
arguments_ty
);
void
free_keyword
(
keyword_ty
);
void
free_alias
(
alias_ty
);
Include/asdl.h
View file @
7b5a604d
...
...
@@ -44,11 +44,4 @@ void asdl_seq_free(asdl_seq *);
#endif
#define asdl_seq_LEN(S) ((S) == NULL ? 0 : (S)->size)
/* Routines to marshal the basic types. */
int
marshal_write_int
(
PyObject
**
,
int
*
,
int
);
int
marshal_write_bool
(
PyObject
**
,
int
*
,
bool
);
int
marshal_write_identifier
(
PyObject
**
,
int
*
,
identifier
);
int
marshal_write_string
(
PyObject
**
,
int
*
,
string
);
int
marshal_write_object
(
PyObject
**
,
int
*
,
object
);
#endif
/* !Py_ASDL_H */
Parser/asdl_c.py
View file @
7b5a604d
...
...
@@ -367,7 +367,12 @@ def has_sequence(types, doing_specialization):
class
StaticVisitor
(
PickleVisitor
):
'''Very simple, always emit this static code'''
CODE
=
'''Very simple, always emit this static code. Overide CODE'''
def
visit
(
self
,
object
):
self
.
emit
(
self
.
CODE
,
0
,
reflow
=
False
)
class
FreeUtilVisitor
(
StaticVisitor
):
CODE
=
'''static void
free_seq_exprs(asdl_seq *seq)
...
...
@@ -390,10 +395,6 @@ free_seq_stmts(asdl_seq *seq)
}
'''
def
visit
(
self
,
object
):
self
.
emit
(
self
.
CODE
,
0
,
reflow
=
False
)
class
FreeVisitor
(
PickleVisitor
):
def
func_begin
(
self
,
name
,
has_seq
):
...
...
@@ -483,6 +484,77 @@ class FreeVisitor(PickleVisitor):
self
.
emit
(
"free_%s((%s)%s);"
%
(
field
.
type
,
ctype
,
value
),
depth
)
class
MarshalUtilVisitor
(
StaticVisitor
):
CODE
=
'''
#define CHECKSIZE(BUF, OFF, MIN) {
\
\
int need = *(OFF) + MIN;
\
\
if (need >= PyString_GET_SIZE(*(BUF))) {
\
\
int newsize = PyString_GET_SIZE(*(BUF)) * 2;
\
\
if (newsize < need)
\
\
newsize = need;
\
\
if (_PyString_Resize((BUF), newsize) < 0)
\
\
return 0;
\
\
}
\
\
}
static int
marshal_write_int(PyObject **buf, int *offset, int x)
{
char *s;
CHECKSIZE(buf, offset, 4)
s = PyString_AS_STRING(*buf) + (*offset);
s[0] = (x & 0xff);
s[1] = (x >> 8) & 0xff;
s[2] = (x >> 16) & 0xff;
s[3] = (x >> 24) & 0xff;
*offset += 4;
return 1;
}
static int
marshal_write_bool(PyObject **buf, int *offset, bool b)
{
if (b)
marshal_write_int(buf, offset, 1);
else
marshal_write_int(buf, offset, 0);
return 1;
}
static int
marshal_write_identifier(PyObject **buf, int *offset, identifier id)
{
int l = PyString_GET_SIZE(id);
marshal_write_int(buf, offset, l);
CHECKSIZE(buf, offset, l);
memcpy(PyString_AS_STRING(*buf) + *offset,
PyString_AS_STRING(id), l);
*offset += l;
return 1;
}
static int
marshal_write_string(PyObject **buf, int *offset, string s)
{
int len = PyString_GET_SIZE(s);
marshal_write_int(buf, offset, len);
CHECKSIZE(buf, offset, len);
memcpy(PyString_AS_STRING(*buf) + *offset,
PyString_AS_STRING(s), len);
*offset += len;
return 1;
}
static int
marshal_write_object(PyObject **buf, int *offset, object s)
{
/* XXX */
return 0;
}
'''
class
MarshalFunctionVisitor
(
PickleVisitor
):
def
func_begin
(
self
,
name
,
has_seq
):
...
...
@@ -563,6 +635,7 @@ class ChainOfVisitors:
def
visit
(
self
,
object
):
for
v
in
self
.
visitors
:
v
.
visit
(
object
)
v
.
emit
(
""
,
0
)
def
main
(
srcfile
):
auto_gen_msg
=
'/* File automatically generated by %s */
\
n
'
%
sys
.
argv
[
0
]
...
...
@@ -595,8 +668,9 @@ def main(srcfile):
print
>>
f
v
=
ChainOfVisitors
(
MarshalPrototypeVisitor
(
f
),
FunctionVisitor
(
f
),
Static
Visitor
(
f
),
FreeUtil
Visitor
(
f
),
FreeVisitor
(
f
),
MarshalUtilVisitor
(
f
),
MarshalFunctionVisitor
(
f
),
)
v
.
visit
(
mod
)
...
...
Python/Python-ast.c
View file @
7b5a604d
...
...
@@ -17,6 +17,7 @@ static int marshal_write_excepthandler(PyObject **, int *, excepthandler_ty);
static
int
marshal_write_arguments
(
PyObject
**
,
int
*
,
arguments_ty
);
static
int
marshal_write_keyword
(
PyObject
**
,
int
*
,
keyword_ty
);
static
int
marshal_write_alias
(
PyObject
**
,
int
*
,
alias_ty
);
mod_ty
Module
(
asdl_seq
*
body
)
{
...
...
@@ -1087,6 +1088,7 @@ alias(identifier name, identifier asname)
return
p
;
}
static
void
free_seq_exprs
(
asdl_seq
*
seq
)
{
...
...
@@ -1107,6 +1109,7 @@ free_seq_stmts(asdl_seq *seq)
asdl_seq_free
(
seq
);
}
void
free_mod
(
mod_ty
o
)
{
...
...
@@ -1533,6 +1536,76 @@ free_alias(alias_ty o)
free
(
o
);
}
#define CHECKSIZE(BUF, OFF, MIN) { \
int need = *(OFF) + MIN; \
if (need >= PyString_GET_SIZE(*(BUF))) { \
int newsize = PyString_GET_SIZE(*(BUF)) * 2; \
if (newsize < need) \
newsize = need; \
if (_PyString_Resize((BUF), newsize) < 0) \
return 0; \
} \
}
static
int
marshal_write_int
(
PyObject
**
buf
,
int
*
offset
,
int
x
)
{
char
*
s
;
CHECKSIZE
(
buf
,
offset
,
4
)
s
=
PyString_AS_STRING
(
*
buf
)
+
(
*
offset
);
s
[
0
]
=
(
x
&
0xff
);
s
[
1
]
=
(
x
>>
8
)
&
0xff
;
s
[
2
]
=
(
x
>>
16
)
&
0xff
;
s
[
3
]
=
(
x
>>
24
)
&
0xff
;
*
offset
+=
4
;
return
1
;
}
static
int
marshal_write_bool
(
PyObject
**
buf
,
int
*
offset
,
bool
b
)
{
if
(
b
)
marshal_write_int
(
buf
,
offset
,
1
);
else
marshal_write_int
(
buf
,
offset
,
0
);
return
1
;
}
static
int
marshal_write_identifier
(
PyObject
**
buf
,
int
*
offset
,
identifier
id
)
{
int
l
=
PyString_GET_SIZE
(
id
);
marshal_write_int
(
buf
,
offset
,
l
);
CHECKSIZE
(
buf
,
offset
,
l
);
memcpy
(
PyString_AS_STRING
(
*
buf
)
+
*
offset
,
PyString_AS_STRING
(
id
),
l
);
*
offset
+=
l
;
return
1
;
}
static
int
marshal_write_string
(
PyObject
**
buf
,
int
*
offset
,
string
s
)
{
int
len
=
PyString_GET_SIZE
(
s
);
marshal_write_int
(
buf
,
offset
,
len
);
CHECKSIZE
(
buf
,
offset
,
len
);
memcpy
(
PyString_AS_STRING
(
*
buf
)
+
*
offset
,
PyString_AS_STRING
(
s
),
len
);
*
offset
+=
len
;
return
1
;
}
static
int
marshal_write_object
(
PyObject
**
buf
,
int
*
offset
,
object
s
)
{
/* XXX */
return
0
;
}
static
int
marshal_write_mod
(
PyObject
**
buf
,
int
*
off
,
mod_ty
o
)
{
...
...
@@ -2286,3 +2359,4 @@ marshal_write_alias(PyObject **buf, int *off, alias_ty o)
return
1
;
}
Python/asdl.c
View file @
7b5a604d
...
...
@@ -24,69 +24,3 @@ asdl_seq_free(asdl_seq *seq)
PyObject_Free
(
seq
);
}
#define CHECKSIZE(BUF, OFF, MIN) { \
int need = *(OFF) + MIN; \
if (need >= PyString_GET_SIZE(*(BUF))) { \
int newsize = PyString_GET_SIZE(*(BUF)) * 2; \
if (newsize < need) \
newsize = need; \
if (_PyString_Resize((BUF), newsize) < 0) \
return 0; \
} \
}
int
marshal_write_int
(
PyObject
**
buf
,
int
*
offset
,
int
x
)
{
char
*
s
;
CHECKSIZE
(
buf
,
offset
,
4
)
s
=
PyString_AS_STRING
(
*
buf
)
+
(
*
offset
);
s
[
0
]
=
(
x
&
0xff
);
s
[
1
]
=
(
x
>>
8
)
&
0xff
;
s
[
2
]
=
(
x
>>
16
)
&
0xff
;
s
[
3
]
=
(
x
>>
24
)
&
0xff
;
*
offset
+=
4
;
return
1
;
}
int
marshal_write_bool
(
PyObject
**
buf
,
int
*
offset
,
bool
b
)
{
if
(
b
)
marshal_write_int
(
buf
,
offset
,
1
);
else
marshal_write_int
(
buf
,
offset
,
0
);
return
1
;
}
int
marshal_write_identifier
(
PyObject
**
buf
,
int
*
offset
,
identifier
id
)
{
int
l
=
PyString_GET_SIZE
(
id
);
marshal_write_int
(
buf
,
offset
,
l
);
CHECKSIZE
(
buf
,
offset
,
l
);
memcpy
(
PyString_AS_STRING
(
*
buf
)
+
*
offset
,
PyString_AS_STRING
(
id
),
l
);
*
offset
+=
l
;
return
1
;
}
int
marshal_write_string
(
PyObject
**
buf
,
int
*
offset
,
string
s
)
{
int
len
=
PyString_GET_SIZE
(
s
);
marshal_write_int
(
buf
,
offset
,
len
);
CHECKSIZE
(
buf
,
offset
,
len
);
memcpy
(
PyString_AS_STRING
(
*
buf
)
+
*
offset
,
PyString_AS_STRING
(
s
),
len
);
*
offset
+=
len
;
return
1
;
}
int
marshal_write_object
(
PyObject
**
buf
,
int
*
offset
,
object
s
)
{
/* XXX */
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment