Commit adcb586c authored by Lev Walkin's avatar Lev Walkin

macro for free_struct()

parent 8253ea93
...@@ -133,7 +133,7 @@ ANY_to_type(ANY_t *st, asn_TYPE_descriptor_t *td, void **struct_ptr) { ...@@ -133,7 +133,7 @@ ANY_to_type(ANY_t *st, asn_TYPE_descriptor_t *td, void **struct_ptr) {
return 0; return 0;
} else { } else {
/* Remove possibly partially decoded data. */ /* Remove possibly partially decoded data. */
td->free_struct(td, newst, 0); ASN_STRUCT_FREE(*td, newst);
return -1; return -1;
} }
} }
......
...@@ -218,8 +218,7 @@ GeneralizedTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr, ...@@ -218,8 +218,7 @@ GeneralizedTime_encode_xer(asn_TYPE_descriptor_t *td, void *sptr,
rv = OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, rv = OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags,
cb, app_key); cb, app_key);
asn_DEF_GeneralizedTime.free_struct(&asn_DEF_GeneralizedTime, ASN_STRUCT_FREE(asn_DEF_GeneralizedTime, gt);
gt, 0);
return rv; return rv;
} else { } else {
return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags, return OCTET_STRING_encode_xer_utf8(td, sptr, ilevel, flags,
......
...@@ -194,7 +194,7 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -194,7 +194,7 @@ NativeInteger_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
*/ */
rval.consumed = 0; rval.consumed = 0;
} }
asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &st, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &st);
return rval; return rval;
} }
...@@ -248,7 +248,7 @@ NativeInteger_decode_uper(asn_codec_ctx_t *opt_codec_ctx, ...@@ -248,7 +248,7 @@ NativeInteger_decode_uper(asn_codec_ctx_t *opt_codec_ctx,
ASN_DEBUG("NativeInteger %s got value %ld", ASN_DEBUG("NativeInteger %s got value %ld",
td->name, *native); td->name, *native);
} }
asn_DEF_INTEGER.free_struct(&asn_DEF_INTEGER, &tmpint, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_INTEGER, &tmpint);
return rval; return rval;
} }
......
...@@ -152,7 +152,7 @@ NativeReal_encode_der(asn_TYPE_descriptor_t *td, void *ptr, ...@@ -152,7 +152,7 @@ NativeReal_encode_der(asn_TYPE_descriptor_t *td, void *ptr,
} }
/* Free possibly allocated members of the temporary structure */ /* Free possibly allocated members of the temporary structure */
asn_DEF_REAL.free_struct(&asn_DEF_REAL, &tmp, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_REAL, &tmp);
return erval; return erval;
} }
...@@ -190,7 +190,7 @@ NativeReal_decode_xer(asn_codec_ctx_t *opt_codec_ctx, ...@@ -190,7 +190,7 @@ NativeReal_decode_xer(asn_codec_ctx_t *opt_codec_ctx,
} else { } else {
rval.consumed = 0; rval.consumed = 0;
} }
asn_DEF_REAL.free_struct(&asn_DEF_REAL, st, 0); ASN_STRUCT_FREE(asn_DEF_REAL, st);
return rval; return rval;
} }
......
...@@ -244,7 +244,7 @@ main(int ac, char **av) { ...@@ -244,7 +244,7 @@ main(int ac, char **av) {
break; break;
} }
pduType->free_struct(pduType, structure, 0); ASN_STRUCT_FREE(*pduType, structure);
} }
} }
...@@ -425,7 +425,7 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f ...@@ -425,7 +425,7 @@ static void *data_decode_from_file(asn_TYPE_descriptor_t *pduType, const char *f
fclose(fp); fclose(fp);
/* Clean up partially decoded structure */ /* Clean up partially decoded structure */
pduType->free_struct(pduType, structure, 0); ASN_STRUCT_FREE(*pduType, structure);
fprintf(stderr, "%s: " fprintf(stderr, "%s: "
"Decode failed past byte %ld: %s\n", "Decode failed past byte %ld: %s\n",
......
...@@ -959,10 +959,10 @@ CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { ...@@ -959,10 +959,10 @@ CHOICE_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)ptr + elm->memb_offset); memb_ptr = *(void **)((char *)ptr + elm->memb_offset);
if(memb_ptr) if(memb_ptr)
elm->type->free_struct(elm->type, memb_ptr, 0); ASN_STRUCT_FREE(*elm->type, memb_ptr);
} else { } else {
memb_ptr = (void *)((char *)ptr + elm->memb_offset); memb_ptr = (void *)((char *)ptr + elm->memb_offset);
elm->type->free_struct(elm->type, memb_ptr, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr);
} }
} }
......
...@@ -958,10 +958,10 @@ SEQUENCE_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) { ...@@ -958,10 +958,10 @@ SEQUENCE_free(asn_TYPE_descriptor_t *td, void *sptr, int contents_only) {
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)sptr + elm->memb_offset); memb_ptr = *(void **)((char *)sptr + elm->memb_offset);
if(memb_ptr) if(memb_ptr)
elm->type->free_struct(elm->type, memb_ptr, 0); ASN_STRUCT_FREE(*elm->type, memb_ptr);
} else { } else {
memb_ptr = (void *)((char *)sptr + elm->memb_offset); memb_ptr = (void *)((char *)sptr + elm->memb_offset);
elm->type->free_struct(elm->type, memb_ptr, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr);
} }
} }
......
...@@ -924,10 +924,10 @@ SET_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { ...@@ -924,10 +924,10 @@ SET_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
if(elm->flags & ATF_POINTER) { if(elm->flags & ATF_POINTER) {
memb_ptr = *(void **)((char *)ptr + elm->memb_offset); memb_ptr = *(void **)((char *)ptr + elm->memb_offset);
if(memb_ptr) if(memb_ptr)
elm->type->free_struct(elm->type, memb_ptr, 0); ASN_STRUCT_FREE(*elm->type, memb_ptr);
} else { } else {
memb_ptr = (void *)((char *)ptr + elm->memb_offset); memb_ptr = (void *)((char *)ptr + elm->memb_offset);
elm->type->free_struct(elm->type, memb_ptr, 1); ASN_STRUCT_FREE_CONTENTS_ONLY(*elm->type, memb_ptr);
} }
} }
......
...@@ -798,7 +798,7 @@ SET_OF_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) { ...@@ -798,7 +798,7 @@ SET_OF_free(asn_TYPE_descriptor_t *td, void *ptr, int contents_only) {
for(i = 0; i < list->count; i++) { for(i = 0; i < list->count; i++) {
void *memb_ptr = list->array[i]; void *memb_ptr = list->array[i];
if(memb_ptr) if(memb_ptr)
elm->type->free_struct(elm->type, memb_ptr, 0); ASN_STRUCT_FREE(*elm->type, memb_ptr);
} }
list->count = 0; /* No meaningful elements left */ list->count = 0; /* No meaningful elements left */
...@@ -925,7 +925,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td, ...@@ -925,7 +925,7 @@ SET_OF_decode_uper(asn_codec_ctx_t *opt_codec_ctx, asn_TYPE_descriptor_t *td,
ASN_DEBUG("Failed decoding %s of %s (SET OF)", ASN_DEBUG("Failed decoding %s of %s (SET OF)",
elm->type->name, td->name); elm->type->name, td->name);
} }
if(ptr) elm->type->free_struct(elm->type, ptr, 0); if(ptr) ASN_STRUCT_FREE(*elm->type, ptr);
_ASN_DECODE_FAILED; _ASN_DECODE_FAILED;
} }
......
...@@ -52,6 +52,9 @@ typedef struct asn_struct_ctx_s { ...@@ -52,6 +52,9 @@ typedef struct asn_struct_ctx_s {
typedef void (asn_struct_free_f)( typedef void (asn_struct_free_f)(
struct asn_TYPE_descriptor_s *type_descriptor, struct asn_TYPE_descriptor_s *type_descriptor,
void *struct_ptr, int free_contents_only); void *struct_ptr, int free_contents_only);
#define ASN_STRUCT_FREE(asn_DEF, ptr) (asn_DEF).free_struct(&(asn_DEF),ptr,0)
#define ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF, ptr) \
(asn_DEF).free_struct(&(asn_DEF),ptr,1)
/* /*
* Print the structure according to its specification. * Print the structure according to its specification.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment