Call a function in a shared library/OCaml: Difference between revisions
Content added Content deleted
mNo edit summary |
m (fixed correctly free when failure) |
||
Line 126: | Line 126: | ||
ffi_status status; |
ffi_status status; |
||
ffi_type *rtype; |
ffi_type *rtype; |
||
int ffi_prep_cif_failed = 0; |
|||
nargs = Wosize_val(ml_args); |
nargs = Wosize_val(ml_args); |
||
Line 210: | Line 211: | ||
status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, rtype, arg_types); |
status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, nargs, rtype, arg_types); |
||
if (status != FFI_OK) |
if (status != FFI_OK) { |
||
ffi_prep_cif_failed = 1; |
|||
{ |
|||
goto freeandfail; |
|||
for (i = 0; i < nargs; i++) free(arg_values[i]); |
|||
free(arg_values); |
|||
free(arg_types); |
|||
⚫ | |||
} |
} |
||
Line 246: | Line 244: | ||
} |
} |
||
freeandfail: |
|||
for (i = 0; i < nargs; i++) { |
for (i = 0; i < nargs; i++) { |
||
switch (Tag_val(Field(ml_args, i))) { |
switch (Tag_val(Field(ml_args, i))) { |
||
Line 275: | Line 274: | ||
free(arg_values); |
free(arg_values); |
||
free(arg_types); |
free(arg_types); |
||
if (ffi_prep_cif_failed) |
|||
⚫ | |||
CAMLreturn(ml_ret); |
CAMLreturn(ml_ret); |
||
Line 286: | Line 288: | ||
Here is the '''"Makefile"''': |
Here is the '''"Makefile"''': |
||
⚫ | |||
<lang make> |
|||
⚫ | |||
FFI_CFLAGS := $(shell pkg-config --cflags libffi) |
FFI_CFLAGS := $(shell pkg-config --cflags libffi) |
||