ruby-changes:50165
From: nobu <ko1@a...>
Date: Wed, 7 Feb 2018 22:41:38 +0900 (JST)
Subject: [ruby-changes:50165] nobu:r62283 (trunk): mjit.c: system_tmpdir
nobu 2018-02-07 22:41:32 +0900 (Wed, 07 Feb 2018) New Revision: 62283 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62283 Log: mjit.c: system_tmpdir * mjit.c (system_tmpdir): use system provided temporary directory, and TMPDIR as well as mktemp(1), before TMP and "/tmp". Modified files: trunk/mjit.c Index: mjit.c =================================================================== --- mjit.c (revision 62282) +++ mjit.c (revision 62283) @@ -1197,6 +1197,42 @@ valid_class_serials_add_i(ID key, VALUE https://github.com/ruby/ruby/blob/trunk/mjit.c#L1197 return ID_TABLE_CONTINUE; } +static char * +system_tmpdir(void) +{ + char *tmpdir; + /* c.f. ext/etc/etc.c:etc_systmpdir() */ +#ifdef _WIN32 + WCHAR tmppath[_MAX_PATH]; + UINT len = rb_w32_system_tmpdir(tmppath, numberof(tmppath)); + if (len) { + tmpdir = rb_w32_wstr_to_mbstr(CP_UTF8, tmppath, -1, NULL); + return get_string(tmpdir); + } +#elif defined _CS_DARWIN_USER_TEMP_DIR + #ifndef MAXPATHLEN + #define MAXPATHLEN 1024 + #endif + char path[MAXPATHLEN]; + size_t len = confstr(_CS_DARWIN_USER_TEMP_DIR, path, sizeof(path)); + if (len > 0) { + tmpdir = xmalloc(len); + if (len > sizeof(path)) { + confstr(_CS_DARWIN_USER_TEMP_DIR, tmpdir, len); + } + else { + memcpy(tmpdir, path, len); + } + return tmpdir; + } +#endif + if (!(tmpdir = getenv("TMPDIR")) && + !(tmpdir = getenv("TMP"))) { + tmpdir = "/tmp"; + } + return get_string(tmpdir); +} + /* Default permitted number of units with a JIT code kept in memory. */ #define DEFAULT_CACHE_SIZE 1000 @@ -1248,12 +1284,7 @@ mjit_init(struct mjit_options *opts) https://github.com/ruby/ruby/blob/trunk/mjit.c#L1284 } #endif - if (getenv("TMP") != NULL) { /* For MinGW */ - tmp_dir = get_string(getenv("TMP")); - } - else { - tmp_dir = get_string("/tmp"); - } + tmp_dir = system_tmpdir(); init_header_filename(); pch_file = get_uniq_filename(0, MJIT_TMP_PREFIX "h", ".h.gch"); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/