diff options
author | Max Mouratov <mmouratov@gmail.com> | 2016-01-05 22:39:12 +0500 |
---|---|---|
committer | Max Mouratov <mmouratov@gmail.com> | 2017-03-17 20:50:16 +0500 |
commit | b8c9e064dfa0832c3dadec3c72087a40ecbd886e (patch) | |
tree | 11ac7fc9134f4402ec59b8e00a87dee490c6c295 | |
parent | 64fe0a5f36a4f3a3c94ac1986e7a4e8b879df2a6 (diff) | |
download | ocaml-b8c9e064dfa0832c3dadec3c72087a40ecbd886e.tar.gz |
runtime: deprecation of caml_strdup, caml_strconcat
For consistency with caml_stat_* functions, caml_strdup and caml_strconcat
were deprecated and replaced with caml_stat_strdup and caml_stat_strconcat.
35 files changed, 133 insertions, 123 deletions
diff --git a/asmrun/natdynlink.c b/asmrun/natdynlink.c index e2599e65fb..74dad7c858 100644 --- a/asmrun/natdynlink.c +++ b/asmrun/natdynlink.c @@ -45,7 +45,7 @@ static value Val_handle(void* handle) { } static void *getsym(void *handle, char *module, char *name){ - char *fullname = caml_strconcat(3, "caml", module, name); + char *fullname = caml_stat_strconcat(3, "caml", module, name); void *sym; sym = caml_dlsym (handle, fullname); /* printf("%s => %lx\n", fullname, (uintnat) sym); */ @@ -73,7 +73,7 @@ CAMLprim value caml_natdynlink_open(value filename, value global) /* TODO: dlclose in case of error... */ - p = caml_strdup(String_val(filename)); + p = caml_stat_strdup(String_val(filename)); caml_enter_blocking_section(); dlhandle = caml_dlopen(p, 1, Int_val(global)); caml_leave_blocking_section(); @@ -155,7 +155,7 @@ CAMLprim value caml_natdynlink_run_toplevel(value filename, value symbol) /* TODO: dlclose in case of error... */ - p = caml_strdup(String_val(filename)); + p = caml_stat_strdup(String_val(filename)); caml_enter_blocking_section(); handle = caml_dlopen(p, 1, 1); caml_leave_blocking_section(); diff --git a/byterun/caml/memory.h b/byterun/caml/memory.h index 0c8fb607dd..0398d49acd 100644 --- a/byterun/caml/memory.h +++ b/byterun/caml/memory.h @@ -79,6 +79,9 @@ CAMLextern void * caml_stat_resize (void *, asize_t); CAMLextern void * caml_stat_alloc_aligned (asize_t bsize, int module, void **block); +CAMLextern char * caml_stat_strdup(const char *s); +CAMLextern char * caml_stat_strconcat(int n, ...); /* n args of char* */ + /* These functions do not throw an OCaml exception in case of errors (direct substitutions for malloc, calloc, realloc). */ @@ -88,6 +91,7 @@ CAMLextern void * caml_stat_alloc_aligned_noexc (asize_t bsize, void **block); CAMLextern void * caml_stat_calloc_noexc (asize_t, asize_t); CAMLextern void * caml_stat_resize_noexc (void *, asize_t); +CAMLextern char * caml_stat_strdup_noexc(const char *s); /* void caml_shrink_heap (char *); Only used in compact.c */ diff --git a/byterun/caml/misc.h b/byterun/caml/misc.h index 75b00a1bd9..0cf07aa460 100644 --- a/byterun/caml/misc.h +++ b/byterun/caml/misc.h @@ -119,18 +119,13 @@ CAMLextern void caml_fatal_error_arg2 (char *fmt1, char *arg1, char *fmt2, char *arg2) CAMLnoreturn_end; -/* Safe string operations */ - -CAMLextern char * caml_strdup(const char * s); -CAMLextern char * caml_strconcat(int n, ...); /* n args of const char * type */ - /* Detection of available C built-in functions, the Clang way. */ #ifdef __has_builtin #define Caml_has_builtin(x) __has_builtin(x) #else #define Caml_has_builtin(x) 0 -#endif +#endif /* Integer arithmetic with overflow detection. The functions return 0 if no overflow, 1 if overflow. @@ -149,7 +144,7 @@ static inline int caml_uadd_overflow(uintnat a, uintnat b, uintnat * res) return c < a; #endif } - + static inline int caml_usub_overflow(uintnat a, uintnat b, uintnat * res) { #if __GNUC__ >= 5 || Caml_has_builtin(__builtin_sub_overflow) @@ -160,7 +155,7 @@ static inline int caml_usub_overflow(uintnat a, uintnat b, uintnat * res) return a < b; #endif } - + #if __GNUC__ >= 5 || Caml_has_builtin(__builtin_mul_overflow) static inline int caml_umul_overflow(uintnat a, uintnat b, uintnat * res) { @@ -168,7 +163,7 @@ static inline int caml_umul_overflow(uintnat a, uintnat b, uintnat * res) } #else extern int caml_umul_overflow(uintnat a, uintnat b, uintnat * res); -#endif +#endif /* Use macros for some system calls being called from OCaml itself. These calls can be either traced for security reasons, or changed to @@ -297,10 +292,10 @@ void caml_gc_message (int, char *, uintnat); extern uintnat caml_runtime_warnings; int caml_runtime_warnings_active(void); -/* Memory routines */ - -/* A deprecated alias */ +/* Deprecated aliases */ #define caml_aligned_malloc caml_stat_alloc_aligned_noexc +#define caml_strdup caml_stat_strdup +#define caml_strconcat caml_stat_strconcat #ifdef DEBUG #ifdef ARCH_SIXTYFOUR diff --git a/byterun/dynlink.c b/byterun/dynlink.c index 7f8a78465a..0ecbf884c4 100644 --- a/byterun/dynlink.c +++ b/byterun/dynlink.c @@ -84,7 +84,7 @@ static char * parse_ld_conf(void) stdlib = getenv("OCAMLLIB"); if (stdlib == NULL) stdlib = getenv("CAMLLIB"); if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR; - ldconfname = caml_strconcat(3, stdlib, "/", LD_CONF_NAME); + ldconfname = caml_stat_strconcat(3, stdlib, "/", LD_CONF_NAME); if (stat(ldconfname, &st) == -1) { caml_stat_free(ldconfname); return NULL; @@ -171,7 +171,7 @@ void caml_build_primitive_table(char * lib_path, caml_fatal_error_arg("Fatal error: unknown C primitive `%s'\n", p); caml_ext_table_add(&caml_prim_table, (void *) prim); #ifdef DEBUG - caml_ext_table_add(&caml_prim_name_table, caml_strdup(p)); + caml_ext_table_add(&caml_prim_name_table, caml_stat_strdup(p)); #endif } /* Clean up */ @@ -194,7 +194,7 @@ void caml_build_primitive_table_builtin(void) caml_ext_table_add(&caml_prim_table, (void *) caml_builtin_cprim[i]); #ifdef DEBUG caml_ext_table_add(&caml_prim_name_table, - caml_strdup(caml_names_of_builtin_cprim[i])); + caml_stat_strdup(caml_names_of_builtin_cprim[i])); #endif } } @@ -219,7 +219,7 @@ CAMLprim value caml_dynlink_open_lib(value mode, value filename) caml_gc_message(0x100, "Opening shared library %s\n", (uintnat) String_val(filename)); - p = caml_strdup(String_val(filename)); + p = caml_stat_strdup(String_val(filename)); caml_enter_blocking_section(); handle = caml_dlopen(p, Int_val(mode), 1); caml_leave_blocking_section(); diff --git a/byterun/io.c b/byterun/io.c index 4207762ce5..2cd6816516 100644 --- a/byterun/io.c +++ b/byterun/io.c @@ -474,7 +474,7 @@ CAMLprim value caml_ml_set_channel_name(value vchannel, value vname) struct channel * channel = Channel(vchannel); caml_stat_free(channel->name); if (caml_string_length(vname) > 0) - channel->name = caml_strdup(String_val(vname)); + channel->name = caml_stat_strdup(String_val(vname)); else channel->name = NULL; return Val_unit; diff --git a/byterun/memory.c b/byterun/memory.c index d9c160c193..e90f0c2ac1 100644 --- a/byterun/memory.c +++ b/byterun/memory.c @@ -884,3 +884,51 @@ CAMLexport void* caml_stat_calloc_noexc(asize_t num, asize_t sz) memset(result, 0, sz); return result; } + +CAMLexport char* caml_stat_strdup_noexc(const char *s) +{ + size_t slen = strlen(s); + char *result = caml_stat_alloc_noexc(slen + 1); + if (result == NULL) + return NULL; + memcpy(result, s, slen + 1); + return result; +} + +CAMLexport char* caml_stat_strdup(const char *s) +{ + void *result = caml_stat_strdup_noexc(s); + if (result == NULL) + caml_raise_out_of_memory(); + return result; +} + +CAMLexport char* caml_stat_strconcat(int n, ...) +{ + va_list args; + char *result, *p; + size_t len = 0; + int i; + + va_start(args, n); + for (i = 0; i < n; i++) { + const char *s = va_arg(args, const char*); + len += strlen(s); + } + va_end(args); + + result = caml_stat_alloc(len + 1); + + va_start(args, n); + p = result; + for (i = 0; i < n; i++) { + const char *s = va_arg(args, const char*); + size_t l = strlen(s); + memcpy(p, s, l); + p += l; + } + va_end(args); + + *p = 0; + return result; +} diff --git a/byterun/misc.c b/byterun/misc.c index 690199bf3a..c5efe96112 100644 --- a/byterun/misc.c +++ b/byterun/misc.c @@ -17,7 +17,6 @@ #include <stdio.h> #include <string.h> -#include <stdarg.h> #include "caml/config.h" #include "caml/misc.h" #include "caml/memory.h" @@ -132,42 +131,6 @@ void caml_ext_table_free(struct ext_table * tbl, int free_entries) caml_stat_free(tbl->contents); } -CAMLexport char * caml_strdup(const char * s) -{ - size_t slen = strlen(s); - char * res = caml_stat_alloc(slen + 1); - memcpy(res, s, slen + 1); - return res; -} - -CAMLexport char * caml_strconcat(int n, ...) -{ - va_list args; - char * res, * p; - size_t len; - int i; - - len = 0; - va_start(args, n); - for (i = 0; i < n; i++) { - const char * s = va_arg(args, const char *); - len += strlen(s); - } - va_end(args); - res = caml_stat_alloc(len + 1); - va_start(args, n); - p = res; - for (i = 0; i < n; i++) { - const char * s = va_arg(args, const char *); - size_t l = strlen(s); - memcpy(p, s, l); - p += l; - } - va_end(args); - *p = 0; - return res; -} - /* Integer arithmetic with overflow detection */ #if ! (__GNUC__ >= 5 || Caml_has_builtin(__builtin_mul_overflow)) diff --git a/byterun/startup.c b/byterun/startup.c index 04032f0221..e2e2531a99 100644 --- a/byterun/startup.c +++ b/byterun/startup.c @@ -421,7 +421,7 @@ CAMLexport value caml_startup_code_exn( #endif cds_file = getenv("CAML_DEBUG_FILE"); if (cds_file != NULL) { - caml_cds_file = caml_strdup(cds_file); + caml_cds_file = caml_stat_strdup(cds_file); } caml_parse_ocamlrunparam(); exe_name = caml_executable_name(); diff --git a/byterun/sys.c b/byterun/sys.c index cb6f21a2c7..40bb49f030 100644 --- a/byterun/sys.c +++ b/byterun/sys.c @@ -174,7 +174,7 @@ CAMLprim value caml_sys_open(value path, value vflags, value vperm) char * p; caml_sys_check_path(path); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); flags = caml_convert_flag_list(vflags, sys_open_flags); perm = Int_val(vperm); /* open on a named FIFO can block (PR#1533) */ @@ -211,7 +211,7 @@ CAMLprim value caml_sys_file_exists(value name) int ret; if (! caml_string_is_c_safe(name)) return Val_false; - p = caml_strdup(String_val(name)); + p = caml_stat_strdup(String_val(name)); caml_enter_blocking_section(); #ifdef _WIN32 ret = _stati64(p, &st); @@ -236,7 +236,7 @@ CAMLprim value caml_sys_is_directory(value name) int ret; caml_sys_check_path(name); - p = caml_strdup(String_val(name)); + p = caml_stat_strdup(String_val(name)); caml_enter_blocking_section(); #ifdef _WIN32 ret = _stati64(p, &st); @@ -260,7 +260,7 @@ CAMLprim value caml_sys_remove(value name) char * p; int ret; caml_sys_check_path(name); - p = caml_strdup(String_val(name)); + p = caml_stat_strdup(String_val(name)); caml_enter_blocking_section(); ret = CAML_SYS_UNLINK(p); caml_leave_blocking_section(); @@ -276,8 +276,8 @@ CAMLprim value caml_sys_rename(value oldname, value newname) int ret; caml_sys_check_path(oldname); caml_sys_check_path(newname); - p_old = caml_strdup(String_val(oldname)); - p_new = caml_strdup(String_val(newname)); + p_old = caml_stat_strdup(String_val(oldname)); + p_new = caml_stat_strdup(String_val(newname)); caml_enter_blocking_section(); ret = CAML_SYS_RENAME(p_old, p_new); caml_leave_blocking_section(); @@ -294,7 +294,7 @@ CAMLprim value caml_sys_chdir(value dirname) char * p; int ret; caml_sys_check_path(dirname); - p = caml_strdup(String_val(dirname)); + p = caml_stat_strdup(String_val(dirname)); caml_enter_blocking_section(); ret = CAML_SYS_CHDIR(p); caml_leave_blocking_section(); @@ -369,7 +369,7 @@ CAMLprim value caml_sys_system_command(value command) errno = EINVAL; caml_sys_error(command); } - buf = caml_strdup(String_val(command)); + buf = caml_stat_strdup(String_val(command)); caml_enter_blocking_section (); status = CAML_SYS_SYSTEM(buf); caml_leave_blocking_section (); @@ -557,7 +557,7 @@ CAMLprim value caml_sys_read_directory(value path) caml_sys_check_path(path); caml_ext_table_init(&tbl, 50); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = CAML_SYS_READ_DIRECTORY(p, &tbl); caml_leave_blocking_section(); diff --git a/byterun/unix.c b/byterun/unix.c index 5d59779599..b187ce7f88 100644 --- a/byterun/unix.c +++ b/byterun/unix.c @@ -117,7 +117,7 @@ char * caml_decompose_path(struct ext_table * tbl, char * path) size_t n; if (path == NULL) return NULL; - p = caml_strdup(path); + p = caml_stat_strdup(path); q = p; while (1) { for (n = 0; q[n] != 0 && q[n] != ':'; n++) /*nothing*/; @@ -142,13 +142,13 @@ char * caml_search_in_path(struct ext_table * path, char * name) for (i = 0; i < path->size; i++) { dir = path->contents[i]; if (dir[0] == 0) dir = "."; /* empty path component = current dir */ - fullname = caml_strconcat(3, dir, "/", name); + fullname = caml_stat_strconcat(3, dir, "/", name); if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) return fullname; caml_stat_free(fullname); } not_found: - return caml_strdup(name); + return caml_stat_strdup(name); } #ifdef __CYGWIN__ @@ -177,19 +177,19 @@ static char * cygwin_search_exe_in_path(struct ext_table * path, char * name) for (i = 0; i < path->size; i++) { dir = path->contents[i]; if (dir[0] == 0) dir = "."; /* empty path component = current dir */ - fullname = caml_strconcat(3, dir, "/", name); + fullname = caml_stat_strconcat(3, dir, "/", name); if (cygwin_file_exists(fullname)) return fullname; caml_stat_free(fullname); - fullname = caml_strconcat(4, dir, "/", name, ".exe"); + fullname = caml_stat_strconcat(4, dir, "/", name, ".exe"); if (cygwin_file_exists(fullname)) return fullname; caml_stat_free(fullname); } not_found: - if (cygwin_file_exists(name)) return caml_strdup(name); - fullname = caml_strconcat(2, name, ".exe"); + if (cygwin_file_exists(name)) return caml_stat_strdup(name); + fullname = caml_stat_strconcat(2, name, ".exe"); if (cygwin_file_exists(fullname)) return fullname; caml_stat_free(fullname); - return caml_strdup(name); + return caml_stat_strdup(name); } #endif @@ -217,7 +217,7 @@ char * caml_search_dll_in_path(struct ext_table * path, char * name) char * dllname; char * res; - dllname = caml_strconcat(2, name, ".so"); + dllname = caml_stat_strconcat(2, name, ".so"); res = caml_search_in_path(path, dllname); caml_stat_free(dllname); return res; @@ -347,7 +347,7 @@ CAMLexport int caml_read_directory(char * dirname, struct ext_table * contents) e = readdir(d); if (e == NULL) break; if (strcmp(e->d_name, ".") == 0 || strcmp(e->d_name, "..") == 0) continue; - caml_ext_table_add(contents, caml_strdup(e->d_name)); + caml_ext_table_add(contents, caml_stat_strdup(e->d_name)); } closedir(d); return 0; diff --git a/byterun/win32.c b/byterun/win32.c index 823e8e024a..f9b6714512 100644 --- a/byterun/win32.c +++ b/byterun/win32.c @@ -133,7 +133,7 @@ char * caml_decompose_path(struct ext_table * tbl, char * path) int n; if (path == NULL) return NULL; - p = caml_strdup(path); + p = caml_stat_strdup(path); q = p; while (1) { for (n = 0; q[n] != 0 && q[n] != ';'; n++) /*nothing*/; @@ -159,7 +159,7 @@ char * caml_search_in_path(struct ext_table * path, char * name) dir = path->contents[i]; if (dir[0] == 0) continue; /* not sure what empty path components mean under Windows */ - fullname = caml_strconcat(3, dir, "\\", name); + fullname = caml_stat_strconcat(3, dir, "\\", name); caml_gc_message(0x100, "Searching %s\n", (uintnat) fullname); if (stat(fullname, &st) == 0 && S_ISREG(st.st_mode)) return fullname; @@ -167,7 +167,7 @@ char * caml_search_in_path(struct ext_table * path, char * name) } not_found: caml_gc_message(0x100, "%s not found in search path\n", (uintnat) name); - return caml_strdup(name); + return caml_stat_strdup(name); } CAMLexport char * caml_search_exe_in_path(char * name) @@ -190,7 +190,7 @@ CAMLexport char * caml_search_exe_in_path(char * name) caml_gc_message(0x100, "%s not found in search path\n", (uintnat) name); caml_stat_free(fullname); - return caml_strdup(name); + return caml_stat_strdup(name); } if (retcode < fullnamelen) return fullname; @@ -204,7 +204,7 @@ char * caml_search_dll_in_path(struct ext_table * path, char * name) char * dllname; char * res; - dllname = caml_strconcat(2, name, ".dll"); + dllname = caml_stat_strconcat(2, name, ".dll"); res = caml_search_in_path(path, dllname); caml_stat_free(dllname); return res; @@ -363,7 +363,7 @@ static void expand_pattern(char * pat) store_argument(pat); /* a la Bourne shell */ return; } - prefix = caml_strdup(pat); + prefix = caml_stat_strdup(pat); /* We need to stop at the first directory or drive boundary, because the * _findata_t structure contains the filename, not the leading directory. */ for (i = strlen(prefix); i > 0; i--) { @@ -374,7 +374,7 @@ static void expand_pattern(char * pat) if (i == 0) prefix[0] = 0; do { - name = caml_strconcat(2, prefix, ffblk.name); + name = caml_stat_strconcat(2, prefix, ffblk.name); store_argument(name); } while (_findnext(handle, &ffblk) != -1); _findclose(handle); @@ -415,9 +415,9 @@ int caml_read_directory(char * dirname, struct ext_table * contents) (dirname[dirnamelen - 1] == '/' || dirname[dirnamelen - 1] == '\\' || dirname[dirnamelen - 1] == ':')) - template = caml_strconcat(2, dirname, "*.*"); + template = caml_stat_strconcat(2, dirname, "*.*"); else - template = caml_strconcat(2, dirname, "\\*.*"); + template = caml_stat_strconcat(2, dirname, "\\*.*"); h = _findfirst(template, &fileinfo); if (h == -1) { caml_stat_free(template); @@ -425,7 +425,7 @@ int caml_read_directory(char * dirname, struct ext_table * contents) } do { if (strcmp(fileinfo.name, ".") != 0 && strcmp(fileinfo.name, "..") != 0) { - caml_ext_table_add(contents, caml_strdup(fileinfo.name)); + caml_ext_table_add(contents, caml_stat_strdup(fileinfo.name)); } } while (_findnext(h, &fileinfo) == 0); _findclose(h); @@ -626,7 +626,7 @@ char * caml_executable_name(void) { char * name; DWORD namelen, ret; - + namelen = 256; while (1) { name = caml_stat_alloc(namelen); diff --git a/otherlibs/graph/open.c b/otherlibs/graph/open.c index 8f6ee07fb0..890b8713ef 100644 --- a/otherlibs/graph/open.c +++ b/otherlibs/graph/open.c @@ -246,7 +246,7 @@ value caml_gr_window_id(void) value caml_gr_set_window_title(value n) { if (window_name != NULL) caml_stat_free(window_name); - window_name = caml_strdup(String_val(n)); + window_name = caml_stat_strdup(String_val(n)); if (caml_gr_initialized) { XStoreName(caml_gr_display, caml_gr_window.win, window_name); XSetIconName(caml_gr_display, caml_gr_window.win, window_name); diff --git a/otherlibs/unix/access.c b/otherlibs/unix/access.c index 0df09ed25a..b6170026a7 100644 --- a/otherlibs/unix/access.c +++ b/otherlibs/unix/access.c @@ -54,7 +54,7 @@ CAMLprim value unix_access(value path, value perms) caml_unix_check_path(path, "access"); cv_flags = caml_convert_flag_list(perms, access_permission_table); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = access(p, cv_flags); caml_leave_blocking_section(); diff --git a/otherlibs/unix/chdir.c b/otherlibs/unix/chdir.c index 244ad5d3c5..c75261cdb7 100644 --- a/otherlibs/unix/chdir.c +++ b/otherlibs/unix/chdir.c @@ -24,7 +24,7 @@ CAMLprim value unix_chdir(value path) char * p; int ret; caml_unix_check_path(path, "chdir"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = chdir(p); caml_leave_blocking_section(); diff --git a/otherlibs/unix/chmod.c b/otherlibs/unix/chmod.c index cfdc1a3346..8382db5ef6 100644 --- a/otherlibs/unix/chmod.c +++ b/otherlibs/unix/chmod.c @@ -26,7 +26,7 @@ CAMLprim value unix_chmod(value path, value perm) char * p; int ret; caml_unix_check_path(path, "chmod"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = chmod(p, Int_val(perm)); caml_leave_blocking_section(); diff --git a/otherlibs/unix/chown.c b/otherlibs/unix/chown.c index f018e9e0a7..4b53a2c02e 100644 --- a/otherlibs/unix/chown.c +++ b/otherlibs/unix/chown.c @@ -24,7 +24,7 @@ CAMLprim value unix_chown(value path, value uid, value gid) char * p; int ret; caml_unix_check_path(path, "chown"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = chown(p, Int_val(uid), Int_val(gid)); caml_leave_blocking_section(); diff --git a/otherlibs/unix/chroot.c b/otherlibs/unix/chroot.c index 7b87de7223..8da7710cbd 100644 --- a/otherlibs/unix/chroot.c +++ b/otherlibs/unix/chroot.c @@ -24,7 +24,7 @@ CAMLprim value unix_chroot(value path) char * p; int ret; caml_unix_check_path(path, "chroot"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = chroot(p); caml_leave_blocking_section(); diff --git a/otherlibs/unix/getaddrinfo.c b/otherlibs/unix/getaddrinfo.c index 90c27dae9c..ab605bd275 100644 --- a/otherlibs/unix/getaddrinfo.c +++ b/otherlibs/unix/getaddrinfo.c @@ -71,13 +71,13 @@ CAMLprim value unix_getaddrinfo(value vnode, value vserv, value vopts) if (caml_string_length(vnode) == 0) { node = NULL; } else { - node = caml_strdup(String_val(vnode)); + node = caml_stat_strdup(String_val(vnode)); } /* Extract "service" parameter */ if (caml_string_length(vserv) == 0) { serv = NULL; } else { - serv = caml_strdup(String_val(vserv)); + serv = caml_stat_strdup(String_val(vserv)); } /* Parse options, set hints */ memset(&hints, 0, sizeof(hints)); diff --git a/otherlibs/unix/gethost.c b/otherlibs/unix/gethost.c index 1c1f5efa03..6c912e5f7b 100644 --- a/otherlibs/unix/gethost.c +++ b/otherlibs/unix/gethost.c @@ -136,7 +136,7 @@ CAMLprim value unix_gethostbyname(value name) if (! caml_string_is_c_safe(name)) caml_raise_not_found(); #if HAS_GETHOSTBYNAME_R || GETHOSTBYNAME_IS_REENTRANT - hostname = caml_strdup(String_val(name)); + hostname = caml_stat_strdup(String_val(name)); #else hostname = String_val(name); #endif diff --git a/otherlibs/unix/link.c b/otherlibs/unix/link.c index 3179c060dc..6454aaed1a 100644 --- a/otherlibs/unix/link.c +++ b/otherlibs/unix/link.c @@ -26,8 +26,8 @@ CAMLprim value unix_link(value path1, value path2) int ret; caml_unix_check_path(path1, "link"); caml_unix_check_path(path2, "link"); - p1 = caml_strdup(String_val(path1)); - p2 = caml_strdup(String_val(path2)); + p1 = caml_stat_strdup(String_val(path1)); + p2 = caml_stat_strdup(String_val(path2)); caml_enter_blocking_section(); ret = link(p1, p2); caml_leave_blocking_section(); diff --git a/otherlibs/unix/mkdir.c b/otherlibs/unix/mkdir.c index 93cb61cc97..0c1777816e 100644 --- a/otherlibs/unix/mkdir.c +++ b/otherlibs/unix/mkdir.c @@ -26,7 +26,7 @@ CAMLprim value unix_mkdir(value path, value perm) char * p; int ret; caml_unix_check_path(path, "mkdir"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = mkdir(p, Int_val(perm)); caml_leave_blocking_section(); diff --git a/otherlibs/unix/mkfifo.c b/otherlibs/unix/mkfifo.c index 4b97c1c45b..7914c877d1 100644 --- a/otherlibs/unix/mkfifo.c +++ b/otherlibs/unix/mkfifo.c @@ -29,7 +29,7 @@ CAMLprim value unix_mkfifo(value path, value mode) char * p; int ret; caml_unix_check_path(path, "mkfifo"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = mkfifo(p, Int_val(mode)); caml_leave_blocking_section(); @@ -52,7 +52,7 @@ CAMLprim value unix_mkfifo(value path, value mode) char * p; int ret; caml_unix_check_path(path, "mkfifo"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = mknod(p, (Int_val(mode) & 07777) | S_IFIFO, 0); caml_leave_blocking_section(); diff --git a/otherlibs/unix/open.c b/otherlibs/unix/open.c index 1892d44c76..859dbe4467 100644 --- a/otherlibs/unix/open.c +++ b/otherlibs/unix/open.c @@ -73,7 +73,7 @@ CAMLprim value unix_open(value path, value flags, value perm) #if defined(O_CLOEXEC) if (cloexec) cv_flags |= O_CLOEXEC; #endif - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); /* open on a named FIFO can block (PR#1533) */ caml_enter_blocking_section(); fd = open(p, cv_flags, Int_val(perm)); diff --git a/otherlibs/unix/opendir.c b/otherlibs/unix/opendir.c index 067cacc575..ead693d352 100644 --- a/otherlibs/unix/opendir.c +++ b/otherlibs/unix/opendir.c @@ -33,7 +33,7 @@ CAMLprim value unix_opendir(value path) char * p; caml_unix_check_path(path, "opendir"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); d = opendir(p); caml_leave_blocking_section(); diff --git a/otherlibs/unix/readlink.c b/otherlibs/unix/readlink.c index 4e9f04538e..05973e0eb5 100644 --- a/otherlibs/unix/readlink.c +++ b/otherlibs/unix/readlink.c @@ -39,7 +39,7 @@ CAMLprim value unix_readlink(value path) int len; char * p; caml_unix_check_path(path, "readlink"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); len = readlink(p, buffer, sizeof(buffer) - 1); caml_leave_blocking_section(); diff --git a/otherlibs/unix/rename.c b/otherlibs/unix/rename.c index bf13eab6f3..c31e028b62 100644 --- a/otherlibs/unix/rename.c +++ b/otherlibs/unix/rename.c @@ -27,8 +27,8 @@ CAMLprim value unix_rename(value path1, value path2) int ret; caml_unix_check_path(path1, "rename"); caml_unix_check_path(path2, "rename"); - p1 = caml_strdup(String_val(path1)); - p2 = caml_strdup(String_val(path2)); + p1 = caml_stat_strdup(String_val(path1)); + p2 = caml_stat_strdup(String_val(path2)); caml_enter_blocking_section(); ret = rename(p1, p2); caml_leave_blocking_section(); diff --git a/otherlibs/unix/rmdir.c b/otherlibs/unix/rmdir.c index 9f9b4589ee..748a22bed6 100644 --- a/otherlibs/unix/rmdir.c +++ b/otherlibs/unix/rmdir.c @@ -24,7 +24,7 @@ CAMLprim value unix_rmdir(value path) char * p; int ret; caml_unix_check_path(path, "rmdir"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = rmdir(p); caml_leave_blocking_section(); diff --git a/otherlibs/unix/stat.c b/otherlibs/unix/stat.c index cd62dd0bbc..48d4a6bded 100644 --- a/otherlibs/unix/stat.c +++ b/otherlibs/unix/stat.c @@ -85,7 +85,7 @@ CAMLprim value unix_stat(value path) struct stat buf; char * p; caml_unix_check_path(path, "stat"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = stat(p, &buf); caml_leave_blocking_section(); @@ -103,7 +103,7 @@ CAMLprim value unix_lstat(value path) struct stat buf; char * p; caml_unix_check_path(path, "lstat"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); #ifdef HAS_SYMLINK ret = lstat(p, &buf); @@ -138,7 +138,7 @@ CAMLprim value unix_stat_64(value path) struct stat buf; char * p; caml_unix_check_path(path, "stat"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = stat(p, &buf); caml_leave_blocking_section(); @@ -154,7 +154,7 @@ CAMLprim value unix_lstat_64(value path) struct stat buf; char * p; caml_unix_check_path(path, "lstat"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); #ifdef HAS_SYMLINK ret = lstat(p, &buf); diff --git a/otherlibs/unix/symlink.c b/otherlibs/unix/symlink.c index 0bff3f6d70..bbf3cfcb7a 100644 --- a/otherlibs/unix/symlink.c +++ b/otherlibs/unix/symlink.c @@ -29,8 +29,8 @@ CAMLprim value unix_symlink(value to_dir, value path1, value path2) int ret; caml_unix_check_path(path1, "symlink"); caml_unix_check_path(path2, "symlink"); - p1 = caml_strdup(String_val(path1)); - p2 = caml_strdup(String_val(path2)); + p1 = caml_stat_strdup(String_val(path1)); + p2 = caml_stat_strdup(String_val(path2)); caml_enter_blocking_section(); ret = symlink(p1, p2); caml_leave_blocking_section(); diff --git a/otherlibs/unix/truncate.c b/otherlibs/unix/truncate.c index 4f333cbd9c..e7c1f6cb41 100644 --- a/otherlibs/unix/truncate.c +++ b/otherlibs/unix/truncate.c @@ -34,7 +34,7 @@ CAMLprim value unix_truncate(value path, value len) char * p; int ret; caml_unix_check_path(path, "truncate"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = truncate(p, Long_val(len)); caml_leave_blocking_section(); @@ -51,7 +51,7 @@ CAMLprim value unix_truncate_64(value path, value vlen) int ret; file_offset len = File_offset_val(vlen); caml_unix_check_path(path, "truncate"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = truncate(p, len); caml_leave_blocking_section(); diff --git a/otherlibs/unix/unlink.c b/otherlibs/unix/unlink.c index c06dd3632a..f9223b1f85 100644 --- a/otherlibs/unix/unlink.c +++ b/otherlibs/unix/unlink.c @@ -24,7 +24,7 @@ CAMLprim value unix_unlink(value path) char * p; int ret; caml_unix_check_path(path, "unlink"); - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = unlink(p); caml_leave_blocking_section(); diff --git a/otherlibs/unix/utimes.c b/otherlibs/unix/utimes.c index f60fbbcecd..c77b94b0d4 100644 --- a/otherlibs/unix/utimes.c +++ b/otherlibs/unix/utimes.c @@ -43,7 +43,7 @@ CAMLprim value unix_utimes(value path, value atime, value mtime) tv[1].tv_usec = (mt - tv[1].tv_sec) * 1000000; t = tv; } - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = utimes(p, t); caml_leave_blocking_section(); @@ -78,7 +78,7 @@ CAMLprim value unix_utimes(value path, value atime, value mtime) times.modtime = mt; t = × } - p = caml_strdup(String_val(path)); + p = caml_stat_strdup(String_val(path)); caml_enter_blocking_section(); ret = utime(p, t); caml_leave_blocking_section(); diff --git a/otherlibs/win32unix/readlink.c b/otherlibs/win32unix/readlink.c index 7b20614cb7..80112dc51d 100644 --- a/otherlibs/win32unix/readlink.c +++ b/otherlibs/win32unix/readlink.c @@ -29,7 +29,7 @@ CAMLprim value unix_readlink(value opath) char* path; DWORD attributes; caml_unix_check_path(opath, "readlink"); - path = caml_strdup(String_val(opath)); + path = caml_stat_strdup(String_val(opath)); caml_enter_blocking_section(); attributes = GetFileAttributes(path); diff --git a/otherlibs/win32unix/stat.c b/otherlibs/win32unix/stat.c index 8f05562690..7ed2df7028 100644 --- a/otherlibs/win32unix/stat.c +++ b/otherlibs/win32unix/stat.c @@ -304,7 +304,7 @@ static int do_stat(int do_lstat, int use_64, char* opath, mlsize_t l, HANDLE fst { char* path; int ret; - path = caml_strdup(opath); + path = caml_stat_strdup(opath); ret = safe_do_stat(do_lstat, use_64, path, l, fstat, st_ino, res); caml_stat_free(path); return ret; diff --git a/otherlibs/win32unix/symlink.c b/otherlibs/win32unix/symlink.c index 326cefcbb9..11582a27e0 100644 --- a/otherlibs/win32unix/symlink.c +++ b/otherlibs/win32unix/symlink.c @@ -52,8 +52,8 @@ again: } /* Copy source and dest outside the OCaml heap */ - source = caml_strdup(String_val(osource)); - dest = caml_strdup(String_val(odest)); + source = caml_stat_strdup(String_val(osource)); + dest = caml_stat_strdup(String_val(odest)); caml_enter_blocking_section(); result = pCreateSymbolicLink(dest, source, flags); |