aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/asdl.c
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /contrib/tools/python3/src/Python/asdl.c
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'contrib/tools/python3/src/Python/asdl.c')
-rw-r--r--contrib/tools/python3/src/Python/asdl.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/contrib/tools/python3/src/Python/asdl.c b/contrib/tools/python3/src/Python/asdl.c
new file mode 100644
index 0000000000..c211078118
--- /dev/null
+++ b/contrib/tools/python3/src/Python/asdl.c
@@ -0,0 +1,64 @@
+#include "Python.h"
+#include "asdl.h"
+
+asdl_seq *
+_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
+{
+ asdl_seq *seq = NULL;
+ size_t n;
+
+ /* check size is sane */
+ if (size < 0 ||
+ (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ n = (size ? (sizeof(void *) * (size - 1)) : 0);
+
+ /* check if size can be added safely */
+ if (n > SIZE_MAX - sizeof(asdl_seq)) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ n += sizeof(asdl_seq);
+
+ seq = (asdl_seq *)PyArena_Malloc(arena, n);
+ if (!seq) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memset(seq, 0, n);
+ seq->size = size;
+ return seq;
+}
+
+asdl_int_seq *
+_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
+{
+ asdl_int_seq *seq = NULL;
+ size_t n;
+
+ /* check size is sane */
+ if (size < 0 ||
+ (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ n = (size ? (sizeof(void *) * (size - 1)) : 0);
+
+ /* check if size can be added safely */
+ if (n > SIZE_MAX - sizeof(asdl_seq)) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ n += sizeof(asdl_seq);
+
+ seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
+ if (!seq) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+ memset(seq, 0, n);
+ seq->size = size;
+ return seq;
+}