From 76e0ad8308f233b00aa7c570d17cefe38cc84e3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= <huangxin@cmhi.chinamobile.com> Date: Thu, 4 Jul 2019 11:29:48 +0800 Subject: [PATCH] =?UTF-8?q?Mod=20=20aaa-12=20=E4=BF=AE=E6=94=B9struct2json?= =?UTF-8?q?=E5=BA=93malloc=20hook=20RCA=EF=BC=9A=20SOL=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4hook=E6=96=B9=E6=B3=95=EF=BC=8C=E4=BD=BF=E7=94=A8mallo?= =?UTF-8?q?c=E3=80=81free=E5=87=BD=E6=95=B0=20=E4=BF=AE=E6=94=B9=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Ahuangxin=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9Ahuangxi?= =?UTF-8?q?n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/s2j/s2j.h | 26 ------------------- Common/s2j/s2jdef.h | 5 ++-- libs/src/struct2json/struct2json/inc/s2j.h | 6 +---- libs/src/struct2json/struct2json/inc/s2jdef.h | 7 ++--- 4 files changed, 8 insertions(+), 36 deletions(-) diff --git a/Common/s2j/s2j.h b/Common/s2j/s2j.h index 115b826ee..ff67266a6 100644 --- a/Common/s2j/s2j.h +++ b/Common/s2j/s2j.h @@ -80,32 +80,6 @@ extern "C" { #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \ S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element) -/* s2j.c */ -//extern S2jHook s2jHook; -S2jHook s2jHook = { - .malloc_fn = malloc, - .free_fn = free, -}; - -static void s2j_init(S2jHook *hook) -{ - /* initialize cJSON library */ - if(hook == NULL) - { - hook = &s2jHook; - } - - cJSON_InitHooks((cJSON_Hooks *)hook); - /* initialize hooks */ - if (hook) { - s2jHook.malloc_fn = (hook->malloc_fn) ? hook->malloc_fn : malloc; - s2jHook.free_fn = (hook->free_fn) ? hook->free_fn : free; - } else { - s2jHook.malloc_fn = malloc; - s2jHook.free_fn = free; - } -} - #ifdef __cplusplus } #endif diff --git a/Common/s2j/s2jdef.h b/Common/s2j/s2jdef.h index c6a851e02..5d77d9e95 100644 --- a/Common/s2j/s2jdef.h +++ b/Common/s2j/s2jdef.h @@ -31,6 +31,7 @@ #include <cjson/cJSON.h> #include <string.h> +#include <stdlib.h> #ifdef __cplusplus extern "C" { @@ -116,11 +117,11 @@ typedef struct { #define S2J_CREATE_STRUCT_OBJECT(struct_obj, type) \ cJSON *json_temp; \ - type *struct_obj = s2jHook.malloc_fn(sizeof(type)); \ + type *struct_obj = malloc(sizeof(type)); \ if (struct_obj) memset(struct_obj, 0, sizeof(type)); #define S2J_DELETE_STRUCT_OBJECT(struct_obj) \ - s2jHook.free_fn(struct_obj); + free(struct_obj); #define S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, _element) \ S2J_STRUCT_GET_##type##_ELEMENT(to_struct, from_json, _element) diff --git a/libs/src/struct2json/struct2json/inc/s2j.h b/libs/src/struct2json/struct2json/inc/s2j.h index 646c34386..ff67266a6 100644 --- a/libs/src/struct2json/struct2json/inc/s2j.h +++ b/libs/src/struct2json/struct2json/inc/s2j.h @@ -29,7 +29,7 @@ #ifndef __S2J_H__ #define __S2J_H__ -#include <cJSON/cJSON.h> +#include <cjson/cJSON.h> #include <string.h> #include "s2jdef.h" @@ -80,10 +80,6 @@ extern "C" { #define s2j_struct_get_struct_element(child_struct, to_struct, child_json, from_json, type, element) \ S2J_STRUCT_GET_STRUCT_ELEMENT(child_struct, to_struct, child_json, from_json, type, element) -/* s2j.c */ -extern S2jHook s2jHook; -void s2j_init(S2jHook *hook); - #ifdef __cplusplus } #endif diff --git a/libs/src/struct2json/struct2json/inc/s2jdef.h b/libs/src/struct2json/struct2json/inc/s2jdef.h index ee6cfe0c5..5d77d9e95 100644 --- a/libs/src/struct2json/struct2json/inc/s2jdef.h +++ b/libs/src/struct2json/struct2json/inc/s2jdef.h @@ -29,8 +29,9 @@ #ifndef __S2JDEF_H__ #define __S2JDEF_H__ -#include <cJSON/cJSON.h> +#include <cjson/cJSON.h> #include <string.h> +#include <stdlib.h> #ifdef __cplusplus extern "C" { @@ -116,11 +117,11 @@ typedef struct { #define S2J_CREATE_STRUCT_OBJECT(struct_obj, type) \ cJSON *json_temp; \ - type *struct_obj = s2jHook.malloc_fn(sizeof(type)); \ + type *struct_obj = malloc(sizeof(type)); \ if (struct_obj) memset(struct_obj, 0, sizeof(type)); #define S2J_DELETE_STRUCT_OBJECT(struct_obj) \ - s2jHook.free_fn(struct_obj); + free(struct_obj); #define S2J_STRUCT_GET_BASIC_ELEMENT(to_struct, from_json, type, _element) \ S2J_STRUCT_GET_##type##_ELEMENT(to_struct, from_json, _element)