Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various Unix, Apple, and Windows fixes #16

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MisterDA
Copy link

No description provided.

- OCaml 4.13 ships realpath on Unix and Windows. Offload
  core_unix_realpath to caml_unix_realpath if OCaml >= 4.13 is used.

- realpath(..., NULL) allocating a buffer is POSIX 2008. There are no
  more common systems that don't implement this feature. The OCaml
  4.13 implementation uses it inconditonaly. It shouldn't be
  restricted to glibc (musl, BSDs, macOS support it).

- add a fallback if realpath isn't implemented (e.g., on Windows,
  before OCaml 4.13).

This also fixes the following warning:

    filename_unix_stubs.c:31:9: warning: initializing 'char *' with an expression of type 'const char *' discards qualifiers [-Wincompatible-pointer-types-discards-qualifiers]
       31 |   char *path = String_val(v_path);
          |         ^      ~~~~~~~~~~~~~~~~~~
    1 warning generated.

and makes realpath available on Windows (the following was reported by
MinGW-w64):

    In file included from C:\Users\opam\AppData\Local\opam\5.3\lib\jane-street-headers/ocaml_utils.h:6,
                     from filename_unix_stubs.c:5:
    filename_unix_stubs.c: In function 'core_unix_realpath':
    C:/Users/opam/AppData/Local/opam/5.3/lib/ocaml/caml/mlvalues.h:365:23: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
      365 | #define String_val(x) ((const char *) Bp_val(x))
          |                       ^
    filename_unix_stubs.c:31:16: note: in expansion of macro 'String_val'
       31 |   char *path = String_val(v_path);
          |                ^~~~~~~~~~
    filename_unix_stubs.c:36:7: warning: implicit declaration of function 'realpath' [-Wimplicit-function-declaration]
       36 |   if (realpath(path, resolved_path) == NULL)
          |       ^~~~~~~~
    filename_unix_stubs.c:36:37: warning: comparison between pointer and integer
       36 |   if (realpath(path, resolved_path) == NULL)
          |                                     ^~

Signed-off-by: Antonin Décimo <antonin@tarides.com>
    error_checking_mutex_stubs.c: In function 'caml_pthread_check':
    error_checking_mutex_stubs.c:23:7: warning: implicit declaration of function 'strerror_r'; did you mean 'strerror_s'? [-Wimplicit-function-declaration]
       23 |   if (strerror_r(retcode, err_buf, err_buf_len) == -1)
          |       ^~~~~~~~~~
          |       strerror_s

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>
    # core_unix_stubs.c:1055:47: warning: passing 'gid_t *' (aka 'unsigned int *') to parameter of type 'int *' converts between pointers to integer types with different sign [-Wpointer-sign]
    #   n = getgrouplist(c_user, Long_val(v_group), groups, &ngroups);
    #                                               ^~~~~~
    # /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:654:43: note: passing argument to parameter here
    # int      getgrouplist(const char *, int, int *, int *);
    #                                               ^

Signed-off-by: Antonin Décimo <antonin@tarides.com>
Signed-off-by: Antonin Décimo <antonin@tarides.com>
@github-iron github-iron added the forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system. label Jan 24, 2025
@MisterDA
Copy link
Author

MisterDA commented Feb 6, 2025

This errors still on macOS 15.3 arm64 on OCaml 5.3 with:

[ERROR] The compilation of core_unix.v0.17.0 failed at "dune build -p core_unix -j 7".

#=== ERROR while compiling core_unix.v0.17.0 ==================================#
# context     2.3.0 | macos/arm64 | ocaml-base-compiler.5.3.0 | pinned(git+https://github.com/MisterDA/core_unix.git#fixes#0bb6267bb27eb727643b448a48c86ec653073b23)
# path        ~/.opam/ocaml/.opam-switch/build/core_unix.v0.17.0
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p core_unix -j 7
# exit-code   1
# env-file    ~/.opam/log/core_unix-66188-5774d5.env
# output-file ~/.opam/log/core_unix-66188-5774d5.out
### output ###
# [...]
# (cd _build/default && /Users/antonin/.opam/ocaml/bin/ocamlopt.opt -w -40 -g -I date_unix/src/.date_unix.objs/byte -I date_unix/src/.date_unix.objs/native -I /Users/antonin/.opam/ocaml/lib/base -I /Users/antonin/.opam/ocaml/lib/base/base_internalhash_types -I /Users/antonin/.opam/ocaml/lib/base/md5 -I /Users/antonin/.opam/ocaml/lib/base/shadow_stdlib -I /Users/antonin/.opam/ocaml/lib/base_bigs[...]
# File "date_unix/src/date_unix.ml", line 15, characters 19-34:
# 15 |   let zone = force Time.Zone.local in
#                         ^^^^^^^^^^^^^^^
# Alert deprecated: Time.Zone.local
# [since 2021-03] Use [Time_float_unix]
#
# File "date_unix/src/date_unix.ml", line 15, characters 19-34:
# 15 |   let zone = force Time.Zone.local in
#                         ^^^^^^^^^^^^^^^
# Error: The value "Time.Zone.local" has type "[ `Use_Time_unix ]"
#        but an expression was expected of type "'a Base.Lazy.t" = "'a lazy_t"

@mattiasdrp
Copy link

@MisterDA Did you find a way to fix the Time.Zone.local deprecated error?

@MisterDA
Copy link
Author

@MisterDA Did you find a way to fix the Time.Zone.local deprecated error?

No, I didn't...

@shonfeder shonfeder mentioned this pull request Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
forwarded-to-js-devs This report has been forwarded to Jane Street's internal review system.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants