ocaml/runtime/caml/sys.h

55 lines
1.7 KiB
C
Raw Normal View History

/**************************************************************************/
/* */
/* OCaml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* en Automatique. */
/* */
/* All rights reserved. This file is distributed under the terms of */
/* the GNU Lesser General Public License version 2.1, with the */
/* special exception on linking described in the file LICENSE. */
/* */
/**************************************************************************/
#ifndef CAML_SYS_H
#define CAML_SYS_H
#ifdef CAML_INTERNALS
#include "misc.h"
#ifdef __cplusplus
extern "C" {
#endif
#define NO_ARG Val_int(0)
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 03:55:09 -07:00
CAMLnoreturn_start
CAMLextern void caml_sys_error (value)
CAMLnoreturn_end;
CAMLnoreturn_start
CAMLextern void caml_sys_io_error (value)
CAMLnoreturn_end;
CAMLextern double caml_sys_time_unboxed(value);
2017-09-21 03:29:03 -07:00
CAMLextern void caml_sys_init (char_os * exe_name, char_os ** argv);
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 03:55:09 -07:00
CAMLnoreturn_start
CAMLextern value caml_sys_exit (value)
CAMLnoreturn_end;
CAMLextern value caml_sys_get_argv(value unit);
2017-09-21 03:29:03 -07:00
extern char_os * caml_exe_name;
#ifdef __cplusplus
}
#endif
#endif /* CAML_INTERNALS */
#endif /* CAML_SYS_H */