pnoltes commented on code in PR #699: URL: https://github.com/apache/celix/pull/699#discussion_r1476106806
########## libs/dfi/src/dyn_function.c: ########## @@ -30,141 +33,134 @@ static const int MEM_ERROR = 1; static const int PARSE_ERROR = 2; static const int ERROR = 2; -DFI_SETUP_LOG(dynFunction) +static int dynFunction_initCif(dyn_function_type* dynFunc); +static int dynFunction_parseDescriptor(dyn_function_type* dynFunc, FILE* descriptor); +static void dynFunction_ffiBind(ffi_cif* cif, void* ret, void* args[], void* userData); -static int dynFunction_initCif(dyn_function_type *dynFunc); -static int dynFunction_parseDescriptor(dyn_function_type *dynFunc, FILE *descriptor); -static void dynFunction_ffiBind(ffi_cif *cif, void *ret, void *args[], void *userData); - -ffi_type * dynType_ffiType(dyn_type *type); - -int dynFunction_parse(FILE *descriptor, struct types_head *refTypes, dyn_function_type **out) { +int dynFunction_parse(FILE* descriptor, struct types_head* refTypes, dyn_function_type** out) { int status = OK; - dyn_function_type *dynFunc = NULL; - - dynFunc = calloc(1, sizeof(*dynFunc)); + celix_autoptr(dyn_function_type) dynFunc = calloc(1, sizeof(*dynFunc)); + if (dynFunc == NULL) { + celix_err_pushf("Error allocating memory for dyn function"); + return MEM_ERROR; + } - if (dynFunc != NULL) { - TAILQ_INIT(&dynFunc->arguments); - dynFunc->refTypes = refTypes; - status = dynFunction_parseDescriptor(dynFunc, descriptor); - if (status == 0) { - int rc = dynFunction_initCif(dynFunc); - if (rc != 0) { - LOG_ERROR("Error initializing cif"); - status = ERROR; - } - } - } else { - LOG_ERROR("Error allocating memory for dyn function\n"); - status = MEM_ERROR; + TAILQ_INIT(&dynFunc->arguments); + dynFunc->refTypes = refTypes; + status = dynFunction_parseDescriptor(dynFunc, descriptor); + if (status != OK) { + celix_err_pushf("Error parsing descriptor"); + return status; + } + status = dynFunction_initCif(dynFunc); + if (status != OK) { + return status; } - if (status == OK) { - dyn_function_argument_type *arg = NULL; - TAILQ_FOREACH(arg, &dynFunc->arguments, entries) { - const char *meta = dynType_getMetaInfo(arg->type, "am"); - if (meta == NULL) { - arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD; - } else if (strcmp(meta, "handle") == 0) { - arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__HANDLE; - } else if (strcmp(meta, "pre") == 0) { - arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__PRE_ALLOCATED_OUTPUT; - } else if (strcmp(meta, "out") == 0) { - arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__OUTPUT; - } else { - arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD; + dyn_function_argument_type* arg = NULL; + TAILQ_FOREACH(arg, &dynFunc->arguments, entries) { + const dyn_type* real = dynType_realType(arg->type); + const char* meta = dynType_getMetaInfo(arg->type, "am"); + if (meta == NULL) { + arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__STD; + } else if (strcmp(meta, "handle") == 0) { + if (dynType_descriptorType(real) != 'P') { + celix_err_pushf("Error 'handle' is only allowed for untyped pointer not '%c'", dynType_descriptorType(real)); + return PARSE_ERROR; + } + arg->argumentMeta = DYN_FUNCTION_ARGUMENT_META__HANDLE; + } else if (strcmp(meta, "pre") == 0) { + if (dynType_type(real) != DYN_TYPE_TYPED_POINTER) { + celix_err_pushf("Error 'pre' is only allowed for typed pointer not '%c'", dynType_descriptorType(real)); + return PARSE_ERROR; + } + const dyn_type* sub = dynType_typedPointer_getTypedType(real); + if (!dynType_isTrivial(sub)) { + celix_err_pushf("Error 'pre' is only allowed for pointer to trivial types not non-trivial '%c'", dynType_descriptorType(sub)); Review Comment: 👍 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@celix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org