caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign
@ 2013-11-19 22:57 Mike McClurg
  2013-11-20  8:23 ` Jeremy Yallop
  0 siblings, 1 reply; 4+ messages in thread
From: Mike McClurg @ 2013-11-19 22:57 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 3212 bytes --]

Hi list,

I'm running into a strange issue when compiling a ctypes (0.2.1) library
with the -thread option. Here is my test program:

    open Ctypes
    open PosixTypes
    open Foreign

    let time = foreign "time" (ptr time_t @-> returning time_t)

    let _ = ignore (time (from_voidp time_t null))

This is the simplest example I could find from the ctypes tutorial. When I
compile it without -threaded, it works:

$ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg -o
test test.ml
Effective set of compiler predicates:
pkg_unix,pkg_bigarray,pkg_ctypes,pkg_ctypes.foreign-base,pkg_ctypes.foreign,autolink,native
+ ocamlopt.opt -verbose -o test -I /Users/mike/.opam/system/lib/ctypes
/usr/local/lib/ocaml/unix.cmxa /usr/local/lib/ocaml/bigarray.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-unthreaded.cmxa test.ml
+ clang -arch x86_64 -c -o 'test.o'
'/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlasmeaa663.s'
+ clang -arch x86_64 -c -o
'/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup56e173.o'
'/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup78207e.s'
+ cc -Wl,-no_compact_unwind -o 'test'
'-L/Users/mike/.opam/system/lib/ctypes' '-L/usr/local/lib/ocaml'
'/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlstartup56e173.o'
'/usr/local/lib/ocaml/std_exit.o' 'test.o'
'/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-unthreaded.a'
'/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.a'
'/Users/mike/.opam/system/lib/ctypes/ctypes.a'
'/usr/local/lib/ocaml/bigarray.a' '/usr/local/lib/ocaml/unix.a'
'/usr/local/lib/ocaml/stdlib.a' '-L/usr/local/Cellar/libffi/3.0.13/lib'
'-lffi' '-lctypes-foreign-base_stubs'
'-L/usr/local/Cellar/libffi/3.0.13/lib' '-lffi' '-lctypes_stubs'
'-lbigarray' '-lunix' '/usr/local/lib/ocaml/libasmrun.a'

But when I use the -thread option:

$ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg
-thread -o test test.ml
Effective set of compiler predicates:
pkg_unix,pkg_threads.posix,pkg_threads,pkg_bigarray,pkg_ctypes,pkg_ctypes.foreign-base,pkg_ctypes.foreign,autolink,mt,mt_posix,native
+ ocamlopt.opt -verbose -o test -thread -I
/Users/mike/.opam/system/lib/ctypes /usr/local/lib/ocaml/unix.cmxa
/usr/local/lib/ocaml/threads/threads.cmxa
/usr/local/lib/ocaml/bigarray.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-base.cmxa
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa test.ml
+ clang -arch x86_64 -c -o 'test.o'
'/var/folders/56/7m5w0d2s31l99sh6jw_53_900000gn/T/camlasmd75109.s'
File "test.ml", line 1:
Error: Files test.cmx
       and /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa
       make inconsistent assumptions over implementation Foreign

I've deleted all the cmx/cmi/o files and rerun the above command, but I
still get this error. Here I'm using ctypes 0.2.1 from opam on OSX, but
this also fails for me with a ctypes 0.2.1 rpm I built in a CentOS 6.4
environment.

Am I doing something wrong here? Or is something wrong with the way ctypes
is built and packaged?

Mike

[-- Attachment #2: Type: text/html, Size: 3853 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign
  2013-11-19 22:57 [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign Mike McClurg
@ 2013-11-20  8:23 ` Jeremy Yallop
  2013-11-20 15:28   ` Jeremy Yallop
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Yallop @ 2013-11-20  8:23 UTC (permalink / raw)
  To: Mike McClurg; +Cc: Caml List

On 19 November 2013 22:57, Mike McClurg <mike.mcclurg@gmail.com> wrote:
> $ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg
> -thread -o test test.ml
[...]
> File "test.ml", line 1:
> Error: Files test.cmx
>        and /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa
>        make inconsistent assumptions over implementation Foreign
[...]
> Am I doing something wrong here? Or is something wrong with the way ctypes
> is built and packaged?

It's a packaging problem.  Ctypes uses a findlib feature[1] that
selects the library to link according to whether threads are enabled,
as you can see in the META file:

    archive(native, mt) = "ctypes-foreign-threaded.cmxa"
    [...]
    archive(native) = "ctypes-foreign-unthreaded.cmxa"
    (from [2])

This shows up in your command-line as expected: when you don't pass
-thread to ocamlfind it picks the -unthreaded version of the
ctypes-foreign library

   + ocamlopt.opt [...]
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-unthreaded.cmxa
test.ml

and when you pass -thread you get the -threaded version

   + ocamlopt.opt [...]
/Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa
test.ml

So far, so good.  However, although there are two cmxa implementations
installed for ctypes-foreign there's only one set of cmx files, which
happen to match the -unthreaded version of the library.  Compiling
with the -thread option picks the -threaded library but the
-unthreaded cmx, leading to the mismatch that you're seeing.  If you
simply delete the offending cmx file (as a diagnostic step, not a
long-term solution!) you should see the problem disappear:

   rm /Users/mike/.opam/system/lib/ctypes/foreign.cmx

[1] http://projects.camlcity.org/projects/dl/findlib-1.4/doc/guide-html/x261.html
[2] https://github.com/ocamllabs/ocaml-ctypes/blob/ocaml-ctypes-0.2.1/META#L39-L43

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign
  2013-11-20  8:23 ` Jeremy Yallop
@ 2013-11-20 15:28   ` Jeremy Yallop
  2013-11-20 15:55     ` Mike McClurg
  0 siblings, 1 reply; 4+ messages in thread
From: Jeremy Yallop @ 2013-11-20 15:28 UTC (permalink / raw)
  To: Mike McClurg; +Cc: Caml List

On 20 November 2013 08:23, Jeremy Yallop <yallop@gmail.com> wrote:
> On 19 November 2013 22:57, Mike McClurg <mike.mcclurg@gmail.com> wrote:
>> $ ocamlfind ocamlopt -verbose -package ctypes,ctypes.foreign -linkpkg
>> -thread -o test test.ml
> [...]
>> File "test.ml", line 1:
>> Error: Files test.cmx
>>        and /Users/mike/.opam/system/lib/ctypes/ctypes-foreign-threaded.cmxa
>>        make inconsistent assumptions over implementation Foreign
> [...]
>> Am I doing something wrong here? Or is something wrong with the way ctypes
>> is built and packaged?
>
> It's a packaging problem.

The problem is fixed in ctypes 0.2.2, which is now available via OPAM.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign
  2013-11-20 15:28   ` Jeremy Yallop
@ 2013-11-20 15:55     ` Mike McClurg
  0 siblings, 0 replies; 4+ messages in thread
From: Mike McClurg @ 2013-11-20 15:55 UTC (permalink / raw)
  To: Jeremy Yallop; +Cc: Caml List

[-- Attachment #1: Type: text/plain, Size: 315 bytes --]

On Wed, Nov 20, 2013 at 8:28 AM, Jeremy Yallop <yallop@gmail.com> wrote:

> > It's a packaging problem.
>
> The problem is fixed in ctypes 0.2.2, which is now available via OPAM.
>

Awesome, thanks Jeremy! I've tested 0.2.2 from opam on my test program and
confirmed it works. I'm updating my ctypes RPM now.

Mike

[-- Attachment #2: Type: text/html, Size: 685 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-20 15:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 22:57 [Caml-list] ctypes with -thread: inconsistent assumptions over implementation Foreign Mike McClurg
2013-11-20  8:23 ` Jeremy Yallop
2013-11-20 15:28   ` Jeremy Yallop
2013-11-20 15:55     ` Mike McClurg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).