Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 1 | #include "Python.h" |
| 2 | #include "asdl.h" |
| 3 | |
| 4 | asdl_seq * |
Neal Norwitz | adb69fc | 2005-12-17 20:54:49 +0000 | [diff] [blame] | 5 | asdl_seq_new(int size, PyArena *arena) |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 6 | { |
| 7 | asdl_seq *seq = NULL; |
| 8 | size_t n = sizeof(asdl_seq) + |
| 9 | (size ? (sizeof(void *) * (size - 1)) : 0); |
| 10 | |
Thomas Wouters | 49fd7fa | 2006-04-21 10:40:58 +0000 | [diff] [blame] | 11 | seq = (asdl_seq *)PyArena_Malloc(arena, n); |
| 12 | if (!seq) { |
| 13 | PyErr_NoMemory(); |
| 14 | return NULL; |
| 15 | } |
| 16 | memset(seq, 0, n); |
| 17 | seq->size = size; |
| 18 | return seq; |
| 19 | } |
| 20 | |
| 21 | asdl_int_seq * |
| 22 | asdl_int_seq_new(int size, PyArena *arena) |
| 23 | { |
| 24 | asdl_int_seq *seq = NULL; |
| 25 | size_t n = sizeof(asdl_seq) + |
| 26 | (size ? (sizeof(int) * (size - 1)) : 0); |
| 27 | |
| 28 | seq = (asdl_int_seq *)PyArena_Malloc(arena, n); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 29 | if (!seq) { |
Neal Norwitz | daae616 | 2005-11-14 00:47:57 +0000 | [diff] [blame] | 30 | PyErr_NoMemory(); |
Jeremy Hylton | 3e0055f | 2005-10-20 19:59:25 +0000 | [diff] [blame] | 31 | return NULL; |
| 32 | } |
| 33 | memset(seq, 0, n); |
| 34 | seq->size = size; |
| 35 | return seq; |
| 36 | } |