win32: fix incorrectly shared path-conversion buffer

This commit is contained in:
Matthew Flatt 2011-04-20 12:24:58 -06:00
parent 231cf7db48
commit e9dd7580a8
2 changed files with 10 additions and 4 deletions

View File

@ -262,6 +262,7 @@ typedef struct Thread_Local_Variables {
int env_uid_counter_; int env_uid_counter_;
int scheme_overflow_count_; int scheme_overflow_count_;
struct Scheme_Object *original_pwd_; struct Scheme_Object *original_pwd_;
void *file_path_wc_buffer_;
intptr_t scheme_hash_request_count_; intptr_t scheme_hash_request_count_;
intptr_t scheme_hash_iteration_count_; intptr_t scheme_hash_iteration_count_;
struct Scheme_Env *initial_modules_env_; struct Scheme_Env *initial_modules_env_;
@ -579,6 +580,7 @@ XFORM_GC_VARIABLE_STACK_THROUGH_THREAD_LOCAL;
#define env_uid_counter XOA (scheme_get_thread_local_variables()->env_uid_counter_) #define env_uid_counter XOA (scheme_get_thread_local_variables()->env_uid_counter_)
#define scheme_overflow_count XOA (scheme_get_thread_local_variables()->scheme_overflow_count_) #define scheme_overflow_count XOA (scheme_get_thread_local_variables()->scheme_overflow_count_)
#define original_pwd XOA (scheme_get_thread_local_variables()->original_pwd_) #define original_pwd XOA (scheme_get_thread_local_variables()->original_pwd_)
#define file_path_wc_buffer XOA (scheme_get_thread_local_variables()->file_path_wc_buffer_)
#define scheme_hash_request_count XOA (scheme_get_thread_local_variables()->scheme_hash_request_count_) #define scheme_hash_request_count XOA (scheme_get_thread_local_variables()->scheme_hash_request_count_)
#define scheme_hash_iteration_count XOA (scheme_get_thread_local_variables()->scheme_hash_iteration_count_) #define scheme_hash_iteration_count XOA (scheme_get_thread_local_variables()->scheme_hash_iteration_count_)
#define initial_modules_env XOA (scheme_get_thread_local_variables()->initial_modules_env_) #define initial_modules_env XOA (scheme_get_thread_local_variables()->initial_modules_env_)

View File

@ -1153,7 +1153,7 @@ int scheme_os_setcwd(char *expanded, int noexn)
#ifdef DOS_FILE_SYSTEM #ifdef DOS_FILE_SYSTEM
#define WC_BUFFER_SIZE 1024 #define WC_BUFFER_SIZE 1024
static wchar_t wc_buffer[WC_BUFFER_SIZE]; THREAD_LOCAL_DECL(static void *file_path_wc_buffer);
static int wc_strlen(const wchar_t *ws) static int wc_strlen(const wchar_t *ws)
{ {
@ -1174,9 +1174,13 @@ wchar_t *scheme_convert_to_wchar(const char *s, int do_copy)
NULL, 0, -1, NULL, 0, -1,
NULL, 1/*UTF-16*/, '\t'); NULL, 1/*UTF-16*/, '\t');
if (!do_copy && (len < (WC_BUFFER_SIZE-1))) if (!do_copy && (len < (WC_BUFFER_SIZE-1))) {
ws = wc_buffer; if (!file_path_wc_buffer) {
else REGISTER_SO(file_path_wc_buffer);
file_path_wc_buffer = scheme_malloc_atomic(sizeof(wchar_t) * WC_BUFFER_SIZE);
}
ws = (wchar_t *)file_path_wc_buffer;
} else
ws = (wchar_t *)scheme_malloc_atomic(sizeof(wchar_t) * (len + 1)); ws = (wchar_t *)scheme_malloc_atomic(sizeof(wchar_t) * (len + 1));
scheme_utf8_decode(s, 0, l, scheme_utf8_decode(s, 0, l,
(unsigned int *)ws, 0, -1, (unsigned int *)ws, 0, -1,