Skip to content

Commit 8292e3d

Browse files
authored
Merge pull request #1007 from MisterDA/const
Constify C constructors and flags tables
2 parents 0e231d4 + 98607c4 commit 8292e3d

15 files changed

+34
-33
lines changed

src/unix/lwt_unix_stubs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,11 @@ static void lwt_unix_socketpair(int domain, int type, int protocol,
465465
uerror("socketpair", Nothing);
466466
}
467467

468-
static int socket_domain_table[] = {PF_UNIX, PF_INET, PF_INET6};
468+
static const int socket_domain_table[] =
469+
{PF_UNIX, PF_INET, PF_INET6};
469470

470-
static int socket_type_table[] = {SOCK_STREAM, SOCK_DGRAM, SOCK_RAW,
471-
SOCK_SEQPACKET};
471+
static const int socket_type_table[] =
472+
{SOCK_STREAM, SOCK_DGRAM, SOCK_RAW, SOCK_SEQPACKET};
472473

473474
CAMLprim value lwt_unix_socketpair_stub(value cloexec, value domain, value type,
474475
value protocol) {

src/unix/unix_c/unix_access_job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
+-----------------------------------------------------------------+ */
3535

3636
/* Table mapping constructors of ocaml type Unix.access_permission to C values. */
37-
static int access_permission_table[] = {
37+
static const int access_permission_table[] = {
3838
/* Constructor R_OK. */
3939
R_OK,
4040
/* Constructor W_OK. */

src/unix/unix_c/unix_getaddrinfo_job.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ struct job_getaddrinfo {
2929
char data[];
3030
};
3131

32-
static value cst_to_constr(int n, int *tbl, int size, int deflt)
32+
static value cst_to_constr(int n, const int *tbl, int size, int deflt)
3333
{
3434
int i;
3535
for (i = 0; i < size; i++)
3636
if (n == tbl[i]) return Val_int(i);
3737
return Val_int(deflt);
3838
}
3939

40-
static value convert_addrinfo(struct addrinfo *a)
40+
static value convert_addrinfo(const struct addrinfo *a)
4141
{
4242
CAMLparam0();
4343
CAMLlocal3(vres, vaddr, vcanonname);

src/unix/unix_c/unix_getnameinfo_job.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ struct job_getnameinfo {
2828
int result;
2929
};
3030

31-
static int getnameinfo_flag_table[] = {NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD,
32-
NI_NUMERICSERV, NI_DGRAM};
31+
static const int getnameinfo_flag_table[] =
32+
{NI_NOFQDN, NI_NUMERICHOST, NI_NAMEREQD, NI_NUMERICSERV, NI_DGRAM};
3333

3434
static void worker_getnameinfo(struct job_getnameinfo *job)
3535
{

src/unix/unix_c/unix_lockf_job.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static void worker_lockf(struct job_lockf *job)
8484

8585
#else
8686

87-
static int lock_command_table[] = {F_ULOCK, F_LOCK, F_TLOCK,
88-
F_TEST, F_LOCK, F_TLOCK};
87+
static const int lock_command_table[] =
88+
{F_ULOCK, F_LOCK, F_TLOCK, F_TEST, F_LOCK, F_TLOCK};
8989

9090
static void worker_lockf(struct job_lockf *job)
9191
{

src/unix/unix_c/unix_lseek_job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
+-----------------------------------------------------------------+ */
3636

3737
/* Table mapping constructors of ocaml type Unix.seek_command to C values. */
38-
static int seek_command_table[] = {
38+
static const int seek_command_table[] = {
3939
/* Constructor SEEK_SET. */
4040
SEEK_SET,
4141
/* Constructor SEEK_CUR. */

src/unix/unix_c/unix_madvise.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <caml/bigarray.h>
1313
#include <sys/mman.h>
1414

15-
static int advise_table[] = {
15+
static const int advise_table[] = {
1616
MADV_NORMAL, MADV_RANDOM, MADV_SEQUENTIAL, MADV_WILLNEED, MADV_DONTNEED,
1717
#if defined(MADV_MERGEABLE)
1818
MADV_MERGEABLE,

src/unix/unix_c/unix_open_job.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#define caml_unix_cloexec_default unix_cloexec_default
3636
#endif
3737

38-
static int open_flag_table[] = {
38+
static const int open_flag_table[] = {
3939
O_RDONLY, O_WRONLY, O_RDWR, O_NONBLOCK, O_APPEND, O_CREAT, O_TRUNC,
4040
O_EXCL, O_NOCTTY, O_DSYNC, O_SYNC, O_RSYNC, 0, /* O_SHARE_DELETE,
4141
Windows-only */

src/unix/unix_c/unix_recv_send_utils.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include "unix_recv_send_utils.h"
2121

22-
int msg_flag_table[3] = {MSG_OOB, MSG_DONTROUTE, MSG_PEEK};
22+
const int msg_flag_table[3] = {MSG_OOB, MSG_DONTROUTE, MSG_PEEK};
2323

2424
value wrapper_recv_msg(int fd, int n_iovs, struct iovec *iovs)
2525
{

src/unix/unix_c/unix_recv_send_utils.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,15 @@
3636
#define caml_unix_socket_type_table socket_type_table
3737
#endif
3838

39-
extern int msg_flag_table[];
39+
#if OCAML_VERSION < 50300
4040
extern int caml_unix_socket_domain_table[];
4141
extern int caml_unix_socket_type_table[];
42+
#else
43+
extern const int caml_unix_socket_domain_table[];
44+
extern const int caml_unix_socket_type_table[];
45+
#endif
46+
47+
extern const int msg_flag_table[];
4248
extern void get_sockaddr(value mladdr, union sock_addr_union *addr /*out*/,
4349
socklen_t *addr_len /*out*/);
4450
value wrapper_recv_msg(int fd, int n_iovs, struct iovec *iovs);

0 commit comments

Comments
 (0)