From 9662ab30ecea1c543639aed72af8ee10540aa695 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Fri, 15 Nov 2013 19:30:25 +0900 Subject: [PATCH] add pic_vec_extend_ip (for internal API) --- include/picrin.h | 1 + src/vector.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/picrin.h b/include/picrin.h index 17c7a7d4..189a295b 100644 --- a/include/picrin.h +++ b/include/picrin.h @@ -103,6 +103,7 @@ pic_value pic_str_new_cstr(pic_state *, const char *); struct pic_vector *pic_vec_new(pic_state *, size_t); struct pic_vector *pic_vec_new_from_list(pic_state *, pic_value); +void pic_vec_extend_ip(pic_state *, struct pic_vector *, int); int pic_parse_file(pic_state *, FILE *file, pic_value *); int pic_parse_cstr(pic_state *, const char *, pic_value *); diff --git a/src/vector.c b/src/vector.c index 9e695647..e4137680 100644 --- a/src/vector.c +++ b/src/vector.c @@ -32,6 +32,19 @@ pic_vec_new_from_list(pic_state *pic, pic_value data) return vec; } +void +pic_vec_extend_ip(pic_state *pic, struct pic_vector *vec, int size) +{ + int len, i; + + len = vec->len; + vec->len = size; + vec->data = (pic_value *)pic_realloc(pic, vec->data, sizeof(pic_value) * size); + for (i = len; i < size; ++i) { + vec->data[i] = pic_false_value(); + } +} + static pic_value pic_vec_vector_p(pic_state *pic) {