1 | n/a | #include "Python.h" |
---|
2 | n/a | #include "asdl.h" |
---|
3 | n/a | |
---|
4 | n/a | asdl_seq * |
---|
5 | n/a | _Py_asdl_seq_new(Py_ssize_t size, PyArena *arena) |
---|
6 | n/a | { |
---|
7 | n/a | asdl_seq *seq = NULL; |
---|
8 | n/a | size_t n; |
---|
9 | n/a | |
---|
10 | n/a | /* check size is sane */ |
---|
11 | n/a | if (size < 0 || |
---|
12 | n/a | (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) { |
---|
13 | n/a | PyErr_NoMemory(); |
---|
14 | n/a | return NULL; |
---|
15 | n/a | } |
---|
16 | n/a | n = (size ? (sizeof(void *) * (size - 1)) : 0); |
---|
17 | n/a | |
---|
18 | n/a | /* check if size can be added safely */ |
---|
19 | n/a | if (n > SIZE_MAX - sizeof(asdl_seq)) { |
---|
20 | n/a | PyErr_NoMemory(); |
---|
21 | n/a | return NULL; |
---|
22 | n/a | } |
---|
23 | n/a | n += sizeof(asdl_seq); |
---|
24 | n/a | |
---|
25 | n/a | seq = (asdl_seq *)PyArena_Malloc(arena, n); |
---|
26 | n/a | if (!seq) { |
---|
27 | n/a | PyErr_NoMemory(); |
---|
28 | n/a | return NULL; |
---|
29 | n/a | } |
---|
30 | n/a | memset(seq, 0, n); |
---|
31 | n/a | seq->size = size; |
---|
32 | n/a | return seq; |
---|
33 | n/a | } |
---|
34 | n/a | |
---|
35 | n/a | asdl_int_seq * |
---|
36 | n/a | _Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena) |
---|
37 | n/a | { |
---|
38 | n/a | asdl_int_seq *seq = NULL; |
---|
39 | n/a | size_t n; |
---|
40 | n/a | |
---|
41 | n/a | /* check size is sane */ |
---|
42 | n/a | if (size < 0 || |
---|
43 | n/a | (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) { |
---|
44 | n/a | PyErr_NoMemory(); |
---|
45 | n/a | return NULL; |
---|
46 | n/a | } |
---|
47 | n/a | n = (size ? (sizeof(void *) * (size - 1)) : 0); |
---|
48 | n/a | |
---|
49 | n/a | /* check if size can be added safely */ |
---|
50 | n/a | if (n > SIZE_MAX - sizeof(asdl_seq)) { |
---|
51 | n/a | PyErr_NoMemory(); |
---|
52 | n/a | return NULL; |
---|
53 | n/a | } |
---|
54 | n/a | n += sizeof(asdl_seq); |
---|
55 | n/a | |
---|
56 | n/a | seq = (asdl_int_seq *)PyArena_Malloc(arena, n); |
---|
57 | n/a | if (!seq) { |
---|
58 | n/a | PyErr_NoMemory(); |
---|
59 | n/a | return NULL; |
---|
60 | n/a | } |
---|
61 | n/a | memset(seq, 0, n); |
---|
62 | n/a | seq->size = size; |
---|
63 | n/a | return seq; |
---|
64 | n/a | } |
---|