Bug #9189

Build failure on Windows in case of nonascii TEMP environment.

Added by Heesob Park over 1 year ago. Updated 10 months ago.

[ruby-core:58732]
Status:Assigned
Priority:Normal
Assignee:-
ruby -v:ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32] Backport:1.9.3: DONTNEED, 2.0.0: REQUIRED

Description

I experienced a build failure during build extension library with trunk on Windows.

make[2]: Entering directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
generating bigdecimal-i386-mingw32.def
compiling bigdecimal.c
In file included from bigdecimal.c:20:0:
bigdecimal.h:62:1: error: static declaration of 'labs' follows non-static declar
ation
make[2]: *** [bigdecimal.o] Error 1
make[2]: Leaving directory `/c/work/ruby-2.1.0-r43936/ext/bigdecimal'
make[1]: *** [ext/bigdecimal/all] Error 2
make[1]: Leaving directory `/c/work/ruby-2.1.0-r43936'
make: *** [build-ext] Error 2

I found the cause of this error is mkmk failure.
Here is a part of mkmf.log

have_func: checking for labs() in stdlib.h... -------------------- no

"i686-w64-mingw32-gcc -o conftest.exe -I../../.ext/include/i386-mingw32 -I../.././include -I../.././ext/bigdecimal -D_WIN32_WINNT=0x0501 -D_FILE_OFFSET_BITS=64   -O3 -fno-omit-frame-pointer -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration conftest.c  -L. -L../.. -L.      -lmsvcrt-ruby210-static  -lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi  "

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
Cannot create temporary file in C:\Users\??苑?AppData\Local\Temp\: Invalid argument

The TEMP environment varable is

C:\work\ruby-2.1.0-r43936>set TEMP
TEMP=C:\Users\희섭\AppData\Local\Temp

It seems that miniruby cannot handle encoding properly.

C:\work\ruby-2.1.0-r43936>miniruby -ve "p ENV['TEMP']"
ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
"C:\\Users\\\xED\x9D\xAC\xEC\x84\xAD\\AppData\\Local\\Temp"

C:\work\ruby-2.1.0-r43936>miniruby.exe -ve "p ENV['TEMP'].encoding"
ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
#<Encoding:ASCII-8BIT>  

Whereas, the final ruby can handle encoding properly.

C:\work>ruby -ve "p ENV['TEMP']"
ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
"C:\\Users\\희섭\\AppData\\Local\\Temp"   

C:\work>ruby -ve "p ENV['TEMP'].encoding"
ruby 2.1.0dev (2013-11-30 trunk 43923) [i386-mingw32]
#<Encoding:CP949>

Associated revisions

Revision 43950
Added by Usaku NAKAMURA over 1 year ago

  • hash.c (getenv): use ANSI codepage version of getenv() for miniruby on Windows. [Bug #9189] reported by phasis68 (Heesob Park).

Revision 43950
Added by Usaku NAKAMURA over 1 year ago

  • hash.c (getenv): use ANSI codepage version of getenv() for miniruby on Windows. [Bug #9189] reported by phasis68 (Heesob Park).

History

#1 Updated by Hiroshi SHIBATA over 1 year ago

  • Assignee set to Usaku NAKAMURA
  • Target version set to 2.1.0

#2 Updated by Usaku NAKAMURA over 1 year ago

  • Status changed from Open to Third Party's Issue

"This application" is not ruby.
It's your compiler.
Please contact the compiler's support team for more information :)

#3 Updated by Heesob Park over 1 year ago

Yes, the error message is not from ruby, but from mingw compilers.
And I found TMP environtment variable is the actual cause of this error.
Nevertheless, I think Ruby is not entirely free from this error.

If I run "ruby extconf.rb" in ext/bigdecimal folder,
The mkmf works as expected without error on the same environment.

Anyway, I leave this message for the record:
If you want to build ruby from source with Mingw toolchain,
the TMP environment variable should not contain non-ascii string.

#4 Updated by Nobuyoshi Nakada over 1 year ago

Is TEMP changed by miniruby?
miniruby -e "system('set TEMP')"
shows the correct path?

#5 Updated by Heesob Park over 1 year ago

Yes, it shows the correct path.

C:\work\ruby-2.1.0-r43936>miniruby.exe -e "system('set TEMP')"
TEMP=C:\Users\희섭\AppData\Local\Temp

BTW, In Visual C++ compiler, I can see same build failure with non-ascii USERNAME environment variable.

#6 Updated by Usaku NAKAMURA over 1 year ago

  • Status changed from Third Party's Issue to Assigned
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: REQUIRED

Ah, I see.
There is a bug of handling the environment variables in miniruby.
I'm debugging it now...

#7 Updated by Usaku NAKAMURA over 1 year ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43950.
Heesob, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • hash.c (getenv): use ANSI codepage version of getenv() for miniruby on Windows. [Bug #9189] reported by phasis68 (Heesob Park).

#8 Updated by Usaku NAKAMURA about 1 year ago

  • Status changed from Closed to Assigned
  • Assignee deleted (Usaku NAKAMURA)
  • Backport changed from 1.9.3: DONTNEED, 2.0.0: REQUIRED to 1.9.3: REQUIRED, 2.0.0: REQUIRED

r43950 (and r43958) is only a workaround.
We have to change the entire implementation of ENV to treat encoding.

#9 Updated by Usaku NAKAMURA about 1 year ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED to 1.9.3: DONTNEED, 2.0.0: REQUIRED

#10 Updated by Hiroshi SHIBATA about 1 year ago

  • Target version changed from 2.1.0 to current: 2.2.0

#11 Updated by Heesob Park 10 months ago

I still failed to build trunk.

C:\work\ruby-2.2.0-r45738>nmake
...
generating psych-x64-mswin64_120.def
compiling psych.c
psych.c
compiling psych_emitter.c
psych_emitter.c
compiling psych_parser.c
psych_parser.c
compiling psych_to_ruby.c
psych_to_ruby.c
compiling psych_yaml_tree.c
psych_yaml_tree.c
compiling ../.././ext/psych/yaml/api.c
api.c
../.././ext/psych/yaml/api.c(10) : error C2491: 'yaml_get_version_string' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(11) : error C2065: 'YAML_VERSION_STRING' : undeclared identifier
../.././ext/psych/yaml/api.c(11) : warning C4047: 'return' : 'const char *' differs in levels of indirection from 'int'
../.././ext/psych/yaml/api.c(20) : error C2491: 'yaml_get_version' : definitionof dllimport function not allowed
../.././ext/psych/yaml/api.c(21) : error C2065: 'YAML_VERSION_MAJOR' : undeclared identifier
../.././ext/psych/yaml/api.c(22) : error C2065: 'YAML_VERSION_MINOR' : undeclared identifier
../.././ext/psych/yaml/api.c(23) : error C2065: 'YAML_VERSION_PATCH' : undeclared identifier
../.././ext/psych/yaml/api.c(32) : error C2491: 'yaml_malloc' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(42) : error C2491: 'yaml_realloc' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(52) : error C2491: 'yaml_free' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(62) : error C2491: 'yaml_strdup' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(76) : error C2491: 'yaml_string_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(98) : error C2491: 'yaml_string_join' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(119) : error C2491: 'yaml_stack_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(137) : error C2491: 'yaml_queue_extend' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(172) : error C2491: 'yaml_parser_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(215) : error C2491: 'yaml_parser_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(285) : error C2491: 'yaml_parser_set_input_string': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(304) : error C2491: 'yaml_parser_set_input_file' :definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(322) : error C2491: 'yaml_parser_set_input' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(337) : error C2491: 'yaml_parser_set_encoding' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(350) : error C2491: 'yaml_emitter_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(387) : error C2491: 'yaml_emitter_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(453) : error C2491: 'yaml_emitter_set_output_string' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(473) : error C2491: 'yaml_emitter_set_output_file': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(491) : error C2491: 'yaml_emitter_set_output' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(506) : error C2491: 'yaml_emitter_set_encoding' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(519) : error C2491: 'yaml_emitter_set_canonical' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(531) : error C2491: 'yaml_emitter_set_indent' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(543) : error C2491: 'yaml_emitter_set_width' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(555) : error C2491: 'yaml_emitter_set_unicode' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(567) : error C2491: 'yaml_emitter_set_break' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(579) : error C2491: 'yaml_token_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(665) : error C2491: 'yaml_stream_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(681) : error C2491: 'yaml_stream_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(701) : error C2491: 'yaml_document_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(776) : error C2491: 'yaml_document_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(792) : error C2491: 'yaml_alias_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(820) : error C2491: 'yaml_scalar_event_initialize': definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(876) : error C2491: 'yaml_sequence_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(913) : error C2491: 'yaml_sequence_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(931) : error C2491: 'yaml_mapping_start_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(968) : error C2491: 'yaml_mapping_end_event_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(984) : error C2491: 'yaml_event_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1039) : error C2491: 'yaml_document_initialize' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1122) : error C2491: 'yaml_document_delete' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1169) : error C2491: 'yaml_document_get_node' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1184) : error C2491: 'yaml_document_get_root_node' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1201) : error C2491: 'yaml_document_add_scalar' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1259) : error C2491: 'yaml_document_add_sequence' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1309) : error C2491: 'yaml_document_add_mapping' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1359) : error C2491: 'yaml_document_append_sequence_item' : definition of dllimport function not allowed
../.././ext/psych/yaml/api.c(1387) : error C2491: 'yaml_document_append_mapping_pair' : definition of dllimport function not allowed
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\x86_amd64\cl.EXE"' : return code '0x2'
Stop.
NMAKE : fatal error U1077: 'cd' : return code '0x2'
Stop.
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\BIN\nmake.EXE"' : return code '0x2'
Stop.

Here is a patch.

diff --git a/hash.c b/hash.c
index c3a06e5..64c4057 100644
--- a/hash.c
+++ b/hash.c
@@ -2740,7 +2740,13 @@ ruby_setenv(const char *name, const char *value)
     else {
    buf = rb_sprintf("%s=", name);
     }
-    failed = putenv(RSTRING_PTR(buf));
+    if(rb_locale_encindex()==ENCINDEX_ASCII) {
+        WCHAR *wbuf = rb_w32_mbstr_to_wstr(CP_UTF8, RSTRING_PTR(buf), -1, NULL);     
+        failed = _wputenv(wbuf);
+        free(wbuf);
+    } else {
+        failed = putenv(RSTRING_PTR(buf)); 
+    }     
     /* even if putenv() failed, clean up and try to delete the
      * variable from the system area. */
     rb_str_resize(buf, 0); 

Also available in: Atom PDF