Skip to content

Commit 3897667

Browse files
authored
Change PATH_MAX to JL_PATH_MAX (#43986)
1 parent 99aab66 commit 3897667

File tree

7 files changed

+27
-26
lines changed

7 files changed

+27
-26
lines changed

cli/loader.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
/* Bring in definitions for `_OS_X_`, `PATH_MAX` and `PATHSEPSTRING`, `jl_ptls_t`, etc... */
3+
/* Bring in definitions for `_OS_X_`, `JL_PATH_MAX` and `PATHSEPSTRING`, `jl_ptls_t`, etc... */
44
#include "../src/support/platform.h"
55
#include "../src/support/dirpath.h"
66
#include "../src/julia_fasttls.h"

cli/loader_lib.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ static void * load_library(const char * rel_path, const char * src_dir, int err)
4949
return handle;
5050
#endif
5151

52-
char path[2*PATH_MAX + 1] = {0};
52+
char path[2*JL_PATH_MAX + 1] = {0};
5353
strncat(path, src_dir, sizeof(path) - 1);
5454
strncat(path, PATHSEPSTRING, sizeof(path) - 1);
5555
strncat(path, rel_path, sizeof(path) - 1);
5656

5757
#if defined(_OS_WINDOWS_)
58-
wchar_t wpath[2*PATH_MAX + 1] = {0};
59-
if (!utf8_to_wchar(path, wpath, 2*PATH_MAX)) {
58+
wchar_t wpath[2*JL_PATH_MAX + 1] = {0};
59+
if (!utf8_to_wchar(path, wpath, 2*JL_PATH_MAX)) {
6060
jl_loader_print_stderr3("ERROR: Unable to convert path ", path, " to wide string!\n");
6161
exit(1);
6262
}
@@ -98,7 +98,7 @@ static void * lookup_symbol(const void * lib_handle, const char * symbol_name) {
9898
}
9999

100100
// Find the location of libjulia.
101-
char lib_dir[PATH_MAX];
101+
char lib_dir[JL_PATH_MAX];
102102
JL_DLLEXPORT const char * jl_get_libdir()
103103
{
104104
// Reuse the path if this is not the first call.
@@ -107,11 +107,11 @@ JL_DLLEXPORT const char * jl_get_libdir()
107107
}
108108
#if defined(_OS_WINDOWS_)
109109
// On Windows, we use GetModuleFileNameW
110-
wchar_t libjulia_path[PATH_MAX];
110+
wchar_t libjulia_path[JL_PATH_MAX];
111111
HMODULE libjulia = NULL;
112112

113113
// Get a handle to libjulia.
114-
if (!utf8_to_wchar(LIBJULIA_NAME, libjulia_path, PATH_MAX)) {
114+
if (!utf8_to_wchar(LIBJULIA_NAME, libjulia_path, JL_PATH_MAX)) {
115115
jl_loader_print_stderr3("ERROR: Unable to convert path ", LIBJULIA_NAME, " to wide string!\n");
116116
exit(1);
117117
}
@@ -120,11 +120,11 @@ JL_DLLEXPORT const char * jl_get_libdir()
120120
jl_loader_print_stderr3("ERROR: Unable to load ", LIBJULIA_NAME, "!\n");
121121
exit(1);
122122
}
123-
if (!GetModuleFileNameW(libjulia, libjulia_path, PATH_MAX)) {
123+
if (!GetModuleFileNameW(libjulia, libjulia_path, JL_PATH_MAX)) {
124124
jl_loader_print_stderr("ERROR: GetModuleFileName() failed\n");
125125
exit(1);
126126
}
127-
if (!wchar_to_utf8(libjulia_path, lib_dir, PATH_MAX)) {
127+
if (!wchar_to_utf8(libjulia_path, lib_dir, JL_PATH_MAX)) {
128128
jl_loader_print_stderr("ERROR: Unable to convert julia path to UTF-8\n");
129129
exit(1);
130130
}

src/cgmemmgr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static intptr_t get_anon_hdl(void)
175175
if (check_fd_or_close(fd))
176176
return fd;
177177
# endif
178-
char shm_name[PATH_MAX] = "julia-codegen-0123456789-0123456789/tmp///";
178+
char shm_name[JL_PATH_MAX] = "julia-codegen-0123456789-0123456789/tmp///";
179179
pid_t pid = getpid();
180180
// `shm_open` can't be mapped exec on mac
181181
# ifndef _OS_DARWIN_

src/debuginfo.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -865,7 +865,7 @@ static objfileentry_t &find_object_file(uint64_t fbase, StringRef fname) JL_NOTS
865865
CFRelease(objuuid);
866866
CFRelease(objurl);
867867

868-
char objpathcstr[PATH_MAX];
868+
char objpathcstr[JL_PATH_MAX];
869869
if (dsympathurl != NULL &&
870870
CFURLGetFileSystemRepresentation(
871871
dsympathurl, true, (UInt8 *)objpathcstr,

src/init.c

+11-11
Original file line numberDiff line numberDiff line change
@@ -466,8 +466,8 @@ static char *abspath(const char *in, int nprefix)
466466
memcpy(out, in, sz + nprefix);
467467
}
468468
else {
469-
size_t path_size = PATH_MAX;
470-
char *path = (char*)malloc_s(PATH_MAX);
469+
size_t path_size = JL_PATH_MAX;
470+
char *path = (char*)malloc_s(JL_PATH_MAX);
471471
if (uv_cwd(path, &path_size)) {
472472
jl_error("fatal error: unexpected error while retrieving current working directory");
473473
}
@@ -502,8 +502,8 @@ static const char *absformat(const char *in)
502502
if (in[0] == '%' || jl_isabspath(in))
503503
return in;
504504
// get an escaped copy of cwd
505-
size_t path_size = PATH_MAX;
506-
char path[PATH_MAX];
505+
size_t path_size = JL_PATH_MAX;
506+
char path[JL_PATH_MAX];
507507
if (uv_cwd(path, &path_size)) {
508508
jl_error("fatal error: unexpected error while retrieving current working directory");
509509
}
@@ -527,17 +527,17 @@ static const char *absformat(const char *in)
527527
static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
528528
{ // this function resolves the paths in jl_options to absolute file locations as needed
529529
// and it replaces the pointers to `julia_bindir`, `julia_bin`, `image_file`, and output file paths
530-
// it may fail, print an error, and exit(1) if any of these paths are longer than PATH_MAX
530+
// it may fail, print an error, and exit(1) if any of these paths are longer than JL_PATH_MAX
531531
//
532532
// note: if you care about lost memory, you should call the appropriate `free()` function
533533
// on the original pointer for each `char*` you've inserted into `jl_options`, after
534534
// calling `julia_init()`
535-
char *free_path = (char*)malloc_s(PATH_MAX);
536-
size_t path_size = PATH_MAX;
535+
char *free_path = (char*)malloc_s(JL_PATH_MAX);
536+
size_t path_size = JL_PATH_MAX;
537537
if (uv_exepath(free_path, &path_size)) {
538538
jl_error("fatal error: unexpected error while retrieving exepath");
539539
}
540-
if (path_size >= PATH_MAX) {
540+
if (path_size >= JL_PATH_MAX) {
541541
jl_error("fatal error: jl_options.julia_bin path too long");
542542
}
543543
jl_options.julia_bin = (char*)malloc_s(path_size + 1);
@@ -556,10 +556,10 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
556556
if (jl_options.image_file) {
557557
if (rel == JL_IMAGE_JULIA_HOME && !jl_isabspath(jl_options.image_file)) {
558558
// build time path, relative to JULIA_BINDIR
559-
free_path = (char*)malloc_s(PATH_MAX);
560-
int n = snprintf(free_path, PATH_MAX, "%s" PATHSEPSTRING "%s",
559+
free_path = (char*)malloc_s(JL_PATH_MAX);
560+
int n = snprintf(free_path, JL_PATH_MAX, "%s" PATHSEPSTRING "%s",
561561
jl_options.julia_bindir, jl_options.image_file);
562-
if (n >= PATH_MAX || n < 0) {
562+
if (n >= JL_PATH_MAX || n < 0) {
563563
jl_error("fatal error: jl_options.image_file path too long");
564564
}
565565
jl_options.image_file = free_path;

src/julia_fasttls.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
extern "C" {
1010
#endif
1111

12-
/* Bring in definitions for `_OS_X_`, `PATH_MAX` and `PATHSEPSTRING`, `jl_ptls_t`, etc... */
12+
/* Bring in definitions for `_OS_X_`, `JL_PATH_MAX` and `PATHSEPSTRING`, `jl_ptls_t`, etc... */
1313
#include "platform.h"
1414
#include "dirpath.h"
1515

src/support/dirpath.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@
66
#ifdef _OS_WINDOWS_
77
#define PATHSEPSTRING "\\"
88
#define PATHLISTSEPSTRING ";"
9+
#define JL_PATH_MAX PATH_MAX
910
#if defined(_COMPILER_CLANG_)
10-
#define PATH_MAX MAX_PATH
11+
#define JL_PATH_MAX MAX_PATH
1112
#endif
1213
#else
1314
#define PATHSEPSTRING "/"
1415
#define PATHLISTSEPSTRING ":"
15-
#ifndef PATH_MAX // many platforms don't have a max path, we define one anyways
16-
#define PATH_MAX 1024
16+
#ifndef JL_PATH_MAX // many platforms don't have a max path, we define one anyways
17+
#define JL_PATH_MAX 1024
1718
#endif
1819
#endif
1920

0 commit comments

Comments
 (0)