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