Project

General

Profile

Actions

Bug #9189

open

Build failure on Windows in case of nonascii TEMP environment.

Added by phasis68 (Heesob Park) almost 11 years ago. Updated 6 months ago.

Status:
Open
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-11-30 trunk 43936) [i386-mingw32]
[ruby-core:58732]

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>

Updated by hsbt (Hiroshi SHIBATA) almost 11 years ago

  • Assignee set to usa (Usaku NAKAMURA)
  • Target version set to 2.1.0

Updated by usa (Usaku NAKAMURA) almost 11 years 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 :)

Updated by phasis68 (Heesob Park) almost 11 years 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.

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

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

Updated by phasis68 (Heesob Park) almost 11 years 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.

Updated by usa (Usaku NAKAMURA) almost 11 years 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...

Actions #7

Updated by usa (Usaku NAKAMURA) almost 11 years 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.
    [ruby-core:58732] [Bug #9189] reported by phasis68 (Heesob Park).

Updated by usa (Usaku NAKAMURA) almost 11 years ago

  • Status changed from Closed to Assigned
  • Assignee deleted (usa (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.

Updated by usa (Usaku NAKAMURA) almost 11 years ago

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

Updated by hsbt (Hiroshi SHIBATA) over 10 years ago

  • Target version changed from 2.1.0 to 2.2.0

Updated by phasis68 (Heesob Park) over 10 years 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); 
Actions #12

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Target version deleted (2.2.0)

Updated by pcai (Peter Cai) 11 months ago

I'm unable to reproduce. Windows presents an ascii-safe alias of the TEMP folder for me so I can't seem to test the handling:

  • windows 11 (Version 10.0.22621 Build 22621)
  • Ruby+Devkit 3.2.2-1 (x64)
C:\work>ruby -e "system('set TEMP')"
TEMP=C:\Users\6863~1\tmp

C:\work>set TEMP
TEMP=C:\Users\6863~1\tmp

C:\work>cd C:\Users\희섭\tmp

C:\Users\희섭\tmp>echo %cd%
C:\Users\희섭\tmp

C:\Users\희섭\tmp>ruby -v
ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x64-mingw-ucrt]

Can anyone describe an environment that can reproduce?

Updated by nobu (Nobuyoshi Nakada) 11 months ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: REQUIRED to 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN

pcai (Peter Cai) wrote in #note-13:

I'm unable to reproduce. Windows presents an ascii-safe alias of the TEMP folder for me so I can't seem to test the handling:

Thank you for testing.
Does it work after set TEMP=C:\Users\희섭\tmp?

Actions #15

Updated by hsbt (Hiroshi SHIBATA) 6 months ago

  • Status changed from Assigned to Open
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0