2005-10-20 16:59:25 -03:00
|
|
|
#include "Python.h"
|
|
|
|
#include "asdl.h"
|
|
|
|
|
|
|
|
asdl_seq *
|
2013-10-12 17:52:43 -03:00
|
|
|
_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
|
2005-10-20 16:59:25 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
asdl_seq *seq = NULL;
|
|
|
|
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
/* check size is sane */
|
|
|
|
if (size < 0 || size == INT_MIN ||
|
|
|
|
(size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
/* check if size can be added safely */
|
|
|
|
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
n += sizeof(asdl_seq);
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2010-05-09 12:52:27 -03: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 07:40:58 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
asdl_int_seq *
|
2013-10-12 17:52:43 -03:00
|
|
|
_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
|
2006-04-21 07:40:58 -03:00
|
|
|
{
|
2010-05-09 12:52:27 -03:00
|
|
|
asdl_int_seq *seq = NULL;
|
|
|
|
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
/* check size is sane */
|
|
|
|
if (size < 0 || size == INT_MIN ||
|
|
|
|
(size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
/* check if size can be added safely */
|
|
|
|
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-17 21:47:36 -03:00
|
|
|
|
2010-05-09 12:52:27 -03:00
|
|
|
n += sizeof(asdl_seq);
|
2006-04-21 07:40:58 -03:00
|
|
|
|
2010-05-09 12:52:27 -03: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 16:59:25 -03:00
|
|
|
}
|