2005-10-20 21:59:25 +02:00
|
|
|
#include "Python.h"
|
|
|
|
#include "asdl.h"
|
|
|
|
|
|
|
|
asdl_seq *
|
2013-10-12 22:52:43 +02:00
|
|
|
_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
|
2005-10-20 21:59:25 +02:00
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
asdl_seq *seq = NULL;
|
2014-08-17 22:20:00 +02:00
|
|
|
size_t n;
|
2008-06-18 02:47:36 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
/* check size is sane */
|
2014-08-17 22:20:00 +02:00
|
|
|
if (size < 0 ||
|
2016-09-07 18:26:18 +02:00
|
|
|
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
|
2010-05-09 17:52:27 +02:00
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-17 22:20:00 +02:00
|
|
|
n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-18 02:47:36 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
/* check if size can be added safely */
|
2016-09-07 18:26:18 +02:00
|
|
|
if (n > SIZE_MAX - sizeof(asdl_seq)) {
|
2010-05-09 17:52:27 +02:00
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
n += sizeof(asdl_seq);
|
2005-10-20 21:59:25 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
seq = (asdl_seq *)PyArena_Malloc(arena, n);
|
|
|
|
if (!seq) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(seq, 0, n);
|
|
|
|
seq->size = size;
|
|
|
|
return seq;
|
2006-04-21 12:40:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
asdl_int_seq *
|
2013-10-12 22:52:43 +02:00
|
|
|
_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
|
2006-04-21 12:40:58 +02:00
|
|
|
{
|
2010-05-09 17:52:27 +02:00
|
|
|
asdl_int_seq *seq = NULL;
|
2014-08-17 22:20:00 +02:00
|
|
|
size_t n;
|
2008-06-18 02:47:36 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
/* check size is sane */
|
2014-08-17 22:20:00 +02:00
|
|
|
if (size < 0 ||
|
2016-09-07 18:26:18 +02:00
|
|
|
(size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
|
2010-05-09 17:52:27 +02:00
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-17 22:20:00 +02:00
|
|
|
n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-18 02:47:36 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
/* check if size can be added safely */
|
2016-09-07 18:26:18 +02:00
|
|
|
if (n > SIZE_MAX - sizeof(asdl_seq)) {
|
2010-05-09 17:52:27 +02:00
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
n += sizeof(asdl_seq);
|
2006-04-21 12:40:58 +02:00
|
|
|
|
2010-05-09 17:52:27 +02:00
|
|
|
seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
|
|
|
|
if (!seq) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memset(seq, 0, n);
|
|
|
|
seq->size = size;
|
|
|
|
return seq;
|
2005-10-20 21:59:25 +02:00
|
|
|
}
|