]> git.proxmox.com Git - mirror_edk2.git/blame - AppPkg/Applications/Python/Python-2.7.10/Python/asdl.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / AppPkg / Applications / Python / Python-2.7.10 / Python / asdl.c
CommitLineData
c8042e10
DM
1#include "Python.h"\r
2#include "asdl.h"\r
3\r
4asdl_seq *\r
5asdl_seq_new(int size, PyArena *arena)\r
6{\r
7 asdl_seq *seq = NULL;\r
8 size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);\r
9\r
10 /* check size is sane */\r
11 if (size < 0 || size == INT_MIN ||\r
12 (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {\r
13 PyErr_NoMemory();\r
14 return NULL;\r
15 }\r
16\r
17 /* check if size can be added safely */\r
18 if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {\r
19 PyErr_NoMemory();\r
20 return NULL;\r
21 }\r
22\r
23 n += sizeof(asdl_seq);\r
24\r
25 seq = (asdl_seq *)PyArena_Malloc(arena, n);\r
26 if (!seq) {\r
27 PyErr_NoMemory();\r
28 return NULL;\r
29 }\r
30 memset(seq, 0, n);\r
31 seq->size = size;\r
32 return seq;\r
33}\r
34\r
35asdl_int_seq *\r
36asdl_int_seq_new(int size, PyArena *arena)\r
37{\r
38 asdl_int_seq *seq = NULL;\r
39 size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);\r
40\r
41 /* check size is sane */\r
42 if (size < 0 || size == INT_MIN ||\r
43 (size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {\r
44 PyErr_NoMemory();\r
45 return NULL;\r
46 }\r
47\r
48 /* check if size can be added safely */\r
49 if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {\r
50 PyErr_NoMemory();\r
51 return NULL;\r
52 }\r
53\r
54 n += sizeof(asdl_seq);\r
55\r
56 seq = (asdl_int_seq *)PyArena_Malloc(arena, n);\r
57 if (!seq) {\r
58 PyErr_NoMemory();\r
59 return NULL;\r
60 }\r
61 memset(seq, 0, n);\r
62 seq->size = size;\r
63 return seq;\r
64}\r