Skip to content

Commit

Permalink
Fix up locale handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaiepi committed Jul 11, 2019
1 parent 07d63b1 commit 2fed1ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
11 changes: 7 additions & 4 deletions src/core/threadcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,9 @@ MVMThreadContext * MVM_tc_create(MVMThreadContext *parent, MVMInstance *instance
/* Initialize plugin_guard_args so we never have to do a NULL check */
tc->plugin_guard_args = instance->VMNull;

/* Initialize state related to locales on UNIX-like OSes. Windows doesn't
* need this because it doesn't support setting UTF-8 as the locale;
* transcoding between wide strings and UTF-8 strings and vice versa is
* handled differently from how you'd normally do it on other OSes. */
#ifndef _MSC_VER
/* Initialize state related to locales on UNIX-like OSes. Windows doesn't
* need this because its locale support blows and doesn't support UTF-8. */
tc->mbstate = (mbstate_t){ 0 };
tc->locale = duplocale(instance->locale);
#endif
Expand Down Expand Up @@ -118,6 +116,11 @@ void MVM_tc_destroy(MVMThreadContext *tc) {
MVM_free(tc->temp_bigints[i]);
}

#ifndef _MSC_VER
/* Free our thread's locale. */
freelocale(tc->locale);
#endif

/* Free the thread context itself. */
memset(tc, 0, sizeof(MVMThreadContext));
MVM_free(tc);
Expand Down
10 changes: 1 addition & 9 deletions src/core/threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,8 @@ static void start_thread(void *data) {
ThreadStart *ts = (ThreadStart *)data;
MVMThreadContext *tc = ts->tc;

/* Set up the thread's locale. This is not important on Windows since its
* locale support blows and doesn't allow setting it to UTF-8. We handle
* transcoding wide strings to UTF-8 strings and vice versa in a different
* way from how you'd do it on other OSes on Windows. */
#ifndef _MSC_VER
/* Use the locale created by our thread context. */
uselocale(tc->locale);
#endif

Expand Down Expand Up @@ -106,11 +103,6 @@ static void start_thread(void *data) {
/* Mark as exited, so the GC will know to clear our stuff. */
tc->thread_obj->body.stage = MVM_thread_stage_exited;

/* Clean up this thread's locale. */
#ifndef _MSC_VER
freelocale(tc->locale);
#endif

/* Mark ourselves as blocked, so that another thread will take care
* of GC-ing our objects and cleaning up our thread context. */
MVM_gc_mark_thread_blocked(tc);
Expand Down
6 changes: 4 additions & 2 deletions src/moar.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ MVMInstance * MVM_vm_create_instance(void) {
/* Set up instance data structure. */
instance = MVM_calloc(1, sizeof(MVMInstance));

#ifndef _WIN32
#ifndef _MSC_VER
/* Set up instance locale. */
instance->locale = newlocale(LC_CTYPE_MASK, "en_US.UTF-8", (locale_t)0);
#endif
Expand Down Expand Up @@ -647,8 +647,10 @@ void MVM_vm_destroy_instance(MVMInstance *instance) {
/* Clean up fixed size allocator */
MVM_fixed_size_destroy(instance->fsa);

#ifndef _MSC_VER
/* Clean up locale. */
MVM_free(instance->locale);
freelocale(instance->locale);
#endif

/* Clear up VM instance memory. */
MVM_free(instance);
Expand Down

0 comments on commit 2fed1ce

Please sign in to comment.