Mercurial > cpython-lru_cache-weakref
annotate Python/asdl.c @ 58973:db86bf39ccaa legacy-trunk
Issue 7970: When email.Parser.Parser parses a MIME message of type
message/rfc822 it turns it into an object whose body consists of
a list containing a single Message object. HeaderParser, on the
other hand, just copies the body as a string. Generator.flatten
has a special handler for the message mime type that expected the
body to be the one item list. This fails if the message was parsed
by HeaderParser. So we now check to see if the body is a string
first, and if so just we just emit it.
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Sun, 21 Feb 2010 04:23:00 +0000 |
| parents | 1c964ed35ef9 |
| children | fd25030223b0 |
| rev | line source |
|---|---|
| 35742 | 1 #include "Python.h" |
| 2 #include "asdl.h" | |
| 3 | |
| 4 asdl_seq * | |
|
36065
ea083efdc96c
Merge from ast-arena. This reduces the code in Python/ast.c by ~300 lines,
Neal Norwitz <nnorwitz@gmail.com>
parents:
35869
diff
changeset
|
5 asdl_seq_new(int size, PyArena *arena) |
| 35742 | 6 { |
| 7 asdl_seq *seq = NULL; | |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
8 size_t n = (size ? (sizeof(void *) * (size - 1)) : 0); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
9 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
10 /* check size is sane */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
11 if (size < 0 || size == INT_MIN || |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
12 (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
13 PyErr_NoMemory(); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
14 return NULL; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
15 } |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
16 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
17 /* check if size can be added safely */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
18 if (n > PY_SIZE_MAX - sizeof(asdl_seq)) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
19 PyErr_NoMemory(); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
20 return NULL; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
21 } |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
22 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
23 n += sizeof(asdl_seq); |
| 35742 | 24 |
|
37685
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
25 seq = (asdl_seq *)PyArena_Malloc(arena, n); |
| 35742 | 26 if (!seq) { |
|
35869
9003836a036f
Use convenience function
Neal Norwitz <nnorwitz@gmail.com>
parents:
35866
diff
changeset
|
27 PyErr_NoMemory(); |
| 35742 | 28 return NULL; |
| 29 } | |
| 30 memset(seq, 0, n); | |
| 31 seq->size = size; | |
| 32 return seq; | |
| 33 } | |
|
37685
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
34 |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
35 asdl_int_seq * |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
36 asdl_int_seq_new(int size, PyArena *arena) |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
37 { |
| 37689 | 38 asdl_int_seq *seq = NULL; |
|
47587
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
39 size_t n = (size ? (sizeof(void *) * (size - 1)) : 0); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
40 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
41 /* check size is sane */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
42 if (size < 0 || size == INT_MIN || |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
43 (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
44 PyErr_NoMemory(); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
45 return NULL; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
46 } |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
47 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
48 /* check if size can be added safely */ |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
49 if (n > PY_SIZE_MAX - sizeof(asdl_seq)) { |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
50 PyErr_NoMemory(); |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
51 return NULL; |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
52 } |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
53 |
|
1c964ed35ef9
Merge in release25-maint r60793:
Gregory P. Smith <greg@mad-scientist.com>
parents:
37689
diff
changeset
|
54 n += sizeof(asdl_seq); |
|
37685
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
55 |
| 37689 | 56 seq = (asdl_int_seq *)PyArena_Malloc(arena, n); |
|
37685
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
57 if (!seq) { |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
58 PyErr_NoMemory(); |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
59 return NULL; |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
60 } |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
61 memset(seq, 0, n); |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
62 seq->size = size; |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
63 return seq; |
|
5e72b0c74100
Introduce asdl_int_seq, to hold cmpop_ty.
Martin v. Löwis <martin@v.loewis.de>
parents:
36718
diff
changeset
|
64 } |
