Skip to content

Commit bf57e46

Browse files
committed
[GR-18163] Fix parsing literal floats when the locale does not use . for the decimal separator
PullRequest: truffleruby/4224
2 parents cc9720c + b520a43 commit bf57e46

File tree

18 files changed

+122
-98
lines changed

18 files changed

+122
-98
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Bug fixes:
88
* Fix repeated calling of methods `Dir#{each,each_child,children}` (#3464, @andrykonchin).
99
* Fix `IO#{wait,wait_readable,wait_writable}` methods and switch the current thread into a sleep state (@andrykonchin).
1010
* Fix `rb_global_variable()` for `Float` and bignum values during the `Init_` function (#3478, @eregon).
11+
* Fix parsing literal floats when the locale does not use `.` for the decimal separator (e.g. `LANG=fr_FR.UTF-8`) (#3512, @eregon).
1112

1213
Compatibility:
1314
* Move `IO#wait_readable`, `IO#wait_writable`, `IO#wait_priority` and `IO#wait` into core library (@andrykonchin).

doc/contributor/updating-ruby.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Update all of these:
144144
* Update `.ruby-version`, `TruffleRuby.LANGUAGE_VERSION`
145145
* Reset `truffleruby-abi-version.h` to `$RUBY_VERSION.1` and `lib/cext/ABI_check.txt` to `1` if `RUBY_VERSION` was updated.
146146
* Update `versions.json` (with gem versions provided by `cat ../ruby/gems/bundled_gems | sort`, `ls -l lib/gems/specifications/default` and `grep 'VERSION =' lib/mri/rubygems.rb`)
147-
* Also update version numbers for `debug` and `rbs` in `src/main/c/Makefile` and in `mx.truffleruby/suite.py`.
147+
* Also update version numbers for `debug` and `rbs` in `src/main/c/Makefile`, `mx.truffleruby/suite.py` and `lib/gems/gems/debug-*/ext/debug/extconf.rb`.
148148
* Copy and paste `-h` and `--help` output to `RubyLauncher` (instructions are in the end of the file `src/launcher/java/org/truffleruby/launcher/RubyLauncher.java`)
149149
* This is a good time to get `jt build` working.
150150
* Copy and paste the TruffleRuby `--help` output to `doc/user/options.md` (e.g., with `jt ruby --help | xsel -b`)

lib/cext/ABI_check.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
15
1+
16

lib/gems/gems/debug-1.7.1/ext/debug/extconf.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require 'mkmf'
2-
require_relative '../../lib/debug/version'
3-
File.write("debug_version.h", "#define RUBY_DEBUG_VERSION \"#{DEBUGGER__::VERSION}\"\n")
2+
# TruffleRuby: hardcode the version here to avoid depending on version.rb which is not copied to src/main/c/debug
3+
File.write("debug_version.h", "#define RUBY_DEBUG_VERSION \"#{"1.7.1"}\"\n")
44
$distcleanfiles << "debug_version.h"
55

66
if defined? RubyVM

lib/truffle/rbconfig.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,11 @@ module RbConfig
135135

136136
# Set extra flags needed for --building-core-cexts
137137
if Truffle::Boot.get_option 'building-core-cexts'
138-
libtruffleruby = "#{ruby_home}/src/main/c/cext/libtruffleruby.#{soext}"
139-
libtrufflerubytrampoline = "#{ruby_home}/src/main/c/cext-trampoline/libtrufflerubytrampoline.#{soext}"
138+
repo = Truffle::System.get_java_property 'truffleruby.repository'
139+
libtruffleruby = "#{repo}/src/main/c/cext/libtruffleruby.#{soext}"
140+
libtrufflerubytrampoline = "#{repo}/src/main/c/cext-trampoline/libtrufflerubytrampoline.#{soext}"
140141

141-
relative_debug_paths = " -fdebug-prefix-map=#{ruby_home}=."
142+
relative_debug_paths = " -fdebug-prefix-map=#{repo}=."
142143
cppflags << relative_debug_paths
143144

144145
warnflags << '-Wundef' # Warn for undefined preprocessor macros for core C extensions

mx.truffleruby/mx_truffleruby.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import os
1212
import pipes
1313
from os.path import join, exists, basename
14+
import re
1415
import shutil
1516
import sys
1617

@@ -48,6 +49,27 @@ def add_ext_suffix(name):
4849

4950
mx_subst.results_substitutions.register_with_arg('extsuffix', add_ext_suffix)
5051

52+
# From org.truffleruby.shared.Platform
53+
def get_cruby_arch():
54+
arch = mx.get_arch()
55+
if arch == 'amd64':
56+
return 'x86_64'
57+
elif arch == 'aarch64':
58+
return 'aarch64'
59+
else:
60+
raise Exception("Unknown platform " + arch)
61+
62+
mx_subst.results_substitutions.register_no_arg('cruby_arch', get_cruby_arch)
63+
64+
def get_truffleruby_abi_version():
65+
path = join(root, 'lib/cext/include/truffleruby/truffleruby-abi-version.h')
66+
with open(path, "r") as f:
67+
contents = f.read()
68+
m = re.search('"(.+)"', contents)
69+
return m.group(1)
70+
71+
mx_subst.results_substitutions.register_no_arg('truffleruby_abi_version', get_truffleruby_abi_version)
72+
5173
# Utilities
5274

5375
class VerboseMx:
@@ -118,10 +140,10 @@ def contents(self, result):
118140
if debug_args:
119141
jvm_args.extend(['-ea', '-esa'])
120142

121-
jvm_args.append('-Dorg.graalvm.language.ruby.home=' + root)
143+
bootstrap_home = mx.distribution('TRUFFLERUBY_BOOTSTRAP_HOME').get_output()
144+
jvm_args.append('-Dorg.graalvm.language.ruby.home=' + bootstrap_home)
122145

123-
libyarpbindings = list(mx.project('org.truffleruby.yarp.bindings').getArchivableResults())[0][0]
124-
jvm_args.append('-Dtruffleruby.libyarpbindings=' + libyarpbindings)
146+
jvm_args.append('-Dtruffleruby.repository=' + root)
125147

126148
main_class = 'org.truffleruby.launcher.RubyLauncher'
127149
ruby_options = [

mx.truffleruby/suite.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@
368368
"TRUFFLERUBY", # We need this jar to run extconf.rb
369369
"TRUFFLERUBY-LAUNCHER", # We need this jar to run extconf.rb
370370
"sulong:SULONG_NATIVE", # We need this jar to find the toolchain with Toolchain#getToolPath
371-
"org.truffleruby.yarp.bindings", # libyarpbindings.so
371+
"TRUFFLERUBY_BOOTSTRAP_HOME", # libyarpbindings.so, librubysignal.so
372372
],
373373
"license": ["EPL-2.0"],
374374
},
@@ -404,8 +404,8 @@
404404
"src/main/c/ripper/<extsuffix:ripper>",
405405
"src/main/c/syslog/<extsuffix:syslog>",
406406
"src/main/c/zlib/<extsuffix:zlib>",
407-
"lib/gems/gems/debug-1.7.1/lib/debug/<extsuffix:debug>",
408-
"lib/gems/gems/rbs-2.8.2/lib/<extsuffix:rbs_extension>",
407+
"src/main/c/debug/<extsuffix:debug>",
408+
"src/main/c/rbs/<extsuffix:rbs_extension>",
409409
],
410410
"license": [
411411
"EPL-2.0", # JRuby (we're choosing EPL out of EPL,GPL,LGPL)
@@ -667,19 +667,39 @@
667667
"maven": False,
668668
},
669669

670+
"TRUFFLERUBY_BOOTSTRAP_HOME": {
671+
"description": "TruffleRuby bootstrap home used by a minimal TruffleRuby to run extconf.rb of default & bundled gems C extensions",
672+
"native": True,
673+
"platformDependent": True,
674+
"layout": {
675+
"lib/": [
676+
"file:lib/json",
677+
"file:lib/mri",
678+
"file:lib/patches",
679+
"file:lib/truffle",
680+
"dependency:org.truffleruby.yarp.bindings",
681+
],
682+
"lib/cext/": [
683+
"file:lib/cext/*.rb",
684+
# libtruffleposix is handled specially in posix.rb to avoid a cyclic dependency between org.truffleruby.cext and TRUFFLERUBY-BOOTSTRAP-LAUNCHER
685+
"dependency:org.truffleruby.librubysignal",
686+
],
687+
"lib/cext/include/": [
688+
"file:lib/cext/include/*",
689+
],
690+
},
691+
"maven": False,
692+
},
693+
670694
"TRUFFLERUBY_GRAALVM_SUPPORT_PLATFORM_AGNOSTIC": {
671695
"description": "Platform-agnostic TruffleRuby home files",
672696
"fileListPurpose": 'native-image-resources',
673697
"native": True,
674698
"platformDependent": False,
675-
# The project org.truffleruby.cext touches lib/gems/gems/debug-1.7.1/ext
676-
# and lib/gems/extensions/$ARCH-$OS/$ABI/rbs-2.8.2/gem.build_complete.
677-
# This causes this layout distribution to be rebuilt even though nothing changes in the result.
678-
# To avoid that we force org.truffleruby.cext to complete first.
679-
"dependencies": ["org.truffleruby.cext"],
680699
"layout": {
681700
"lib/": [
682701
"file:lib/json",
702+
"file:lib/gems",
683703
"file:lib/mri",
684704
"file:lib/patches",
685705
"file:lib/truffle",
@@ -690,23 +710,6 @@
690710
"lib/cext/include/": [
691711
"file:lib/cext/include/*",
692712
],
693-
"lib/gems/": [
694-
{
695-
"source_type": "file",
696-
"path": "lib/gems/*",
697-
"exclude": [
698-
# The debug and rbs gems have native extensions.
699-
# Do not ship ext/ as it includes an unnecessary copy of the .so and intermediate files.
700-
# The .so in lib/ are copied in the platform-specific distribution.
701-
# <extsuffix:...> does not work in exclude, so use .* here (.{so,bundle} does not work either).
702-
"lib/gems/extensions",
703-
"lib/gems/gems/debug-1.7.1/ext",
704-
"lib/gems/gems/debug-1.7.1/lib/debug/debug.*",
705-
"lib/gems/gems/rbs-2.8.2/ext",
706-
"lib/gems/gems/rbs-2.8.2/lib/rbs_extension.*",
707-
],
708-
},
709-
],
710713
},
711714
"license": [
712715
"EPL-2.0", # JRuby (we're choosing EPL out of EPL,GPL,LGPL)
@@ -732,10 +735,15 @@
732735
"dependency:org.truffleruby.cext/src/main/c/cext-trampoline/<lib:trufflerubytrampoline>",
733736
"dependency:org.truffleruby.librubysignal",
734737
],
735-
# The platform-specific files from debug and rbs, see comment above
736-
"lib/gems/": "file:lib/gems/extensions",
737-
"lib/gems/gems/debug-1.7.1/lib/debug/": "dependency:org.truffleruby.cext/lib/gems/gems/debug-1.7.1/lib/debug/<extsuffix:debug>",
738-
"lib/gems/gems/rbs-2.8.2/lib/": "dependency:org.truffleruby.cext/lib/gems/gems/rbs-2.8.2/lib/<extsuffix:rbs_extension>",
738+
# Create the complete files to let RubyGems know the gems are fully built
739+
"lib/gems/extensions/<cruby_arch>-<os>/<truffleruby_abi_version>/debug-1.7.1/gem.build_complete": "string:",
740+
"lib/gems/extensions/<cruby_arch>-<os>/<truffleruby_abi_version>/rbs-2.8.2/gem.build_complete": "string:",
741+
"lib/gems/gems/debug-1.7.1/lib/debug/": [
742+
"dependency:org.truffleruby.cext/src/main/c/debug/<extsuffix:debug>",
743+
],
744+
"lib/gems/gems/rbs-2.8.2/lib/": [
745+
"dependency:org.truffleruby.cext/src/main/c/rbs/<extsuffix:rbs_extension>",
746+
],
739747
"lib/mri/": [
740748
"dependency:org.truffleruby.cext/src/main/c/bigdecimal/<extsuffix:bigdecimal>",
741749
"dependency:org.truffleruby.cext/src/main/c/date/<extsuffix:date_core>",
@@ -764,9 +772,9 @@
764772
},
765773

766774
"TRUFFLERUBY_GRAALVM_SUPPORT_NO_NI_RESOURCES": {
775+
"description": "TruffleRuby support distribution for the GraalVM, the contents is not included as native image resources.",
767776
"native": True,
768777
"platformDependent": True,
769-
"description": "TruffleRuby support distribution for the GraalVM, the contents is not included as native image resources.",
770778
"layout": {
771779
"./": [
772780
"file:CHANGELOG.md",

src/main/c/Makefile

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,15 @@ BASIC_EXTCONF_DEPS := $(BASIC_DEPS) $(RBCONFIG) $(MKMF)
3232
# However, if libtruffleruby is recompiled, there is no need to rebuild C extensions, so it's a order-only-prerequisite.
3333
EXTCONF_DEPS := $(BASIC_EXTCONF_DEPS) | $(LIBTRUFFLERUBY)
3434

35-
DEBUG_GEM := $(ROOT)/lib/gems/gems/debug-1.7.1
36-
DEBUG_GEM_EXT := $(DEBUG_GEM)/ext/debug
37-
DEBUG_GEM_EXT_SO := $(DEBUG_GEM_EXT)/debug.$(DLEXT)
38-
DEBUG_GEM_LIB_SO := $(DEBUG_GEM)/lib/debug/debug.$(DLEXT)
39-
40-
RBS_GEM := $(ROOT)/lib/gems/gems/rbs-2.8.2
41-
RBS_GEM_EXT := $(RBS_GEM)/ext/rbs_extension
42-
RBS_GEM_EXT_SO := $(RBS_GEM_EXT)/rbs_extension.$(DLEXT)
43-
RBS_GEM_LIB_SO := $(RBS_GEM)/lib/rbs_extension.$(DLEXT)
35+
DEBUG_GEM_EXT := $(ROOT)/lib/gems/gems/debug-1.7.1/ext/debug
36+
RBS_GEM_EXT := $(ROOT)/lib/gems/gems/rbs-2.8.2/ext/rbs_extension
4437

4538
IF_EXTCONF_FAIL := ( echo "`pwd`/extconf.rb failed:" 1>&2 && cat mkmf.log && false )
4639

4740
all: $(TRAMPOLINE) $(LIBTRUFFLERUBY) openssl/openssl.$(DLEXT) zlib/zlib.$(DLEXT) \
4841
psych/psych.$(DLEXT) ripper/ripper.$(DLEXT) syslog/syslog.$(DLEXT) nkf/nkf.$(DLEXT) \
4942
bigdecimal/bigdecimal.$(DLEXT) date/date_core.$(DLEXT) io-console/console.$(DLEXT) etc/etc.$(DLEXT) \
50-
rbconfig-sizeof/sizeof.$(DLEXT) $(DEBUG_GEM_LIB_SO) $(RBS_GEM_LIB_SO)
43+
rbconfig-sizeof/sizeof.$(DLEXT) debug/debug.$(DLEXT) rbs/rbs_extension.$(DLEXT)
5144

5245
clean: clean_cexts clean_truffleposix clean_trampoline
5346

@@ -70,8 +63,8 @@ clean_cexts:
7063
$(Q) rm -f io-console/Makefile io-console/*.o io-console/console.$(DLEXT)
7164
$(Q) rm -f etc/Makefile etc/*.o etc/etc.$(DLEXT) etc/constdefs.h
7265
$(Q) rm -f rbconfig-sizeof/Makefile rbconfig-sizeof/*.o rbconfig-sizeof/sizeof.$(DLEXT)
73-
$(Q) rm -f $(DEBUG_GEM_EXT)/Makefile $(DEBUG_GEM_EXT)/*.o $(DEBUG_GEM_EXT_SO) $(DEBUG_GEM_LIB_SO)
74-
$(Q) rm -f $(RBS_GEM_EXT)/Makefile $(RBS_GEM_EXT)/*.o $(RBS_GEM_EXT_SO) $(RBS_GEM_LIB_SO)
66+
$(Q) rm -f debug/Makefile debug/*.o debug/debug.$(DLEXT)
67+
$(Q) rm -f rbs/Makefile rbs/*.o rbs/rbs_extension.$(DLEXT)
7568

7669
# spawn-helper
7770
$(SPAWN_HELPER): spawn-helper/Makefile spawn-helper/spawn-helper.c
@@ -178,23 +171,24 @@ psych/psych.$(DLEXT): psych/Makefile psych/*.c psych/*.h
178171
$(Q) cd psych && $(MAKE) $(MKMF_MAKEFILE_SUBPROCESS_FLAGS)
179172

180173
# debug bundled gem
181-
$(DEBUG_GEM_EXT)/Makefile: $(DEBUG_GEM_EXT)/extconf.rb $(EXTCONF_DEPS)
182-
$(Q) cd $(DEBUG_GEM_EXT) && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
174+
debug/extconf.rb: $(DEBUG_GEM_EXT)/extconf.rb $(DEBUG_GEM_EXT)/*.c
175+
$(Q) mkdir -p debug
176+
$(Q) cd debug && cp $(DEBUG_GEM_EXT)/*.{rb,c} .
183177

184-
$(DEBUG_GEM_EXT_SO): $(DEBUG_GEM_EXT)/Makefile $(DEBUG_GEM_EXT)/*.c
185-
$(Q) cd $(DEBUG_GEM_EXT) && $(MAKE) $(MKMF_MAKEFILE_SUBPROCESS_FLAGS)
178+
debug/Makefile: debug/extconf.rb $(EXTCONF_DEPS)
179+
$(Q) cd debug && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
186180

187-
$(DEBUG_GEM_LIB_SO): $(DEBUG_GEM_EXT_SO)
188-
$(Q) cp $< $@
189-
$(Q) $(RUBY) $(ROOT)/tool/mark-gem-extension-as-built.rb debug
181+
debug/debug.$(DLEXT): debug/Makefile
182+
$(Q) cd debug && $(MAKE) $(MKMF_MAKEFILE_SUBPROCESS_FLAGS)
190183

191184
# rbs bundled gem
192-
$(RBS_GEM_EXT)/Makefile: $(RBS_GEM_EXT)/extconf.rb $(EXTCONF_DEPS)
193-
$(Q) cd $(RBS_GEM_EXT) && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
185+
rbs/extconf.rb: $(RBS_GEM_EXT)/extconf.rb $(RBS_GEM_EXT)/*.c $(RBS_GEM_EXT)/*.h
186+
$(Q) mkdir -p rbs
187+
$(Q) cd rbs && cp $(RBS_GEM_EXT)/*.{rb,c,h} .
188+
189+
rbs/Makefile: rbs/extconf.rb $(EXTCONF_DEPS)
190+
$(Q) cd rbs && $(RUBY) extconf.rb || $(IF_EXTCONF_FAIL)
194191

195-
$(RBS_GEM_EXT_SO): $(RBS_GEM_EXT)/Makefile $(RBS_GEM_EXT)/*.c $(RBS_GEM_EXT)/*.h
196-
$(Q) cd $(RBS_GEM_EXT) && $(MAKE) $(MKMF_MAKEFILE_SUBPROCESS_FLAGS)
192+
rbs/rbs_extension.$(DLEXT): rbs/Makefile
193+
$(Q) cd rbs && $(MAKE) $(MKMF_MAKEFILE_SUBPROCESS_FLAGS)
197194

198-
$(RBS_GEM_LIB_SO): $(RBS_GEM_EXT_SO)
199-
$(Q) cp $< $@
200-
$(Q) $(RUBY) $(ROOT)/tool/mark-gem-extension-as-built.rb rbs

src/main/c/rubysignal/src/rubysignal.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@
88
* GNU Lesser General Public License version 2.1.
99
*/
1010
#include "org_truffleruby_signal_LibRubySignal.h"
11+
#include <locale.h>
1112
#include <pthread.h>
1213
#include <signal.h>
1314
#include <unistd.h>
1415
#include <sys/syscall.h>
1516

1617
_Static_assert(sizeof(pthread_t) == sizeof(jlong), "Expected sizeof(pthread_t) == sizeof(jlong)");
1718

19+
JNIEXPORT void JNICALL Java_org_truffleruby_signal_LibRubySignal_setupLocale(JNIEnv *env, jclass clazz) {
20+
setlocale(LC_ALL, "C");
21+
setlocale(LC_CTYPE, "");
22+
}
23+
1824
static void empty_handler(int sig) {
1925
}
2026

src/main/java/org/truffleruby/RubyLanguage.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -816,17 +816,12 @@ private TruffleFile searchRubyHome(Env env) {
816816
private boolean isRubyHome(TruffleFile path) {
817817
var lib = path.resolve("lib");
818818
return lib.resolve("truffle").isDirectory() &&
819-
lib.resolve("gems").isDirectory() &&
819+
(options.BUILDING_CORE_CEXTS || lib.resolve("gems").isDirectory()) &&
820820
lib.resolve("patches").isDirectory();
821821
}
822822

823823
private void loadLibYARPBindings() {
824-
String libyarpbindings;
825-
if (options.BUILDING_CORE_CEXTS) {
826-
libyarpbindings = System.getProperty("truffleruby.libyarpbindings");
827-
} else {
828-
libyarpbindings = getRubyHome() + "/lib/libyarpbindings" + Platform.LIB_SUFFIX;
829-
}
824+
String libyarpbindings = getRubyHome() + "/lib/libyarpbindings" + Platform.LIB_SUFFIX;
830825
Parser.loadLibrary(libyarpbindings);
831826
}
832827

0 commit comments

Comments
 (0)