X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fbindings%2Frmr-python%2Frmr%2Frmr.py;h=85c9ee8a0b217ab60dfaa56bff9f289191617760;hb=refs%2Fchanges%2F09%2F1209%2F1;hp=9e45dd6092ae8933243c435e39a8fee3cf67e299;hpb=ab4019f2cdf80f10323e70199d38817d19b7482b;p=ric-plt%2Flib%2Frmr.git diff --git a/src/bindings/rmr-python/rmr/rmr.py b/src/bindings/rmr-python/rmr/rmr.py index 9e45dd6..85c9ee8 100644 --- a/src/bindings/rmr-python/rmr/rmr.py +++ b/src/bindings/rmr-python/rmr/rmr.py @@ -19,6 +19,7 @@ import json from ctypes import RTLD_GLOBAL, Structure, c_int, POINTER, c_char, c_char_p, c_void_p, memmove, cast from ctypes import CDLL from ctypes import create_string_buffer +from rmr.exceptions import BadBufferAllocation # https://docs.python.org/3.7/library/ctypes.html # https://stackoverflow.com/questions/2327344/ctypes-loading-a-c-shared-library-that-has-dependencies/30845750#30845750 @@ -219,7 +220,12 @@ def rmr_alloc_msg(vctx, size): Refer to the rmr C documentation for rmr_alloc_msg extern rmr_mbuf_t* rmr_alloc_msg(void* vctx, int size) """ - return _rmr_alloc_msg(vctx, size) + sbuf = _rmr_alloc_msg(vctx, size) + try: + sbuf.contents + except ValueError: + raise BadBufferAllocation + return sbuf _rmr_free_msg = rmr_c_lib.rmr_free_msg