summaryrefslogtreecommitdiff
path: root/otherlibs
diff options
context:
space:
mode:
authoryallop <yallop@gmail.com>2017-08-03 14:19:13 +0100
committerMark Shinwell <mshinwell@gmail.com>2017-08-03 14:19:13 +0100
commit65c932253b96651a6d13550a48dd386a89244ed0 (patch)
treee06098840d29e15d888c28e7c40238743cb65f7a /otherlibs
parent3d1a0fba2f64ad82bc3961311d85d8b7f6c48f06 (diff)
downloadocaml-65c932253b96651a6d13550a48dd386a89244ed0.tar.gz
String_val: return 'const char *' when -safe-string is globally enabled (#1274)
Diffstat (limited to 'otherlibs')
-rw-r--r--otherlibs/graph/libgraph.h2
-rw-r--r--otherlibs/graph/open.c5
-rw-r--r--otherlibs/graph/text.c4
-rw-r--r--otherlibs/str/strstubs.c11
-rw-r--r--otherlibs/unix/cstringv.c2
-rw-r--r--otherlibs/unix/execvp.c4
-rw-r--r--otherlibs/unix/socketaddr.c9
-rw-r--r--otherlibs/unix/unixsupport.c6
-rw-r--r--otherlibs/unix/unixsupport.h6
-rw-r--r--otherlibs/win32unix/unixsupport.c6
-rw-r--r--otherlibs/win32unix/unixsupport.h6
11 files changed, 30 insertions, 31 deletions
diff --git a/otherlibs/graph/libgraph.h b/otherlibs/graph/libgraph.h
index 5eb397af58..e2dcb2bf2a 100644
--- a/otherlibs/graph/libgraph.h
+++ b/otherlibs/graph/libgraph.h
@@ -77,7 +77,7 @@ extern int caml_gr_bits_per_pixel;
#endif
CAMLnoreturn_start
-extern void caml_gr_fail(char *fmt, char *arg)
+extern void caml_gr_fail(const char *fmt, const char *arg)
CAMLnoreturn_end;
extern void caml_gr_check_open(void);
diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c
index 890b8713ef..10a0c4ad76 100644
--- a/otherlibs/graph/open.c
+++ b/otherlibs/graph/open.c
@@ -51,7 +51,8 @@ value caml_gr_clear_graph(void);
value caml_gr_open_graph(value arg)
{
char display_name[256], geometry_spec[64];
- char * p, * q;
+ const char * p;
+ char * q;
XSizeHints hints;
int ret;
XEvent event;
@@ -366,7 +367,7 @@ value caml_gr_sigio_handler(void)
static value * graphic_failure_exn = NULL;
-void caml_gr_fail(char *fmt, char *arg)
+void caml_gr_fail(const char *fmt, const char *arg)
{
char buffer[1024];
diff --git a/otherlibs/graph/text.c b/otherlibs/graph/text.c
index 7328967d95..d98c884e06 100644
--- a/otherlibs/graph/text.c
+++ b/otherlibs/graph/text.c
@@ -18,7 +18,7 @@
XFontStruct * caml_gr_font = NULL;
-static void caml_gr_get_font(char *fontname)
+static void caml_gr_get_font(const char *fontname)
{
XFontStruct * font = XLoadQueryFont(caml_gr_display, fontname);
if (font == NULL) caml_gr_fail("cannot find font %s", fontname);
@@ -40,7 +40,7 @@ value caml_gr_set_text_size (value sz)
return Val_unit;
}
-static void caml_gr_draw_text(char *txt, int len)
+static void caml_gr_draw_text(const char *txt, int len)
{
if (caml_gr_font == NULL) caml_gr_get_font(DEFAULT_FONT);
if (caml_gr_remember_modeflag)
diff --git a/otherlibs/str/strstubs.c b/otherlibs/str/strstubs.c
index 505b927ed4..51d7b79687 100644
--- a/otherlibs/str/strstubs.c
+++ b/otherlibs/str/strstubs.c
@@ -286,18 +286,18 @@ static value re_match(value re,
case ACCEPT:
goto accept;
case SIMPLEOPT: {
- char * set = String_val(Field(cpool, Arg(instr)));
+ const char * set = String_val(Field(cpool, Arg(instr)));
if (txt < endtxt && In_bitset(set, *txt, c)) txt++;
break;
}
case SIMPLESTAR: {
- char * set = String_val(Field(cpool, Arg(instr)));
+ const char * set = String_val(Field(cpool, Arg(instr)));
while (txt < endtxt && In_bitset(set, *txt, c))
txt++;
break;
}
case SIMPLEPLUS: {
- char * set = String_val(Field(cpool, Arg(instr)));
+ const char * set = String_val(Field(cpool, Arg(instr)));
if (txt == endtxt) goto prefix_match;
if (! In_bitset(set, *txt, c)) goto backtrack;
txt++;
@@ -483,7 +483,8 @@ CAMLprim value re_replacement_text(value repl, value groups, value orig)
CAMLparam3(repl, groups, orig);
CAMLlocal1(res);
mlsize_t start, end, len, n;
- char * p, * q;
+ const char * p;
+ char * q;
int c;
len = 0;
@@ -517,7 +518,7 @@ CAMLprim value re_replacement_text(value repl, value groups, value orig)
}
res = caml_alloc_string(len);
p = String_val(repl);
- q = String_val(res);
+ q = (char *)String_val(res);
n = caml_string_length(repl);
while (n > 0) {
c = *p++; n--;
diff --git a/otherlibs/unix/cstringv.c b/otherlibs/unix/cstringv.c
index 68441cfaa6..c5a89e6c3b 100644
--- a/otherlibs/unix/cstringv.c
+++ b/otherlibs/unix/cstringv.c
@@ -28,7 +28,7 @@ char ** cstringvect(value arg, char * cmdname)
if (! caml_string_is_c_safe(Field(arg, i)))
unix_error(EINVAL, cmdname, Field(arg, i));
res = (char **) caml_stat_alloc((size + 1) * sizeof(char *));
- for (i = 0; i < size; i++) res[i] = String_val(Field(arg, i));
+ for (i = 0; i < size; i++) res[i] = (char *)String_val(Field(arg, i));
res[size] = NULL;
return res;
}
diff --git a/otherlibs/unix/execvp.c b/otherlibs/unix/execvp.c
index d521adcff7..6de0c06ee5 100644
--- a/otherlibs/unix/execvp.c
+++ b/otherlibs/unix/execvp.c
@@ -37,7 +37,7 @@ CAMLprim value unix_execvp(value path, value args)
CAMLprim value unix_execvpe(value path, value args, value env)
{
- char * exefile;
+ const char * exefile;
char ** argv;
char ** envp;
caml_unix_check_path(path, "execvpe");
@@ -45,7 +45,7 @@ CAMLprim value unix_execvpe(value path, value args, value env)
argv = cstringvect(args, "execvpe");
envp = cstringvect(env, "execvpe");
(void) execve(exefile, argv, envp);
- caml_stat_free(exefile);
+ caml_stat_free((char *)exefile);
caml_stat_free((char *) argv);
caml_stat_free((char *) envp);
uerror("execvpe", path);
diff --git a/otherlibs/unix/socketaddr.c b/otherlibs/unix/socketaddr.c
index 5f64021f31..69fc52cc22 100644
--- a/otherlibs/unix/socketaddr.c
+++ b/otherlibs/unix/socketaddr.c
@@ -35,8 +35,7 @@ CAMLexport value alloc_inet_addr(struct in_addr * a)
/* Use a string rather than an abstract block so that it can be
marshaled safely. Remember that a is in network byte order,
hence is marshaled in an endian-independent manner. */
- res = caml_alloc_string(4);
- memcpy(String_val(res), a, 4);
+ res = caml_alloc_initialized_string(4, (char *)a);
return res;
}
@@ -45,8 +44,7 @@ CAMLexport value alloc_inet_addr(struct in_addr * a)
CAMLexport value alloc_inet6_addr(struct in6_addr * a)
{
value res;
- res = caml_alloc_string(16);
- memcpy(String_val(res), a, 16);
+ res = caml_alloc_initialized_string(16, (char *)a);
return res;
}
@@ -117,8 +115,7 @@ value alloc_sockaddr(union sock_addr_union * adr /*in*/,
mlsize_t path_length =
strnlen(adr->s_unix.sun_path,
adr_len - offsetof(struct sockaddr_un, sun_path));
- n = caml_alloc_string(path_length);
- memmove(String_val(n), adr->s_unix.sun_path, path_length);
+ n = caml_alloc_initialized_string(path_length, (char *)adr->s_unix.sun_path);
Begin_root (n);
res = caml_alloc_small(1, 0);
Field(res,0) = n;
diff --git a/otherlibs/unix/unixsupport.c b/otherlibs/unix/unixsupport.c
index b3ff8a4bf8..9bbb9343d6 100644
--- a/otherlibs/unix/unixsupport.c
+++ b/otherlibs/unix/unixsupport.c
@@ -285,7 +285,7 @@ extern int code_of_unix_error (value error)
}
}
-void unix_error(int errcode, char *cmdname, value cmdarg)
+void unix_error(int errcode, const char *cmdname, value cmdarg)
{
value res;
value name = Val_unit, err = Val_unit, arg = Val_unit;
@@ -309,12 +309,12 @@ void unix_error(int errcode, char *cmdname, value cmdarg)
caml_raise(res);
}
-void uerror(char *cmdname, value cmdarg)
+void uerror(const char *cmdname, value cmdarg)
{
unix_error(errno, cmdname, cmdarg);
}
-void caml_unix_check_path(value path, char * cmdname)
+void caml_unix_check_path(value path, const char * cmdname)
{
if (! caml_string_is_c_safe(path)) unix_error(ENOENT, cmdname, path);
}
diff --git a/otherlibs/unix/unixsupport.h b/otherlibs/unix/unixsupport.h
index 41698e648f..7098d5440c 100644
--- a/otherlibs/unix/unixsupport.h
+++ b/otherlibs/unix/unixsupport.h
@@ -30,14 +30,14 @@ extern value unix_error_of_code (int errcode);
extern int code_of_unix_error (value error);
CAMLnoreturn_start
-extern void unix_error (int errcode, char * cmdname, value arg)
+extern void unix_error (int errcode, const char * cmdname, value arg)
CAMLnoreturn_end;
CAMLnoreturn_start
-extern void uerror (char * cmdname, value arg)
+extern void uerror (const char * cmdname, value arg)
CAMLnoreturn_end;
-extern void caml_unix_check_path(value path, char * cmdname);
+extern void caml_unix_check_path(value path, const char * cmdname);
#define UNIX_BUFFER_SIZE 65536
diff --git a/otherlibs/win32unix/unixsupport.c b/otherlibs/win32unix/unixsupport.c
index ced62fd821..4ed2383b3b 100644
--- a/otherlibs/win32unix/unixsupport.c
+++ b/otherlibs/win32unix/unixsupport.c
@@ -280,7 +280,7 @@ value unix_error_of_code (int errcode)
return err;
}
-void unix_error(int errcode, char *cmdname, value cmdarg)
+void unix_error(int errcode, const char *cmdname, value cmdarg)
{
value res;
value name = Val_unit, err = Val_unit, arg = Val_unit;
@@ -305,12 +305,12 @@ void unix_error(int errcode, char *cmdname, value cmdarg)
caml_raise(res);
}
-void uerror(char * cmdname, value cmdarg)
+void uerror(const char * cmdname, value cmdarg)
{
unix_error(errno, cmdname, cmdarg);
}
-void caml_unix_check_path(value path, char * cmdname)
+void caml_unix_check_path(value path, const char * cmdname)
{
if (! caml_string_is_c_safe(path)) unix_error(ENOENT, cmdname, path);
}
diff --git a/otherlibs/win32unix/unixsupport.h b/otherlibs/win32unix/unixsupport.h
index 139e179c32..55e5887620 100644
--- a/otherlibs/win32unix/unixsupport.h
+++ b/otherlibs/win32unix/unixsupport.h
@@ -61,14 +61,14 @@ extern void win32_maperr(DWORD errcode);
extern value unix_error_of_code (int errcode);
CAMLnoreturn_start
-extern void unix_error (int errcode, char * cmdname, value arg)
+extern void unix_error (int errcode, const char * cmdname, value arg)
CAMLnoreturn_end;
CAMLnoreturn_start
-extern void uerror (char * cmdname, value arg)
+extern void uerror (const char * cmdname, value arg)
CAMLnoreturn_end;
-extern void caml_unix_check_path(value path, char * cmdname);
+extern void caml_unix_check_path(value path, const char * cmdname);
extern value unix_freeze_buffer (value);
extern char ** cstringvect(value arg, char * cmdname);