Skip to content

Commit

Permalink
Merge pull request #445 from yallop/public-types-only
Browse files Browse the repository at this point in the history
Only install cmti files for modules intended for end users
  • Loading branch information
yallop committed Sep 14, 2016
2 parents d87d527 + 2758a95 commit e638716
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 10 deletions.
6 changes: 4 additions & 2 deletions Makefile
Expand Up @@ -45,7 +45,8 @@ clean:
rm -f $(GENERATED)

# ctypes subproject
ctypes.public = ctypes_static ctypes_primitive_types unsigned signed ctypes_structs ctypes posixTypes ctypes_types
ctypes.cmi_only = ctypes_static ctypes_primitive_types ctypes_structs
ctypes.public = unsigned signed ctypes posixTypes ctypes_types
ctypes.dir = src/ctypes
ctypes.extra_mls = ctypes_primitives.ml
ctypes.deps = str bigarray bytes
Expand All @@ -59,7 +60,8 @@ ctypes: PROJECT=ctypes
ctypes: $(ctypes.dir)/$(ctypes.extra_mls) $$(LIB_TARGETS)

# cstubs subproject
cstubs.public = cstubs_internals cstubs_structs cstubs cstubs_inverted
cstubs.cmi_only = cstubs_internals
cstubs.public = cstubs_structs cstubs cstubs_inverted
cstubs.dir = src/cstubs
cstubs.subproject_deps = ctypes
cstubs.deps = str bytes
Expand Down
3 changes: 2 additions & 1 deletion Makefile.rules
Expand Up @@ -70,7 +70,8 @@ endif
LIB_TARGET_EXTRAS = $(if $(STUB_LIB),$(BUILDDIR)/lib$(PROJECT)_stubs.a) \
$(if $(XEN_LIB),$(BUILDDIR)/lib$(PROJECT)_stubs_xen.a) \
$(BUILDDIR)/$(PROJECT).a
INSTALL_CMIS = $($(PROJECT).public:%=$(BUILDDIR)/$($(PROJECT).dir)/%.cmi)
INSTALL_CMIS = $($(PROJECT).public:%=$(BUILDDIR)/$($(PROJECT).dir)/%.cmi) \
$($(PROJECT).cmi_only:%=$(BUILDDIR)/$($(PROJECT).dir)/%.cmi)
INSTALL_CMTIS = $($(PROJECT).public:%=$(BUILDDIR)/$($(PROJECT).dir)/%.cmti)
INSTALL_CMTS = $($(PROJECT).public:%=$(BUILDDIR)/$($(PROJECT).dir)/%.cmt)
INSTALL_MLIS = $($(PROJECT).public:%=$($(PROJECT).dir)/%.mli)
Expand Down
7 changes: 5 additions & 2 deletions src/ctypes-foreign-base/ctypes_foreign_basis.ml
Expand Up @@ -34,14 +34,17 @@ struct
Ctypes.ptr_of_raw_address (Ctypes_ptr.Raw.to_nativeint p)

let foreign_value ?from symbol t =
from_voidp t (ptr_of_raw_ptr (dlsym ?handle:from ~symbol))
from_voidp t (ptr_of_raw_ptr
(Ctypes_ptr.Raw.of_nativeint (dlsym ?handle:from ~symbol)))

let foreign ?(abi=Libffi_abi.default_abi) ?from ?(stub=false)
?(check_errno=false) ?(release_runtime_lock=false) symbol typ =
try
let coerce = Ctypes_coerce.coerce (static_funptr (void @-> returning void))
(funptr ~abi ~name:symbol ~check_errno ~runtime_lock:release_runtime_lock typ) in
coerce (funptr_of_raw_ptr (dlsym ?handle:from ~symbol))
coerce (funptr_of_raw_ptr
(Ctypes_ptr.Raw.of_nativeint
(dlsym ?handle:from ~symbol)))
with
| exn -> if stub then fun _ -> raise exn else raise exn
end
2 changes: 1 addition & 1 deletion src/ctypes-foreign-base/dl.ml.unix
Expand Up @@ -60,5 +60,5 @@ let dlclose ~handle =

let dlsym ?handle ~symbol =
match _dlsym ?handle ~symbol with
| Some symbol -> Ctypes_ptr.Raw.of_nativeint symbol
| Some symbol -> symbol
| None -> _report_dl_error false
2 changes: 1 addition & 1 deletion src/ctypes-foreign-base/dl.ml.win
Expand Up @@ -10,7 +10,7 @@ type dlsym_ret =
| Dlsy_nomem
| Dlsy_enoent
| Dlsy_error of string
| Dlsy_ok of Ctypes_ptr.voidp
| Dlsy_ok of nativeint
external _dlsym_default: string -> dlsym_ret = "ctypes_win32_dlsym_rtld_default"
external _dlsym: library -> string -> dlsym_ret = "ctypes_win32_dlsym"

Expand Down
2 changes: 1 addition & 1 deletion src/ctypes-foreign-base/dl.mli
Expand Up @@ -41,5 +41,5 @@ Note for windows users: the filename must be encoded in UTF-8 *)
val dlclose : handle:library -> unit
(** Close a dynamic library. *)

val dlsym : ?handle:library -> symbol:string -> Ctypes_ptr.voidp
val dlsym : ?handle:library -> symbol:string -> nativeint
(** Look up a symbol in a dynamic library. *)
4 changes: 2 additions & 2 deletions tests/test-raw/test_raw.ml
Expand Up @@ -30,7 +30,7 @@ let test_fabs _ =
let () = prep_callspec callspec Libffi_abi.(abi_code default_abi)
double_ffitype in

let dlfabs = Dl.dlsym "fabs" in
let dlfabs = Ctypes_ptr.Raw.of_nativeint (Dl.dlsym "fabs") in
let dlfabs_fat = Ctypes_ptr.Fat.make dlfabs
~reftyp:Ctypes.(double @-> returning double) in

Expand Down Expand Up @@ -65,7 +65,7 @@ let test_pow _ =
let () = prep_callspec callspec Libffi_abi.(abi_code default_abi)
double_ffitype in

let dlpow = Dl.dlsym "pow" in
let dlpow = Ctypes_ptr.Raw.of_nativeint (Dl.dlsym "pow") in
let dlpow_fat = Ctypes_ptr.Fat.make dlpow
~reftyp:Ctypes.(double @-> double @-> returning double) in

Expand Down

0 comments on commit e638716

Please sign in to comment.