diff options
author | Antonin Décimo <antonin@tarides.com> | 2023-05-08 18:05:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-08 19:05:39 +0200 |
commit | d7ced7e6b0ac2b03fda7b0bcc29c46fef26f71c9 (patch) | |
tree | 57ac1d372e882d477d8c2133c7656c54b74f0765 | |
parent | 683d0ca1de0b8bea7ae9e62cc2415a576b6e35b8 (diff) | |
download | ocaml-d7ced7e6b0ac2b03fda7b0bcc29c46fef26f71c9.tar.gz |
Constify C constructors and flags tables (#12223)
-rw-r--r-- | Changes | 4 | ||||
-rw-r--r-- | otherlibs/unix/access.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/cst2constr.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/cst2constr.h | 3 | ||||
-rw-r--r-- | otherlibs/unix/getnameinfo.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/lockf_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/lseek_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/open_unix.c | 4 | ||||
-rw-r--r-- | otherlibs/unix/open_win32.c | 8 | ||||
-rw-r--r-- | otherlibs/unix/sendrecv_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/sendrecv_win32.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/shutdown_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/shutdown_win32.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/stat_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/stat_win32.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/termios.c | 6 | ||||
-rw-r--r-- | otherlibs/unix/unixsupport_unix.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/unixsupport_win32.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/wait.c | 2 | ||||
-rw-r--r-- | otherlibs/unix/winwait.c | 2 | ||||
-rw-r--r-- | runtime/extern.c | 2 | ||||
-rw-r--r-- | runtime/signals.c | 2 |
22 files changed, 32 insertions, 27 deletions
@@ -10,6 +10,10 @@ Working version of `caml_read_directory`. Also, check for overflows in ext table sizes. (Xavier Leroy, report by Arseniy Alekseyev, review by Gabriel Scherer) +- #12223: Constify constructors and flags tables in C code. Now these + tables will go in the readonly segment, where they belong. + (Antonin Décimo, review by Gabriel Scherer and Xavier Leroy) + ### Code generation and optimizations: ### Standard library: diff --git a/otherlibs/unix/access.c b/otherlibs/unix/access.c index 0f7b3b3daf..48d95f7acb 100644 --- a/otherlibs/unix/access.c +++ b/otherlibs/unix/access.c @@ -35,7 +35,7 @@ # endif #endif -static int access_permission_table[] = { +static const int access_permission_table[] = { R_OK, W_OK, #ifdef _WIN32 diff --git a/otherlibs/unix/cst2constr.c b/otherlibs/unix/cst2constr.c index eab427e0b2..7bade04709 100644 --- a/otherlibs/unix/cst2constr.c +++ b/otherlibs/unix/cst2constr.c @@ -17,7 +17,7 @@ #include <caml/fail.h> #include "cst2constr.h" -value caml_unix_cst_to_constr(int n, int *tbl, int size, int deflt) +value caml_unix_cst_to_constr(int n, const int *tbl, int size, int deflt) { int i; for (i = 0; i < size; i++) diff --git a/otherlibs/unix/cst2constr.h b/otherlibs/unix/cst2constr.h index 075b6d4d2a..324d617f50 100644 --- a/otherlibs/unix/cst2constr.h +++ b/otherlibs/unix/cst2constr.h @@ -13,4 +13,5 @@ /* */ /**************************************************************************/ -extern value caml_unix_cst_to_constr(int n, int * tbl, int size, int deflt); +extern value caml_unix_cst_to_constr(int n, const int * tbl, int size, + int deflt); diff --git a/otherlibs/unix/getnameinfo.c b/otherlibs/unix/getnameinfo.c index bc7be72463..304c2576e2 100644 --- a/otherlibs/unix/getnameinfo.c +++ b/otherlibs/unix/getnameinfo.c @@ -29,7 +29,7 @@ #include <netdb.h> #endif -static int getnameinfo_flag_table[] = { +static const int getnameinfo_flag_table[] = { NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD, NI_NUMERICSERV, NI_DGRAM }; diff --git a/otherlibs/unix/lockf_unix.c b/otherlibs/unix/lockf_unix.c index 43796c71a2..371e26fad2 100644 --- a/otherlibs/unix/lockf_unix.c +++ b/otherlibs/unix/lockf_unix.c @@ -96,7 +96,7 @@ CAMLprim value caml_unix_lockf(value fd, value cmd, value span) #define F_TEST 3 #endif -static int lock_command_table[] = { +static const int lock_command_table[] = { F_ULOCK, F_LOCK, F_TLOCK, F_TEST, F_LOCK, F_TLOCK }; diff --git a/otherlibs/unix/lseek_unix.c b/otherlibs/unix/lseek_unix.c index 2264c3b969..99f2fccbd8 100644 --- a/otherlibs/unix/lseek_unix.c +++ b/otherlibs/unix/lseek_unix.c @@ -35,7 +35,7 @@ #define EOVERFLOW ERANGE #endif -static int seek_command_table[] = { +static const int seek_command_table[] = { SEEK_SET, SEEK_CUR, SEEK_END }; diff --git a/otherlibs/unix/open_unix.c b/otherlibs/unix/open_unix.c index b527d8907e..41a566395a 100644 --- a/otherlibs/unix/open_unix.c +++ b/otherlibs/unix/open_unix.c @@ -38,7 +38,7 @@ #define O_RSYNC 0 #endif -static int open_flag_table[15] = { +static const int open_flag_table[15] = { O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC, O_EXCL, O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0, /* O_SHARE_DELETE, Windows-only */ @@ -48,7 +48,7 @@ static int open_flag_table[15] = { enum { CLOEXEC = 1, KEEPEXEC = 2 }; -static int open_cloexec_table[15] = { +static const int open_cloexec_table[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/otherlibs/unix/open_win32.c b/otherlibs/unix/open_win32.c index b4e02aefe9..6d545769f7 100644 --- a/otherlibs/unix/open_win32.c +++ b/otherlibs/unix/open_win32.c @@ -22,22 +22,22 @@ #include "unixsupport.h" #include <fcntl.h> -static int open_access_flags[15] = { +static const int open_access_flags[15] = { GENERIC_READ, GENERIC_WRITE, GENERIC_READ|GENERIC_WRITE, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; -static int open_create_flags[15] = { +static const int open_create_flags[15] = { 0, 0, 0, 0, 0, O_CREAT, O_TRUNC, O_EXCL, 0, 0, 0, 0, 0, 0, 0 }; -static int open_share_flags[15] = { +static const int open_share_flags[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FILE_SHARE_DELETE, 0, 0 }; enum { CLOEXEC = 1, KEEPEXEC = 2 }; -static int open_cloexec_flags[15] = { +static const int open_cloexec_flags[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, CLOEXEC, KEEPEXEC }; diff --git a/otherlibs/unix/sendrecv_unix.c b/otherlibs/unix/sendrecv_unix.c index 5ed785816c..46122888aa 100644 --- a/otherlibs/unix/sendrecv_unix.c +++ b/otherlibs/unix/sendrecv_unix.c @@ -24,7 +24,7 @@ #ifdef HAS_SOCKETS #include "socketaddr.h" -static int msg_flag_table[] = { +static const int msg_flag_table[] = { MSG_OOB, MSG_DONTROUTE, MSG_PEEK }; diff --git a/otherlibs/unix/sendrecv_win32.c b/otherlibs/unix/sendrecv_win32.c index 699babd9ca..1fc41d7098 100644 --- a/otherlibs/unix/sendrecv_win32.c +++ b/otherlibs/unix/sendrecv_win32.c @@ -20,7 +20,7 @@ #include "unixsupport.h" #include "socketaddr.h" -static int msg_flag_table[] = { +static const int msg_flag_table[] = { MSG_OOB, MSG_DONTROUTE, MSG_PEEK }; diff --git a/otherlibs/unix/shutdown_unix.c b/otherlibs/unix/shutdown_unix.c index 8c750e2479..898eebbb2d 100644 --- a/otherlibs/unix/shutdown_unix.c +++ b/otherlibs/unix/shutdown_unix.c @@ -21,7 +21,7 @@ #include <sys/socket.h> -static int shutdown_command_table[] = { +static const int shutdown_command_table[] = { 0, 1, 2 }; diff --git a/otherlibs/unix/shutdown_win32.c b/otherlibs/unix/shutdown_win32.c index a5f1d8c011..9bb0b3ed6b 100644 --- a/otherlibs/unix/shutdown_win32.c +++ b/otherlibs/unix/shutdown_win32.c @@ -16,7 +16,7 @@ #include <caml/mlvalues.h> #include "unixsupport.h" -static int shutdown_command_table[] = { +static const int shutdown_command_table[] = { 0, 1, 2 }; diff --git a/otherlibs/unix/stat_unix.c b/otherlibs/unix/stat_unix.c index 31b166fc65..3b28ef8409 100644 --- a/otherlibs/unix/stat_unix.c +++ b/otherlibs/unix/stat_unix.c @@ -44,7 +44,7 @@ #define EOVERFLOW ERANGE #endif -static int file_kind_table[] = { +static const int file_kind_table[] = { S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFLNK, S_IFIFO, S_IFSOCK }; diff --git a/otherlibs/unix/stat_win32.c b/otherlibs/unix/stat_win32.c index 197e4340d6..7f7b17e708 100644 --- a/otherlibs/unix/stat_win32.c +++ b/otherlibs/unix/stat_win32.c @@ -59,7 +59,7 @@ #define S_IFBLK 0 #endif -static int file_kind_table[] = { +static const int file_kind_table[] = { S_IFREG, S_IFDIR, S_IFCHR, S_IFBLK, S_IFLNK, S_IFIFO, S_IFSOCK }; diff --git a/otherlibs/unix/termios.c b/otherlibs/unix/termios.c index f41af150c7..b92ae42661 100644 --- a/otherlibs/unix/termios.c +++ b/otherlibs/unix/termios.c @@ -307,7 +307,7 @@ CAMLprim value caml_unix_tcgetattr(value fd) return res; } -static int when_flag_table[] = { +static const int when_flag_table[] = { TCSANOW, TCSADRAIN, TCSAFLUSH }; @@ -346,7 +346,7 @@ CAMLprim value caml_unix_tcdrain(value fd) } #endif -static int queue_flag_table[] = { +static const int queue_flag_table[] = { TCIFLUSH, TCOFLUSH, TCIOFLUSH }; @@ -357,7 +357,7 @@ CAMLprim value caml_unix_tcflush(value fd, value queue) return Val_unit; } -static int action_flag_table[] = { +static const int action_flag_table[] = { TCOOFF, TCOON, TCIOFF, TCION }; diff --git a/otherlibs/unix/unixsupport_unix.c b/otherlibs/unix/unixsupport_unix.c index 449af8b5c2..0d50e246b2 100644 --- a/otherlibs/unix/unixsupport_unix.c +++ b/otherlibs/unix/unixsupport_unix.c @@ -242,7 +242,7 @@ #define EOVERFLOW (-1) #endif -static int error_table[] = { +static const int error_table[] = { E2BIG, EACCES, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM, EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK, ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC, diff --git a/otherlibs/unix/unixsupport_win32.c b/otherlibs/unix/unixsupport_win32.c index cb5eb35df7..509afa3ea3 100644 --- a/otherlibs/unix/unixsupport_win32.c +++ b/otherlibs/unix/unixsupport_win32.c @@ -251,7 +251,7 @@ void caml_win32_maperr(DWORD errcode) #undef EACCESS #define EACCESS EACCES -static int error_table[] = { +static const int error_table[] = { E2BIG, EACCESS, EAGAIN, EBADF, EBUSY, ECHILD, EDEADLK, EDOM, EEXIST, EFAULT, EFBIG, EINTR, EINVAL, EIO, EISDIR, EMFILE, EMLINK, ENAMETOOLONG, ENFILE, ENODEV, ENOENT, ENOEXEC, ENOLCK, ENOMEM, ENOSPC, diff --git a/otherlibs/unix/wait.c b/otherlibs/unix/wait.c index 3509c76b98..b5aa0516bd 100644 --- a/otherlibs/unix/wait.c +++ b/otherlibs/unix/wait.c @@ -83,7 +83,7 @@ CAMLprim value caml_unix_wait(value unit) #define waitpid(pid,status,opts) wait4(pid,status,opts,NULL) #endif -static int wait_flag_table[] = { +static const int wait_flag_table[] = { WNOHANG, WUNTRACED }; diff --git a/otherlibs/unix/winwait.c b/otherlibs/unix/winwait.c index 2d28117af4..69ac8dd668 100644 --- a/otherlibs/unix/winwait.c +++ b/otherlibs/unix/winwait.c @@ -36,7 +36,7 @@ static value alloc_process_status(HANDLE pid, int status) enum { CAML_WNOHANG = 1, CAML_WUNTRACED = 2 }; -static int wait_flag_table[] = { CAML_WNOHANG, CAML_WUNTRACED }; +static const int wait_flag_table[] = { CAML_WNOHANG, CAML_WUNTRACED }; CAMLprim value caml_unix_waitpid(value vflags, value vpid_req) { diff --git a/runtime/extern.c b/runtime/extern.c index 4301c3df13..7b5b81379b 100644 --- a/runtime/extern.c +++ b/runtime/extern.c @@ -991,7 +991,7 @@ oom1: #endif -static int extern_flag_values[] = { +static const int extern_flag_values[] = { NO_SHARING, CLOSURES, COMPAT_32, COMPRESSED }; diff --git a/runtime/signals.c b/runtime/signals.c index 5a21024ad4..8abdf346b1 100644 --- a/runtime/signals.c +++ b/runtime/signals.c @@ -445,7 +445,7 @@ CAMLexport void caml_process_pending_actions(void) #define SIGXFSZ -1 #endif -static int posix_signals[] = { +static const int posix_signals[] = { SIGABRT, SIGALRM, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGUSR1, SIGUSR2, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGVTALRM, SIGPROF, SIGBUS, |