Commit Graph

2184 Commits (master)

Author SHA1 Message Date
Xavier Leroy d29a01e049
Merge pull request #8670 from stedolan/stack-overflow-fix
Fix stack overflow detection with systhreads.
2019-10-11 10:30:01 +02:00
Jeremie Dimino 2d31ebfc8b Add support for [@@immediate64]
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
2019-09-24 07:56:15 +01:00
Sébastien Hinderer 5ec649f0cb
Build system: share rules to compile C files (#8930)
This commit deduplicates some of the Makefile rules used to compile C files.

Rather than having one such rule per Makefile for each directory
containing C files, the relevant rules are moved to Makefile.common.in.
2019-09-11 09:16:15 +02:00
Jacques-Henri Jourdan c0dbbfdd71 Memprof: stop using C global roots, and use our own root system.
Registering and unregistering global C roots was time consuming.
2019-08-27 19:05:03 +02:00
Stephen Dolan 8b20b69a16 Fix stack overflow detection with systhreads 2019-08-27 14:58:07 +01:00
KC Sivaramakrishnan 126383b2b2 Fix long lines 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan de5ef602fd Rename exn_handler to exception_pointer 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan cededf23b9 Move local_roots, compare unorderd and gc request variables to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 3357490de0 Move native runtime globals used for roots to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan 111f6af469 Move bytecode global variables to domain state 2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan c06038a0ee Move backtrace support global variables to domain state.
Since we cannot access backtrace position in cmmgen.ml anymore,
Cmm.raise_kind in removed. Instead, we use Lambda.raise_kind. When
assembly code is generated, we reset the backtrace position to 0 in the
case of regular raise. Importantly, the semantics remains the same.
2019-08-23 09:50:05 +05:30
KC Sivaramakrishnan fc6f028492 Introduce domain state and steal exception pointer 2019-08-23 09:50:05 +05:30
Gabriel Scherer 4c303cc88a Merge pull request #8826 from glondu/4.08-spelling-errors
Fix spelling errors reported by Lintian

(cherry picked from commit c808ce7068f3e31975594bcd5e6a41dceab3a80e)
2019-07-29 08:36:53 +02:00
Leo White 57e884d57c Fix #8816 2019-07-20 14:04:51 +01:00
Greta Yorsh 351edb49bb Add compile-time option -function-sections 2019-07-15 10:25:26 +01:00
Xavier Leroy a8daa89500 Add Filename.quote_command function (#1492)
MPR#7672: add a Filename.quote_command function

This function takes care of quoting the command and its arguments
so that they are correctly parsed by the system shell
(/bin/sh for Unix, cmd.exe for Win32).

Redirections for std input (< file) and std output (> file) and
std error (2> file) can also be specified as optional arguments.
A 2>&1 redirection is used if stdout and stderr are redirected to the
same file.

The result is a string that can be passed directly to Sys.command or
to the Unix functions that expect shell command lines.
2019-06-25 14:21:58 +02:00
Gabriel Scherer ee156d72ce fix dynlink/Makefile 'depend' target to work from non-built trees
Dynlink does a weird dance of copying compiler files from various
places. The 'depend' target does not perform this copying, and instead
just 'touch'es the files that should be present to run -- defined in
DEPEND_DUMMY_FILES: if you run 'depend' after a build, you get the
real content of the files, but if you run without building you get
empty files.

This is (dubious but apparently) correct for most of those files which
should not generate dependencies anyway, but not for
dynlink_platform_intf.mli which contains important dependencies (as
in: removing them breaks the parallel build) and should be properly
built before 'depend' runs.
2019-06-24 08:17:58 +02:00
Gabriel Scherer b859714871 make alldepend (again ?!) 2019-06-20 10:58:03 +02:00
Gabriel Scherer df631380ba actually remove tools/addlabels.ml, leftover from #8663 2019-06-19 16:46:01 +02:00
Jacques-Henri Jourdan 1ea07c881b Fix Thread sanitizer after GPR#8691.
GPR#8691 refactored the signal/async callback system, and introduced
new data races to `caml_something_to_do` and friends. These data races
morally already existed and are "benign", in the sense that they can
only cause more checks for async callbacks.

The corresponding functions are now marked with a special attribute
for whitelisting them. We do no longer use -fsanitize-blacklist, which
seemed to fail preventing warnings (???).
2019-06-18 13:32:46 +02:00
Jacques-Henri Jourdan 42ab59aab1 Use [caml_something_to_do] both in native and bytecode mode to remember that callbacks are pending.
This make us able to get rid of to xxx_to_do variables in `final.c`
and `memprof.c`. The variable is reset to 0 when entering
`caml_check_urgent_gc`, which is now the main entry point for
asynchronous callbacks. In case a callback raises an exception, we
need to set it back to 1 to make sure no callback is missed.
2019-06-06 16:08:06 +02:00
Jacques-Henri Jourdan 79088fb09d Guarantee that no finalisers will be called while allocating memory in OCaml heap from C code.
The finalizers and all the other asynchronous callbacks (including
signal handlers, memprof callbacks and finalizers) are now called in a
common function, [caml_async_callbacks]. It is called in
[caml_check_urgent_gc] and wherever [caml_process_pending_signals] was
called.

This makes it possible to simplify the [caml_gc_dispatch] logic by
removing the loop it contains, since it no longer calls finalizers.
2019-06-05 14:25:26 +02:00
JPR 6dc59549ce Fixing misspellings 2019-05-21 10:23:27 +02:00
Jacques-Henri Jourdan cea1ff7534 Memprof sampling for blocks in the minor heap, allocated by C code.
Allocations ignored by this version
- Marshalling
- In the minor heap by natively-compiled OCaml code

Allocations potentially sampled
- In the major heap
- In the minor heap by C code and OCaml code in bytecode mode
2019-05-20 13:04:28 +02:00
Jacques-Henri Jourdan 052a950dea Statistical memory profiling of blocks allocated in the major heap. 2019-05-09 16:40:45 +02:00
Nicolás Ojeda Bär ea6573fda1
Implement Unix.truncate and Unix.ftruncate on Windows (#2023) 2019-05-05 09:57:48 +02:00
Xavier Leroy c4f115cdae Be more explicit about the default values of parameters
This generic Makefile is parameterized by several "make" variables,
- two that must be set by the calling Makefile
- nine that can be set by the calling Makefile but have default values
  otherwise.

This commit sets explicitly the default values of the nine variables above,
using "VAR ?= default-value", even if the default value is the empty string.

This avoids spurious warnings by "make --warn-undefined-variables"
and is good documentation-in-code.
2019-05-02 19:43:17 +02:00
Thomas Refis 8ee36fe2db turn off warning 40 2019-04-16 10:41:35 +01:00
Mark Shinwell 8c9e0cfbb5
make alldepend (#8577) 2019-04-02 16:38:02 +01:00
Xavier Leroy aafcd12536
Merge pull request #8568: Bigarray mmap leak 2019-04-02 11:06:51 +02:00
Mark Shinwell 72ea849d2a
Move some middle-end files around (#2281)
* Various file moves in the middle end: this is the first stage of improving separation between the middle end and backend.
* Creation of file_formats/ directory (with associated file moves) to hold the definitions of compilation artifact formats.
* Creation of lambda/ directory (with associated file moves) to hold Lambda language definition files, transformation passes and construction passes from Typedtree.
* Disable (hopefully temporarily) dynlink, debugger and ocamldoc for the dune build.
2019-04-01 17:18:47 +01:00
Damien Doligez 822557f278 fix buggy assertion 2019-04-01 16:22:48 +02:00
Gabriel Scherer c7534721dd partial fix for the dune build
The dune build is, in fact, still broken by format-related changes,
as it does not use the bootstrap compiler.
2019-03-31 09:52:47 +02:00
Mark Shinwell dbede46c2e
Improve the packing mechanism used to build Dynlink (#2268) 2019-03-19 10:26:35 +00:00
Jérémie Dimino c413136fa3 Delete otherlib/{graph,win32graph} (#2318)
The Graphics library is now distributed as a separate package.
The sources are at https://github.com/ocaml/graphics .

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
2019-03-18 15:05:57 +01:00
Stephen Dolan 4f03a1467d
Merge pull request #2293 from stedolan/named-value-const
Make caml_named_value return a const value*
2019-03-18 09:45:02 +00:00
Stephen Dolan 838e44a245
Update issue numbers in comments after Mantis -> Github migration. (#8505) 2019-03-18 09:42:23 +00:00
Jérémie Dimino 9387160a21 Delete old compatibility from the bigarray stubs (#2315)
The compatibility macros (that were introduced while moving bigarray file mapping functions to the Unix library) are no longer necessary, so let's get rid of them.

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
2019-03-13 11:51:02 +01:00
Mark Shinwell 36c163248d Remove support for compiler plugins (#2276)
After consultation on the core developers' list I am proposing this patch to remove support for compiler plugins.

The main motivations for removing compiler plugins are:
- They are a potential security risk.
 - They increase the complexity of the build system and make maintenance of the Dynlink libraries more difficult (although actually, this complexity could probably be reduced after #2268 is merged).
 - Many applications of plugins should be able to be expressed by building custom compiler drivers that link against compilerlibs.

* Remove compiler plugins and hooks
* Add new function Dynlink.unsafe_get_global_symbol but keep it outside the documented API.
* Remove otherlibs/dynlink/nodynlink.ml
* Update Changes
2019-03-13 11:46:37 +01:00
Stephen Dolan c58cddf219 Add const annotation to win32unix 2019-03-12 12:07:34 +00:00
Stephen Dolan 9f0bebf7f7 Make caml_named_value return a const value*.
This commit just adds "const" in several places.
2019-03-12 12:07:04 +00:00
Jérémie Dimino 705054b346 Delete the vmthreads library (#2289)
* Delete the deprecated vmthreads library

It was deprecated in 4.08.

* Remove the byte/native argument of init_path

It is no longer necessary.

* Error out when passing --{enable,disable}-vmthreads to ./configure

Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
2019-03-11 19:38:16 +01:00
Xavier Leroy 187ceb63a0
MPR#7903: make Thread.delay interruptible again (#2306)
In OCaml 4.07, Unix.sleepf and Thread.delay were changed so that they
would restart the sleep when interrupted by a signal (error EINTR).

The unintended consequence is that Thread.delay will not run
signal handlers until the full delay has expired.  If the effect
of the handler is to raise an exception, as with Sys.catch_break,
the delay is not terminated early.

(This is specific to threaded programs, where asynchronous invocation
of signal handlers is turned off and handlers are only run at the next
leave-blocking-section.  Using Unix.sleepf in a non-threaded program
doesn't show the issue because the handler is invoked asynchronously.)

This commit implements a more intuitive behavior, closer to that of 4.06:
signals received during Thread.delay are handled immediately, and if
the handler returns normally, the delay is restarted with the remaining time.

A test is added in testsuite/tests/lib-threads/delayintr.ml
2019-03-11 09:33:18 +01:00
Nicolás Ojeda Bär 3bde063f20 nodynlink.ml: add missing definition for run_shared_startup 2019-03-10 10:14:19 +01:00
Nicolás Ojeda Bär 8da6a7d4d2 Dynlink: run _shared_startup only once per plugin 2019-03-07 11:10:19 +01:00
Romain Beauxis cf39e92d32 Set default status in Unix.waitpid when pid = 0. (#2225)
When `Unix.waitpid` returns immediately with pid = 0, make sure the status returned is always `WEXITED 0` and not some random value coming from an uninitialized C variable.
2019-03-01 15:54:43 +01:00
Jacques-Henri Jourdan 08ed1e85cd Fix Thread.sigmask, take 2 (#2211)
Fix Thread.sigmaks, by checking whether a signal is masked before handling it.

We use [sigprocmask] (if available) to check whether a signal is
blocked when the systhread library is not loaded. As soon as the
[Thread] module gets loaded, we use [pthread_sigmask] instead, and
redirect all the calls to [sigprocmask] to [pthread_sigmask].  Indeed,
the latter has unspecified behavior in a multi-threaded context
anyway.  In practice, this should not change the semantics of
[Unix.sigprocmask] on Linux, since on this platform, [pthread_sigmask]
is actually an alias for [sigprocmask]. On MacOSX, the semantics will
change, since [sigprocmask] changes the masks of the whole process on
this platform.

Also, include [caml_pending_signals] in signals returned by
[Unix.sigpending]. Indeed, some signals might have been handled in the
POSIX sense by the C handler in the OCaml runtime, but not been
handled in the OCaml sense (for example, because they are blocked).

This commit un-reverts 1c82c481a, which has been reverted in
79eb572e4. The issues of the original commit are corrected in this commit.
2019-03-01 14:14:29 +01:00
David Allsopp 1626a018d8 Remove unnecessary executable bit from sources (#2270)
Various files which seem to have acquired Git executable bits.
File contents are unchanged; only permissions are changed.
2019-02-28 16:29:26 +01:00
Jeremie Dimino 8d8df4e1d8 Delete the deprecated Bigarray.*.map_file functions
Signed-off-by: Jeremie Dimino <jeremie@dimino.org>
2019-02-26 11:13:44 +00:00
David Allsopp 7bd3162313 Support otherlibs with no COBJS 2019-02-26 11:13:44 +00:00
Tim Cuthbertson 3424192d48 alloc_sockaddr: handle abstract paths (v2) (#2248)
Second version of b743ea476b
2019-02-21 15:37:25 +00:00
Sébastien Hinderer 6da5262dd1 Bump magic numbers to keep in sync with the 4.08 branch
This commit is the trunk counterpart of
e413426bc766c9046a18b873a417b596bf0871d7 on the 4.08 branch
2019-02-21 11:25:23 +01:00
Damien Doligez 58f9eff953 bump magic numbers and bootstrap to catch up with branch 4.08 (#2249) 2019-02-19 15:57:28 +01:00
Gabriel Scherer 93f0ce31bb env refactoring: separate the cmi/crc handling into a persistent_env module
Persistent_env is a new module that handles the relation between the
type-checking state and the "persistent" typing information laying in
.cmi files on the filesystem. In particular, it handles the collection
and production of CRC information for the .cmi files being read and
written to the filesystem; the using modules (in our case, only Env)
are in charge of turning the cmi files into higher-level information
(components and signatures).

Persistent_env exposes a type `'a t` of a persistent environment,
which acts as a mutable store of `'a` values. There is no global state
in the module itself: while Env (and thus the OCaml type-checker) uses
a single global persistent environment, it should be possible to
create several independent environments to represent, for example,
several independent type-checking sessions.
2019-02-18 17:02:47 +01:00
Fourchaux 1946594bd7 Fixing typos in various files (#2246)
Note: Typos found with https://github.com/codespell-project/codespell

Here is the (semi-manual) command used to get (and correct) the typos:

$ codespell -i 3 -w --skip=".png,.gif,./ocaml/boot,./ocaml/.git,./ocaml/manual/styles,./ocaml/manual/manual/htmlman" -L minimise,instal,contructor,"o'caml",cristal,pres,clos,cmo,uint,iff,te,objext,nto,nd,mut,upto,larg,exten,leage,mthod,delte,tim,atleast,langage,hten,iwth,mke,contant,succint,methids,eles,valu,clas,modul,que,classe,missings,froms,defaut,correspondance,differents,configury,reachs,cas,approche,normale,dur,millon,amin,oje,transfert
2019-02-13 14:04:56 +01:00
Jeremie Dimino 0a3525cc51 Revert "alloc_sockaddr: handle abstract paths"
This patch is causing compilation failures on several achitectures.

This reverts commit b743ea476b.
2019-02-11 16:12:44 +00:00
ahh 7a27cd56b1 Thread.yield fairness with multiple busy yielding threads (#2112)
Thread.yield invoked a trivial blocking section, which basically woke
up a competitor and then raced with them to get the ocaml lock back, invoking
nanosleep() to help guarantee that the yielder would lose the race. However,
until the yielder woke up again and attempted to take the ocaml lock, it
wouldn't be marked as a waiter.

As a result, if two threads A and B yielded to each other in a tight loop, A's
first yield would work well, but then B would execute 10000+ iterations of the
loop before A could mark itself as a waiter and be yielded to. This works even
worse if A and B are pinned to the same CPU, in which case A can't be marked as
a waiter until the kernel preempts B, which can take tens or hundreds of
milliseconds!

So we reimplement yield; instead of dropping the lock and taking it again (with
a wait in the middle), atomically wake a competitor and mark the yielding thread
as a waiter. (We essentially inline a failed masterlock_acquire into
masterlock_release, specialized for the case where we know another waiter exists
and we want them to run instead.)

Now, threads yielding to each other very consistently succeed--in that same
tight loop, we see a change of control on every iteration (with some very rare
exceptions, most likely from other uncommon blocking region invocations.)

This also means we don't have to worry about the vagaries of kernel scheduling
and whether or not a yielding or a yielded-to thread gets to run first; we
consistently let a competing thread run whenever we yield, which is what the API
claims to do.
2019-02-08 17:18:27 +01:00
Tim Cuthbertson b743ea476b alloc_sockaddr: handle abstract paths 2019-02-07 09:20:48 +00:00
Guillaume Munch-Maccagnoni f68692ebc2 Improve protect
- Treat as an error the case where ~finally raises an exception

- Move to Fun module

- Describe the purpose in the documentation

- Remove boilerplate

https://github.com/ocaml/ocaml/pull/2118
2019-02-03 12:27:27 +01:00
David Allsopp 7b9f1b4f10 Fix support for -no-shared-libs
Changes in GPR#1063 weren't applied to nodynlink.ml
2019-02-01 16:18:53 +01:00
Jeremie Dimino 7e0862a212 Refactor load path management and initial environment
- Add a Load_path module which caches files lookup

- Instead of falling back to the external environment, allow to
  declare in the environment that a module comes from the external
  world. This allows persistent structures to shadows non-persistent
  ones
2019-01-30 16:36:38 +00:00
Gabriel Scherer 2956845681
Merge pull request #2220 from toots/fix-find_proc_id
Fix process_*_pid semantics
2019-01-29 14:29:46 +01:00
Romain Beauxis 00bbe473e6 Fix process_*_pid semantics: do not remove process from list of running
processes when fetching its pid. Remove duplicate code in
otherlibs/threads/unix.ml
2019-01-20 10:28:57 -06:00
Damien Doligez 6bbb913693 last commit before branching 4.08 2019-01-18 15:29:36 +01:00
Sébastien Hinderer 8550f71441 Build system: use $(ROOTDIR) rather than hardcoded paths to access ocamlc 2019-01-03 17:02:25 +01:00
Sébastien Hinderer d258bb78ac Build system: use ocamlc -depend rather than ocamldep 2019-01-03 16:43:23 +01:00
David Allsopp 79eb572e42 Revert 1c82c481a5.
Problem with the test on macOS and FreeBSD + issue with downstream use
of signals_are_pending
2018-12-21 17:05:17 +01:00
Florian Angeletti e8d4324ee6
documentation: use Bigarray consistently (#2208) 2018-12-20 18:46:54 +01:00
Jacques-Henri Jourdan 1c82c481a5 Fix Thread.sigmaks, by checking whether a signal is masked before handling it.
We use [sigprocmask] (if available) to check whether a signal is blocked when
the systhread library is not loaded. When it gets loaded, we use
[pthread_sigmask] instead.

Also, include [caml_pending_signals] in signals returned by
[Unix.sigpending]. Indeed, some signals might have been handled in the
POSIX sense by the C handler in the OCaml runtime, but not been
handled in the OCaml sense (for example, because they are blocked).
2018-12-19 10:32:37 +00:00
Gabriel Scherer 295f71cb96 make alldepend (with new one-dep-per-file printing) 2018-12-12 09:38:49 +01:00
Gabriel Scherer 31ce53e166
Merge pull request #2191 from Octachron/manual_graphic
graphic documentation: images are bound to windows
2018-12-09 22:10:21 +01:00
Florian Angeletti cc8cd38f71 graphic documentation: images are bound to windows 2018-12-09 18:37:11 +01:00
Leo White 11d759c584
Fix new dynlink's initialisation checks (#2176) 2018-12-08 10:15:19 -05:00
David Allsopp a875e64571 Missing clean items from GPR#1063 2018-12-06 18:14:38 +00:00
Thomas Refis f9b8935b2e
make alldepend (#2181) 2018-12-03 18:15:28 +01:00
Runhang Li 97329f30ed Extend `open` to arbritrary module expressions in structures and to
applicative module paths in signatures
2018-11-26 16:20:37 +00:00
Leo White fc1e6ad5a2 Update .depend 2018-11-21 03:39:34 -05:00
Thomas Refis aa77d3b93d
fix dune build following natdynlink modifications (#2154)
- silence some principality warning in otherlibs/dynlink
- shared some script between the makefile and the dune files
2018-11-20 15:06:47 +01:00
Nicolás Ojeda Bär fc238875d2
Merge pull request #1063 from mshinwell/natdynlink_load_once
Make (nat)dynlink sound (also fixes MPR#4208, MPR#4229, MPR#4839, MPR#6462, MPR#6957, MPR#6950)
2018-11-15 13:39:04 +01:00
Mark Shinwell 690116890e Various Makefile / dependency fixes 2018-11-15 10:42:49 +00:00
Alain Frisch 2e5b9d1ef1
"Alerts" as a generalization of "deprecated" (#1804) 2018-11-15 09:51:35 +01:00
Mark Shinwell 960cef2e7d Fix makefile problems 2018-11-14 16:20:06 +00:00
Mark Shinwell a4c88eab27 Fixing dynlink makefiles 2018-11-14 13:10:08 +00:00
Mark Shinwell 6526a0c3d9 Make (nat)dynlink sound 2018-11-12 17:44:26 +00:00
Gabriel Scherer 2387870fb3 otherlibs/Makefile with 'all allopt clean partialclean'
I frequently get (parallel) build failures due to wrong dependencies
causing compilation failures in some otherlibs/ subdirectory. When
that happens, my workflow is to go to that subdirectory, run 'make
clean', and then compile again. But then another subdirectory is
broken for the same reason...

This otherlibs/Makefile provides a 'clean' target that will run clean
in all subdirectories (all the ones selected to be built at
configure-time), as well as 'all', 'allopt', 'partialclean' targets
that similarly dispatch to all subdirectories.

This is exactly the logic already present in the 'otherlibraries*'
targets of the root Makefile, except more fun with Make-style generic
functions.
2018-11-12 16:28:01 +01:00
Gabriel Scherer 375dd4a79e rename otherlibs/Makefile into otherlibs/Makefile.otherlibs.common
This file is meant to be included by the per-directory makefiles
of otherlibs/*/Makefile; its target cannot be run directly from
otherlibs/. We would like to propose targets from otherlibs/,
in a new Makefile.
2018-11-12 16:28:01 +01:00
Daniel Bünzli acb0e91ac6 Stdlib doc: harmonize heading levels again. (#2142) 2018-11-08 17:33:55 +01:00
yallop ee1c2a4d7e Add paths for built-in types (#1876)
* Add an Extension_constructor submodule to Obj.

Deprecate top-level functions extension_constructor / extension_name /
extension_id.

* Add 'true' and 'false' to the definition of Bool.t

* Add aliases for the built-in 'list' and 'array' types.

* Add an alias for 'exn' to Printexc.

* Changes entry: built-in type aliases

* Add a Unit module.

* Add paths for built-in exceptions.
2018-11-08 16:08:17 +01:00
Daniel Bünzli a7afd89003 s/string_of_int/Int.to_string/g 2018-11-07 13:52:02 +01:00
Daniel Bünzli 89e48a38e9 Stdlib: add Fun module. (#2129)
* Stdlib: add Fun module.

* Stdlib: rename Bool.negate to Fun.negate.
2018-11-06 10:36:07 +01:00
Daniel Bünzli fdba70136f Stdlib: add Bool module. 2018-10-23 11:35:08 +02:00
Nicolás Ojeda Bär 90d9b2287a
Merge pull request #2011 from dbuenzli/int-support
Improve stdlib support for `int`
2018-10-23 11:23:14 +02:00
Gabriel Scherer 4a021322a2
Merge pull request #2100 from Armael/getaddrinfo
Fix Unix.getaddrinfo when called on strings containing null bytes
2018-10-11 22:36:29 +02:00
Armaël Guéneau f249c73178 Fix Unix.getaddrinfo when called on strings containing null bytes 2018-10-10 19:24:21 +02:00
Thomas Refis d68e0e2077
Provide a way to build the bytecode compiler using Dune (#2093) 2018-10-10 16:16:00 +01:00
Daniel Bünzli 5846aecee6 Stdlib: add Int module. 2018-10-09 10:20:39 +02:00
Sébastien Hinderer 01b65ac0af Introduce and use ROOTDIR in more makefiles 2018-09-17 14:51:01 +02:00
Sébastien Hinderer ba6362a07d Move config/Makefile to Makefile.config
In order to prepare the transition to autoconf, this commit moves the
configuration Makefile out of the config directory which will disappear
and gives it the name it will have once intstalled, namely Makefile.config.
2018-09-17 14:23:35 +02:00
Damien Doligez 2fd0186648
Merge pull request #1683 from stedolan/marshal-custom-length
Make marshalled Custom_tag objects store their length.
2018-09-14 10:58:27 +02:00
David Allsopp b069f692b4 Remove space from end of FLEXLINK_ENV 2018-09-07 08:34:53 +02:00
David Allsopp 4756a576f0 Move FLEXLINK_ENV definition to Makefile.common 2018-09-07 08:34:53 +02:00
David Allsopp c13c200f87 Standardise setting and use of OCAML_FLEXLINK
Some Makefiles were using export to set OCAML_FLEXLINK "globally" while
others set a variable FLEXLINK_ENV and set the environment explicitly.

All Makefiles now use FLEXLINK_ENV and also only invoke it on linking
commands (rather than, for example, all invocations of ocamlopt).
2018-09-07 08:34:53 +02:00
Gabriel Scherer ac265e9ea3 (minor) remove unused CAMLYACC variables 2018-09-01 23:17:06 +02:00
Nicolás Ojeda Bär db9671f67b
Merge pull request #1999 from toots/process_pid
API to retrieve high level process's PIDs
2018-08-28 07:14:09 +05:30
Jérémie Dimino 9124ab82d1
Deprecate Pervasives (#1605)
- inline Pervasives in Stdlib and re-add Pervasives as a deprecated
module that aliases all elements of Stdlib except the stdlib modules.

- remove special case for Stdlib.Pervasives in printtyp.ml
2018-08-27 12:42:14 +01:00
Romain Beauxis f5051da474 Add API to retrieve high level process's PIDs 2018-08-23 14:10:17 -05:00
Stephen Dolan e9b04bb0d5 Add CODE_CUSTOM_FIXED for fixed-size custom serializers.
As a space optimisation, custom serializers that always consume
the same number of bytes need not send the lengths explicitly.
2018-08-22 10:33:09 +01:00
Nicolás Ojeda Bär 4a2b27afd0
Merge pull request #1855 from mseri/pervasive-finally
Add "finally" function to Pervasives
2018-08-08 17:31:01 +02:00
Daniel Bünzli 1798999b65 Stdlib: add Option module. 2018-08-08 11:41:09 +02:00
Daniel Bünzli b7affbb9ef Stdlib: add Result module. 2018-08-08 10:34:03 +02:00
Marcello Seri 129458bf0f stdlib: address @nojb review comments
Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:29:07 +02:00
Marcello Seri 5c0b6f71bd stdlib: rename try_finally to protect
As a result of the poll in #1855.
The votes at the time of commiting are:

- 18 for `protect ~finally`
- 12 for `try_finally ~finally`
- 1  for `finally ~cleanup`
- 0  for `try_finally ~always`
- 0  for `try_finally ~cleanup`

Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:26:05 +02:00
Marcello Seri cbb2ed7833 stdlib: simplify try_finally signature and implementation
Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:24:53 +02:00
Marcello Seri 3f2acd87a3 stdlib: use a version of @bobot try_finally
`try_finally work ~always ~exceptionally` is designed to run code
in `work` that may fail with an exception, and has two kind of
cleanup routines:

- `always`, that must be run after **any** execution of the function
  (typically, freeing system resources), and

- `exceptionally`, that should be run **only** if `work` or `always`
  failed with an exception (typically, undoing user-visible state
  changes that would only make sense if the function completes
  correctly).

I had to locally re-define `rab_backtrace`, `get_raw_backtrace`,
`raise_with_backtrace` because I could not refer to `Printexc`.

Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:24:53 +02:00
Marcello Seri 8a90c6ff77 stdlib: update try_finally to newer syntax
Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:24:52 +02:00
Marcello Seri af9174ff52 stdlib: introduce try_finally in Pervasives
Signed-off-by: Marcello Seri <marcello.seri@gmail.com>
2018-08-07 20:24:52 +02:00
Gabriel Scherer d5c76eaa9f make alldepend 2018-08-06 17:31:52 +02:00
Hugo Heuzard 1ac5954ca7 depend 2018-08-06 13:19:28 +01:00
Nicolás Ojeda Bär 27ee0bfb9f Fix Unix.fsync on Windows: retrieve fd outside blocking section 2018-07-31 23:25:20 +02:00
Francois Berenger 5b884d6244 Unix fsync (#1839)
* added otherlibs/unix/fsync.c and otherlibs/unix/unix.ml

* add Unix.fsync

* added otherlibs/win32unix/fsync.c

* Unix.fsync for windows

* big typo

* Rewrite Unix.fsync stub for Windows

* belts and braces: fail in the case of named pipe

* Add missing include

* corrected header

* better ocamldoc for fsync

* rm fsync.c from the UNIX_FILES list

* updated Changes for Unix.fsync

* Use _commit instead of FlushFileBuffers

* Include <io.h>
2018-07-31 07:57:21 +02:00
Xavier Clerc 7e29162582 Pass the elements from `BUILD_PATH_PREFIX_MAP` to the assembler (#1930) 2018-07-27 12:25:23 +02:00
Gabriel Radanne 1be47bf7ab Just some tbl things. (#1699) 2018-07-23 13:19:41 +01:00
whitequark 1ebc9f5a4c Remove the Sort module. (PR7812)
It has been deprecated since 2000, shown a deprecation warning
since 4.02, and Sort.merge is documented to have undefined behavior
when the lists being merged are not sorted in the first place.
2018-07-13 16:04:49 +02:00
sliquister 2d445f5cc1 Make Printexc.get_callstack work in newly-created, native-code threads (#1895)
The `top_of_stack` field of the `th` descriptor for the new thread was initialized too late, causing `caml_top_of_stack` to be NULL when the thread starts running.  The fix is to initialize `th->top_of_stack` earlier.
2018-07-12 19:32:10 +02:00
Valentin Gatien-Baron 71f20ee78a install the mli files of the thread library next to its cmi/cmt/etc
Here is the diff in the installation directory, limited to the condition module:
-./lib/ocaml/condition.mli
 ./lib/ocaml/threads/condition.cmi
 ./lib/ocaml/threads/condition.cmti
 ./lib/ocaml/threads/condition.cmx
+./lib/ocaml/threads/condition.mli
 ./lib/ocaml/vmthreads/condition.cmi
 ./lib/ocaml/vmthreads/condition.cmti
 ./lib/ocaml/vmthreads/condition.mli

and overall:

@@ -1300,7 +1300,6 @@
 ./lib/ocaml/complex.mli
 ./lib/ocaml/complex.p.cmt
 ./lib/ocaml/complex.p.cmx
-./lib/ocaml/condition.mli
 ./lib/ocaml/digest.cmi
 ./lib/ocaml/digest.cmt
 ./lib/ocaml/digest.cmti
@@ -1324,7 +1323,6 @@
 ./lib/ocaml/ephemeron.mli
 ./lib/ocaml/ephemeron.p.cmt
 ./lib/ocaml/ephemeron.p.cmx
-./lib/ocaml/event.mli
 ./lib/ocaml/expunge
 ./lib/ocaml/extract_crc
 ./lib/ocaml/filename.cmi
@@ -1471,7 +1469,6 @@
 ./lib/ocaml/moreLabels.mli
 ./lib/ocaml/moreLabels.p.cmt
 ./lib/ocaml/moreLabels.p.cmx
-./lib/ocaml/mutex.mli
 ./lib/ocaml/nativeint.cmi
 ./lib/ocaml/nativeint.cmt
 ./lib/ocaml/nativeint.cmti
@@ -1774,27 +1771,30 @@
 ./lib/ocaml/sys.p.cmx
 ./lib/ocaml/target_camlheaderd
 ./lib/ocaml/target_camlheaderi
-./lib/ocaml/thread.mli
 ./lib/ocaml/threads
 ./lib/ocaml/threads/condition.cmi
 ./lib/ocaml/threads/condition.cmti
 ./lib/ocaml/threads/condition.cmx
+./lib/ocaml/threads/condition.mli
 ./lib/ocaml/threads/event.cmi
 ./lib/ocaml/threads/event.cmti
 ./lib/ocaml/threads/event.cmx
+./lib/ocaml/threads/event.mli
 ./lib/ocaml/threads/mutex.cmi
 ./lib/ocaml/threads/mutex.cmti
 ./lib/ocaml/threads/mutex.cmx
+./lib/ocaml/threads/mutex.mli
 ./lib/ocaml/threads/thread.cmi
 ./lib/ocaml/threads/thread.cmti
 ./lib/ocaml/threads/thread.cmx
+./lib/ocaml/threads/thread.mli
 ./lib/ocaml/threads/threads.a
 ./lib/ocaml/threads/threads.cma
 ./lib/ocaml/threads/threads.cmxa
 ./lib/ocaml/threads/threadUnix.cmi
 ./lib/ocaml/threads/threadUnix.cmti
 ./lib/ocaml/threads/threadUnix.cmx
-./lib/ocaml/threadUnix.mli
+./lib/ocaml/threads/threadUnix.mli
 ./lib/ocaml/topdirs.cmi
 ./lib/ocaml/topdirs.cmt
 ./lib/ocaml/topdirs.cmti
2018-07-01 07:50:33 -04:00
David Allsopp d5952a5093 GPR#1061 check-typo compliance 2018-07-01 10:55:30 +01:00
Sébastien Hinderer d3e73595e5 Merge the asmrun and byterun directories into the runtime directory 2018-06-28 17:50:33 +02:00
Christopher Zimmermann 5792a9e983 Unix.link: include errno.h, correctly set feature test macro
Which is needed for the case without support for linkat as reported by Gabriel Scherer.
Also set _XOPEN_SOURCE == 700 instead of testing for it.
Test for availablility of linkat by looking at AT_SYMLINK_FOLLOW, which is, according to
introduced in POSIX IEEE Std 1003.1-2008 for linkat.
2018-06-26 13:57:54 +02:00
madroach cba4ca510c Add ~follow option to Unix.link (#1061)
This allows hardlinking symlinks.
2018-06-25 13:39:21 +02:00
Gabriel Scherer f3aca2376f
Merge pull request #1821 from gasche/makefiles-consistent-opt-targets
Makefiles: consistently offer `allopt` and `opt.opt` targets
2018-06-24 00:46:50 +02:00
Sébastien Hinderer 85fa27f7e9 Rename C compiler related build variables
This commit renames a few C compiler related build variables so that
they are reserved for the build system. They will then be re-introduced,
but this time as user varialbes whose value can be freely customized
when compiling the package, without risking to conflict with those
command-line flags that are required by the build system itself.

Here are the variables this commit renames:

- CFLAGS -> OC_CFLAGS
- CPPFLAGS -> OC_CPPFLAGS
- LDFLAGS -> OC_LDFLAGS

Note: before this commit the compilation of scheduler.c in
otherlibs/threads was relying on make's implicit rule to compile C files.

Since this commit stops using the standard variables for flags,
it is necessary to introduce an explicit rule to compile C files
and that makes use of the newly introduced variables.
2018-06-20 14:01:42 +02:00
Sébastien Hinderer a10a3f5806 Rename build variable SHAREDCCCOMPOPTS to SHAREDLIB_CFLAGS 2018-06-20 14:01:42 +02:00
Gabriel Scherer 60167c1def
Merge pull request #1847 from gasche/fix-bigarray-depend
fix 'depend' target in otherlibs/bigarray
2018-06-19 18:28:26 +02:00
Gabriel Scherer ca9fd145d4 fix 'depend' target in otherlibs/bigarray
This target has been broken by the move of bigarray C files to the runtime.
Before the current PR:

```
$ make depend
gcc -MM -O2 -fno-strict-aliasing -fwrapv -Wall -Werror -fno-tree-vrp -fPIC -I../unix -DIN_OCAML_BIGARRAY -D_FILE_OFFSET_BITS=64 -D_REENTRANT -DCAML_NAME_SPACE  -I../../byterun *.c | sed -e 's/\.o/.$(O)/g' > .depend
gcc: error: *.c: No such file or directory
gcc: fatal error: no input files
```
2018-06-19 15:02:34 +02:00
Gabriel Scherer feb27cfd94 make alldepend 2018-06-19 15:00:22 +02:00
David Allsopp 4197e75b6b GPR#1825 check-typo compliance 2018-06-14 15:15:34 +01:00
David Allsopp b5d1929e87 Whitespace and overlong line fixes. 2018-06-14 15:15:34 +01:00
Xavier Leroy ea9dc4e555
Add checks to the conversion of Unix file descriptors to I/O channels (#1825)
Unix.{in,out}_channel_of_descr now check that descr has stream semantics.
These functions fail if the given file descriptor is not suitable for
character-oriented I/O, e.g. a block device or a datagram socket.
Fixes part of MPR#7238.
2018-06-14 10:56:25 +02:00
David Allsopp 061262ba70 Fix over-long lines with minor re-wordings 2018-06-13 09:37:49 +01:00
Gabor Igloi 04cc9e8a7c Fix docstring of stats.st_rdev in Unix modules
The st_rdev is not the minor number, it is the device ID according to
the manpage of stat, which is actually the major * 256 + minor. I've
replaced the old incorrect docstring with the description of st_rdev
from the man page of the stat command - it looks like the implemenation
of Unix.stat just puts the st_rdev returned from stat into the st_rdev
field.

Signed-off-by: Gabor Igloi <gabor.igloi@citrix.com>
2018-06-07 17:09:03 +01:00
Xavier Leroy 1c4e822bed
Cleaning up the C code (#1812)
Running Clang 6.0 and GCC 8 with full warnings on suggests a few simple improvements and clean-ups to the C code of OCaml.  This commit implements them.

* Remove old-style, unprototyped function declarations

It's `int f(void)`, not `int f()`.  [-Wstrict-prototypes]

* Be more explicit about conversions involving `float` and `double`

byterun/bigarray.c, byterun/ints.c:
  add explicit casts to clarify the intent
  renamed float field of conversion union from `d` to `f`.

byterun/compact.c, byterun/gc_ctrl.c:
  some local variables were of type `float` while all FP computations
  here are done in double precision;
  turned these variables into `double`.

[-Wdouble-promotion -Wfloat-conversion]

*Add explicit initialization of struct field `compare_ext`

[-Wmissing-field-initializers]

* Declare more functions "noreturn"

[-Wmissing-noreturn]

* Make CAMLassert compliant with ISO C

In `e1 ? e2 : e3`, expressions `e2` and `e3` must have the same type.
`e2` of type `void` and `e3` of type `int`, as in the original code,
is a GNU extension.

* Remove or conditionalize unused macros

Some macros were defined and never used.
Some other macros were always defined but conditionally used.

[-Wunused-macros]

* Replace some uses of `int` by more appropriate types like `intnat`

On a 64-bit platform, `int` is only 32 bits and may not represent correctly
the length of a string or the size of an OCaml heap block.

This commit replaces a number of uses of `int` by other types that
are 64-bit wide on 64-bit architectures, such as `intnat` or `uintnat`
or `size_t` or `mlsize_t`.

Sometimes an `intnat` was used as an `int` and is intended as a Boolean
(0 or 1); then it was replaced by an `int`.

There are many remaining cases where we assign a 64-bit quantity to a
32-bit `int` variable.  Either I believe these cases are safe
(e.g. the 64-bit quantity is the difference between two pointers
within an I/O buffer, something that always fits in 32 bits), or
the code change was not obvious and too risky.

[-Wshorten-64-to-32]

* Put `inline` before return type

`static inline void f(void)` is cleaner than `static void inline f(void)`.

[-Wold-style-declaration]

* Unused assignment to unused parameter

Looks very useless.  [-Wunused-but-set-parameter]
2018-06-07 12:55:09 +02:00
Gabriel Scherer a1bc562d8a makefiles: consistently offer *both* 'allopt' and 'opt.opt' targets
Some makefiles (lex, stdlib, otherlibs) would only offer allopt, while
others (ocamldoc, tools) only offered opt.opt. It is inconvenient to
have to remember which target name to use while going through various
repositories.
2018-06-07 09:54:13 +02:00
ygrek b13819f9a8 Unix: factor out shell
No change entry needed
2018-06-03 20:33:15 -07:00
Gabriel Scherer 15c89485f3
Merge pull request #1723 from stedolan/remove-meta-static
Remove Meta.static_{alloc, free}.
2018-05-28 16:14:52 +02:00
Sébastien Hinderer a2586680a0 Remove the Makefile.nt files 2018-05-25 00:36:56 +02:00
Nicolás Ojeda Bär 76f30d00f3 Unix: add open_process_args{,_in,_out,_full} (#1792)
The idea is to add a variant of the Unix.open_process{,_in,_out,_full} functions that work with a pair (program, args) directly, without going through the system shell, which introduces extra complexity (in particular, with respect to quoting).

I used the name Unix.open_process_args which is the one suggested in ocaml-batteries-team/batteries-included#858, but I am not completely sold on it.

One uses the usual "close" functions Unix.close_process{,_in,_out,_full} with the new functions as well.

The "old" functions Unix.open_process{,_in,_out,_full} are re-implemented in terms of the "new" functions, so I did not feel pressed to add new tests.

Addresses: MPR#7794.
2018-05-24 11:10:36 +02:00
Xavier Leroy ab1ca8e72a
Make sure a function registered with `at_exit` is executed only once (#1790)
Fixes: MPR#7253 (in large part), MPR#7796 (in full).

As shown in the PRs above there are several cases where do_at_exit
is called several times, causing functions registered with at_exit
to be called several times.  Also, an at_exit function that raises
could prevent other at_exit functions from being run.

This commit doesn't try to prevent multiple calls to do_at_exit,
but makes sure that each function registered with at_exit is run
at most once.  The idea is due to Nicolás Ojeda Bär.
2018-05-23 17:12:01 +02:00
Marc Lasson 02e93d657f Fix Segfault on Windows 64 bits
The segfault happens when you use a wildcard '*' or '?'
in the argument of the caml program compiled on Windows
64bits.

The handle was corrupted because is cast from
intptr_t (64bits) to int (32bits).

In order to make sure that both `intptr_t` and `uintptr_t`
are available on MSVC we forced the inclusion of <stdint.h>
for versions that have it (starting from Visual Studio 2010
(MSVC version 1600)). For older versions, the typedefs may be
found in <stddef.h>; therefore we forced the inclusion of this
standard header in config.h.
2018-05-18 12:19:01 +01:00
Mark Shinwell ea2d6a1e31
Add configure options to control installation of source artifacts (#1777) 2018-05-14 08:15:44 +01:00
Gabriel Scherer 559206b4e0 ocamlc -config: new -config-var option to print specific configuration variables
The proposed behavior of `-config-var s` is as follows:
- if `s` is an existing configuration variable, print its value as
  a string and exit with a success return value (0)
- if `s` is not an existing configuration variable, print nothing
  and exit with a failure return value (non-0)

Note that we do not print a newline after the value of the
configuration variable. In particular, if the value is an empty
string, the output is undistinguishable from the output for
non-existing variables, the return value has to be considered instead.

The following alternative behaviors were considered:

- We could print a newline after the configuration value, which
  would let users distinguish empty values from non-existing variables
  by counting the lines of output, and would also be more pleasant for
  users invoking the option from the command-line. However, the way
  bash works on Windows means that $(ocamlc -config-var foo) would keep
  a trailing \r in its output, and portable scripts would have to use
  $(ocamlc -config-var foo | tr -d '\r') instead, which is a pain.
  (This issue was pointed out by David Allsopp)

- We could print a message on the error output if the configuration
  variable does not exist. This is clearer to a human user, but it is
  annoying for scripts if they forget to silence the error output and
  get their output mixed with our error messages. The main use of this
  new feature is for scripting purposes.
2018-04-27 19:54:08 +02:00