2005-10-20 16:59:25 -03:00
|
|
|
#include "Python.h"
|
|
|
|
#include "asdl.h"
|
|
|
|
|
|
|
|
asdl_seq *
|
2005-12-17 16:54:49 -04:00
|
|
|
asdl_seq_new(int size, PyArena *arena)
|
2005-10-20 16:59:25 -03:00
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
asdl_seq *seq = NULL;
|
|
|
|
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -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-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
/* check if size can be added safely */
|
|
|
|
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
n += sizeof(asdl_seq);
|
2005-10-20 16:59:25 -03:00
|
|
|
|
2010-05-09 11:46:46 -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-13 09:29:43 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
asdl_int_seq *
|
|
|
|
asdl_int_seq_new(int size, PyArena *arena)
|
|
|
|
{
|
2010-05-09 11:46:46 -03:00
|
|
|
asdl_int_seq *seq = NULL;
|
|
|
|
size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);
|
2008-06-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -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-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
/* check if size can be added safely */
|
|
|
|
if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
|
|
|
|
PyErr_NoMemory();
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-06-11 04:41:16 -03:00
|
|
|
|
2010-05-09 11:46:46 -03:00
|
|
|
n += sizeof(asdl_seq);
|
2006-04-13 09:29:43 -03:00
|
|
|
|
2010-05-09 11:46:46 -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
|
|
|
}
|