From fc20724c1252318e7e31f864c128930275037ac5 Mon Sep 17 00:00:00 2001 From: suncb Date: Tue, 21 Jul 2020 11:27:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=87=8F=E5=B0=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inc/cson.h | 26 +++----------------------- src/cson.c | 3 +++ 2 files changed, 6 insertions(+), 23 deletions(-) diff --git a/inc/cson.h b/inc/cson.h index 3bcd97f..4e097c4 100644 --- a/inc/cson.h +++ b/inc/cson.h @@ -192,7 +192,7 @@ typedef void* (*loop_func_t)(void* pData, const reflect_item_t* tbl); * * @return void. */ -void csonLoopProperty(void* obj, const reflect_item_t* tbl, loop_func_t func); +void csonLoopProperty(void* obj, const reflect_item_t* tbl, loop_func_t func); /** * @brief convert json string to struct object. @@ -237,31 +237,10 @@ void csonPrintProperty(void* pData, const reflect_item_t* tbl); void csonFreePointer(void* list, const reflect_item_t* tbl); /* - for Multidimensional array support + for Multidimensional array support */ typedef size_t cson_array_size_t; -/** - * @brief get array memory. - * - * @param count: count of array item - * @param sizePerItem: bytes per array time - * - * @return void*. - * @attention Array header information is implied, so don't use malloc directly. - */ -void* csonArrayAlloc(cson_array_size_t count, cson_array_size_t sizePerItem); - -/** - * @brief free array memory. - * - * @param ptr: array memory to be free. - * - * @return void. - * @attention Array header information is implied, so don't use free directly. - */ -void csonArrayFree(void* ptr); - /** * @brief fast alloc multi-dimen array * @@ -277,6 +256,7 @@ void* csonAllocMultiDimenArray(int dimen, cson_array_size_t* sizePerDimen, size_ * @brief the description of multidimensional array. */ void csonFreeMultiDimenArray(void* p); + typedef struct { cson_array_size_t size; cson_array_size_t cap; diff --git a/src/cson.c b/src/cson.c index 8afa28b..28d3da0 100644 --- a/src/cson.c +++ b/src/cson.c @@ -175,6 +175,9 @@ static void* parseJsonMDArrayTail(cson_t jo_tmp, const reflect_item_t* tbl, int static void csonLoopPropertyMDArraySub(void* pProperty, const reflect_item_t* tbl, int i, int dimen, loop_func_t func); static int invalidCountField(const reflect_item_t* tbl); +static void csonArrayFree(void* ptr); +static void* csonArrayAlloc(cson_array_size_t count, cson_array_size_t sizePerItem); + int csonStruct2JsonStr(char** jstr, void* input, const reflect_item_t* tbl) { cson_t jsonPack = cson_object();