ยปCore Development>Code coverage>Python/asdl.c

Python code coverage for Python/asdl.c

#countcontent
1n/a#include "Python.h"
2n/a#include "asdl.h"
3n/a
4n/aasdl_seq *
5n/a_Py_asdl_seq_new(Py_ssize_t size, PyArena *arena)
6n/a{
7n/a asdl_seq *seq = NULL;
8n/a size_t n;
9n/a
10n/a /* check size is sane */
11n/a if (size < 0 ||
12n/a (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
13n/a PyErr_NoMemory();
14n/a return NULL;
15n/a }
16n/a n = (size ? (sizeof(void *) * (size - 1)) : 0);
17n/a
18n/a /* check if size can be added safely */
19n/a if (n > SIZE_MAX - sizeof(asdl_seq)) {
20n/a PyErr_NoMemory();
21n/a return NULL;
22n/a }
23n/a n += sizeof(asdl_seq);
24n/a
25n/a seq = (asdl_seq *)PyArena_Malloc(arena, n);
26n/a if (!seq) {
27n/a PyErr_NoMemory();
28n/a return NULL;
29n/a }
30n/a memset(seq, 0, n);
31n/a seq->size = size;
32n/a return seq;
33n/a}
34n/a
35n/aasdl_int_seq *
36n/a_Py_asdl_int_seq_new(Py_ssize_t size, PyArena *arena)
37n/a{
38n/a asdl_int_seq *seq = NULL;
39n/a size_t n;
40n/a
41n/a /* check size is sane */
42n/a if (size < 0 ||
43n/a (size && (((size_t)size - 1) > (SIZE_MAX / sizeof(void *))))) {
44n/a PyErr_NoMemory();
45n/a return NULL;
46n/a }
47n/a n = (size ? (sizeof(void *) * (size - 1)) : 0);
48n/a
49n/a /* check if size can be added safely */
50n/a if (n > SIZE_MAX - sizeof(asdl_seq)) {
51n/a PyErr_NoMemory();
52n/a return NULL;
53n/a }
54n/a n += sizeof(asdl_seq);
55n/a
56n/a seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
57n/a if (!seq) {
58n/a PyErr_NoMemory();
59n/a return NULL;
60n/a }
61n/a memset(seq, 0, n);
62n/a seq->size = size;
63n/a return seq;
64n/a}