pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42238?usp=email )
Change subject: Introduce API osmo_asn1_tcap_TCMessage_decode() ...................................................................... Introduce API osmo_asn1_tcap_TCMessage_decode() This new API allows passing a talloc context where all memory is allocated by asn1c code is allocated. Related: SYS#5423 Related: OS#6965 Change-Id: I02923afb3936a1acf6643def27528e35e4b03e86 --- A TODO-RELEASE M include/osmocom/tcap/asn_internal.h M include/osmocom/tcap/tcap.h M src/Makefile.am M src/tcap.c 5 files changed, 25 insertions(+), 4 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-asn1-tcap refs/changes/38/42238/1 diff --git a/TODO-RELEASE b/TODO-RELEASE new file mode 100644 index 0000000..9312dbd --- /dev/null +++ b/TODO-RELEASE @@ -0,0 +1,10 @@ +# When cleaning up this file: bump API version in corresponding Makefile.am and rename corresponding debian/lib*.install +# according to https://osmocom.org/projects/cellular-infrastructure/wiki/Make_a_new_release +# In short: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html#Updating-version-info +# LIBVERSION=c:r:a +# If the library source code has changed at all since the last update, then increment revision: c:r + 1:a. +# If any interfaces have been added, removed, or changed since the last update: c + 1:0:a. +# If any interfaces have been added since the last public release: c:r:a + 1. +# If any interfaces have been removed or changed since the last public release: c:r:0. +#library what description / commit summary line +libosmo-asn1-tcap add osmo_asn1_tcap_TCMessage_decode() diff --git a/include/osmocom/tcap/asn_internal.h b/include/osmocom/tcap/asn_internal.h index f4337d3..18e493f 100644 --- a/include/osmocom/tcap/asn_internal.h +++ b/include/osmocom/tcap/asn_internal.h @@ -35,7 +35,7 @@ #define ASN1C_ENVIRONMENT_VERSION 923 /* Compile-time version */ int get_asn1c_environment_version(void); /* Run-time version */ -extern void *tcap_talloc_asn1_ctx; +extern __thread void *tcap_talloc_asn1_ctx; #define CALLOC(nmemb, size) talloc_zero_size(tcap_talloc_asn1_ctx, (nmemb) * (size)) #define MALLOC(size) talloc_size(tcap_talloc_asn1_ctx, size) #define REALLOC(oldptr, size) talloc_realloc_size(tcap_talloc_asn1_ctx, oldptr, size) diff --git a/include/osmocom/tcap/tcap.h b/include/osmocom/tcap/tcap.h index 309f283..c7db4ab 100644 --- a/include/osmocom/tcap/tcap.h +++ b/include/osmocom/tcap/tcap.h @@ -6,6 +6,8 @@ #include <osmocom/tcap/TCAP_TCMessage.h> -int osmo_asn1_tcap_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data, size_t data_len); +int osmo_asn1_tcap_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data, size_t data_len) OSMO_DEPRECATED("Use osmo_asn1_tcap_TCMessage_decode() instead"); + +int osmo_asn1_tcap_TCMessage_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data, size_t data_len, void *talloc_ctx); void osmo_asn1_tcap_TCMessage_free_contents(struct TCAP_TCMessage *tcapmsg); diff --git a/src/Makefile.am b/src/Makefile.am index 42089af..78d8d0d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -243,7 +243,7 @@ ../../move-asn1-header-files.sh osmocom/tcap $(ASN_MODULE_INC) #Patch mem alloc defines to use talloc: sed -i "s/#define\tASN_INTERNAL_H/#define\tASN_INTERNAL_H\n#include <talloc.h>/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h - sed -i "s/#define\tCALLOC/extern void *tcap_talloc_asn1_ctx;\n#define\tCALLOC/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h + sed -i "s/#define\tCALLOC/extern __thread void *tcap_talloc_asn1_ctx;\n#define\tCALLOC/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h sed -i "s/calloc(nmemb, size)/talloc_zero_size(tcap_talloc_asn1_ctx, (nmemb) * (size))/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h sed -i "s/malloc(size)/talloc_size(tcap_talloc_asn1_ctx, size)/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h sed -i "s/realloc(oldptr, size)/talloc_realloc_size(tcap_talloc_asn1_ctx, oldptr, size)/g" $(top_srcdir)/include/osmocom/tcap/asn_internal.h diff --git a/src/tcap.c b/src/tcap.c index f5303ac..0957faa 100644 --- a/src/tcap.c +++ b/src/tcap.c @@ -26,7 +26,7 @@ #include <osmocom/tcap/asn_codecs.h> #include <osmocom/tcap/TCAP_TCMessage.h> -void *tcap_talloc_asn1_ctx; +__thread void *tcap_talloc_asn1_ctx; int osmo_asn1_tcap_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data, size_t data_len) { @@ -41,6 +41,15 @@ return 0; } +int osmo_asn1_tcap_TCMessage_decode(struct TCAP_TCMessage *tcapmsg, const uint8_t *data, size_t data_len, void *talloc_ctx) +{ + int rc; + tcap_talloc_asn1_ctx = talloc_ctx; + rc = osmo_asn1_tcap_decode(tcapmsg, data, data_len); + tcap_talloc_asn1_ctx = NULL; + return rc; +} + void osmo_asn1_tcap_TCMessage_free_contents(struct TCAP_TCMessage *tcapmsg) { ASN_STRUCT_FREE_CONTENTS_ONLY(asn_DEF_TCAP_TCMessage, tcapmsg); -- To view, visit https://gerrit.osmocom.org/c/libosmo-asn1-tcap/+/42238?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmo-asn1-tcap Gerrit-Branch: master Gerrit-Change-Id: I02923afb3936a1acf6643def27528e35e4b03e86 Gerrit-Change-Number: 42238 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <[email protected]>
