Skip to content

Use platform bit width for J/j pack directive#7581

Merged
headius merged 1 commit intojruby:jruby-9.3from
headius:pack_j_32bit
Jan 20, 2023
Merged

Use platform bit width for J/j pack directive#7581
headius merged 1 commit intojruby:jruby-9.3from
headius:pack_j_32bit

Conversation

@headius
Copy link
Member

@headius headius commented Jan 13, 2023

These pack directives are intended to produce an encoded signed or unsigned int of the width of a native pointer. Regardless of whether JRuby treats all platforms as 64-bit (due to JVM's 64-bit nature) we should probably encode these values according to the host platform's bit depth.

Fixes #7542

I do not have a 32-bit platform on which to test this, but hacking JRuby and mspec to pretend the system is 32-bit yields passing specs for the 32-bit logic:

diff --git a/core/src/main/java/org/jruby/platform/Platform.java b/core/src/main/java/org/jruby/platform/Platform.java
index 1b292498ce..2be4f03bf1 100644
--- a/core/src/main/java/org/jruby/platform/Platform.java
+++ b/core/src/main/java/org/jruby/platform/Platform.java
@@ -126,7 +126,7 @@ public abstract class Platform {
     public static final int BIG_ENDIAN = 4321;
     public static final int LITTLE_ENDIAN = 1234;
     public static final int BYTE_ORDER = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN) ? BIG_ENDIAN : LITTLE_ENDIAN;
-    public static final int BIT_WIDTH = jnr.ffi.Platform.getNativePlatform().is32Bit() ? 32 : 64;
+    public static final int BIT_WIDTH = 32; //jnr.ffi.Platform.getNativePlatform().is32Bit() ? 32 : 64;
 
     public static final boolean IS_GCJ = JVM.equals(GCJ);
     public static final boolean IS_J9 = JVM.equals(OPENJ9) || JVM.equals(IBM);
diff --git a/spec/mspec/lib/mspec/guards/platform.rb b/spec/mspec/lib/mspec/guards/platform.rb
index 2d5c2de6b6..7076e8c62f 100644
--- a/spec/mspec/lib/mspec/guards/platform.rb
+++ b/spec/mspec/lib/mspec/guards/platform.rb
@@ -53,7 +53,7 @@ class PlatformGuard < SpecGuard
 
   POINTER_SIZE = begin
     require 'rbconfig/sizeof'
-    RbConfig::SIZEOF["void*"] * 8
+    RbConfig::SIZEOF["void*"] * 4
   rescue LoadError
     WORD_SIZE
   end

@headius headius added this to the JRuby 9.3.10.0 milestone Jan 13, 2023
These pack directives are intended to produce an encoded signed or
unsigned int of the width of a native pointer. Regardless of
whether JRuby treats all platforms as 64-bit (due to JVM's 64-bit
nature) we should probably encode these values according to the
host platform's bit depth.

Fixes jruby#7542
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant