ppx_cstubs icon indicating copy to clipboard operation
ppx_cstubs copied to clipboard

default_headers custom order

Open ozanmakes opened this issue 2 years ago • 2 comments

Because of inclusion of default_headers before my own headers I'm getting a lot of compiler warnings. For example, I have gstreamer bindings and the gst_stubs.c ends up like this:

#include <caml/callback.h>
#include <caml/fail.h>
...
#include <ges/ges.h>
#include <gst/gst.h>

As a result of that I get many pages of warnings like so:

In file included from /usr/local/include/gstreamer-1.0/ges/ges.h:50:
In file included from /usr/local/include/gstreamer-1.0/ges/ges-asset.h:25:
In file included from /usr/local/include/gstreamer-1.0/ges/ges-extractable.h:26:
In file included from /opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/gio/gio.h:177:
/opt/homebrew/Cellar/glib/2.74.0/include/glib-2.0/gio/gvolume.h:243:69: warning: "callback" is deprecated: use "caml_callback" instead [-W#pragma-messages]
                                               GAsyncReadyCallback  callback,
                                                                    ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/compatibility.h:71:18: note: expanded from macro 'callback'
#define callback CAML_DEPRECATED("callback", "caml_callback") caml_callback
                 ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:57:3: note: expanded from macro 'CAML_DEPRECATED'
  CAML_PREPROWARNING(name1 is deprecated: use name2 instead)
  ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:55:31: note: expanded from macro 'CAML_PREPROWARNING'
#define CAML_PREPROWARNING(x) _Pragma(CAML_MAKEWARNING2(x))
                              ^
<scratch space>:89:6: note: expanded from here
 GCC warning "\"callback\" is deprecated: use \"caml_callback\" instead"
     ^
In file included from gst_stubs.c:53:
In file included from /usr/local/include/gstreamer-1.0/ges/ges.h:50:
/usr/local/include/gstreamer-1.0/ges/ges-asset.h:112:59: warning: "callback" is deprecated: use "caml_callback" instead [-W#pragma-messages]
                                      GAsyncReadyCallback callback,
                                                          ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/compatibility.h:71:18: note: expanded from macro 'callback'
#define callback CAML_DEPRECATED("callback", "caml_callback") caml_callback
                 ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:57:3: note: expanded from macro 'CAML_DEPRECATED'
  CAML_PREPROWARNING(name1 is deprecated: use name2 instead)
  ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:55:31: note: expanded from macro 'CAML_PREPROWARNING'
#define CAML_PREPROWARNING(x) _Pragma(CAML_MAKEWARNING2(x))
                              ^
<scratch space>:159:6: note: expanded from here
 GCC warning "\"callback\" is deprecated: use \"caml_callback\" instead"
     ^
In file included from gst_stubs.c:53:
In file included from /usr/local/include/gstreamer-1.0/ges/ges.h:53:
/usr/local/include/gstreamer-1.0/ges/ges-uri-asset.h:73:74: warning: "callback" is deprecated: use "caml_callback" instead [-W#pragma-messages]
                                                     GAsyncReadyCallback callback,
                                                                         ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/compatibility.h:71:18: note: expanded from macro 'callback'
#define callback CAML_DEPRECATED("callback", "caml_callback") caml_callback
                 ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:57:3: note: expanded from macro 'CAML_DEPRECATED'
  CAML_PREPROWARNING(name1 is deprecated: use name2 instead)
  ^
/Users/osener/.opam/4.14.0/lib/ocaml/caml/misc.h:55:31: note: expanded from macro 'CAML_PREPROWARNING'
#define CAML_PREPROWARNING(x) _Pragma(CAML_MAKEWARNING2(x))
                              ^
<scratch space>:70:6: note: expanded from here
 GCC warning "\"callback\" is deprecated: use \"caml_callback\" instead"
     ^
244 warnings generated.

Is there a way to customise this or work around it?

ozanmakes avatar Nov 18 '22 13:11 ozanmakes

Do the warning messages already disappear when CAML_NAME_SPACE is properly defined? ⇨ #caml-name-space

If there really is a name collision between the headers of OCaml and the manually added headers, it gets ugly. There would be more to consider and spontaneously I am unsure how to solve this in a way that is not error prone and transparent.

fdopen avatar Nov 18 '22 15:11 fdopen

I really appreciate your quick response! I wanted to try this branch first thing this week but it slipped my mind.

CAML_NAME_SPACE does the trick for my codebase. No warnings get reported anymore, and it makes it much easier to develop because warnings and errors from my own code don't get lost in all this. This is great, thanks!

ozanmakes avatar Nov 24 '22 09:11 ozanmakes