Skip to content

Commit ec6341f

Browse files
committed
Fixed getBI code to support Rakudo allomorphs.
It's still somewhat of a hack, but at least it works again.
1 parent 4796e92 commit ec6341f

File tree

1 file changed

+37
-5
lines changed
  • src/vm/jvm/runtime/org/perl6/nqp/runtime

1 file changed

+37
-5
lines changed

src/vm/jvm/runtime/org/perl6/nqp/runtime/Ops.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44
import java.io.IOException;
55
import java.io.InputStream;
66
import java.io.UnsupportedEncodingException;
7+
import java.lang.reflect.Field;
8+
import java.lang.reflect.Method;
79
import java.lang.invoke.MethodHandle;
810
import java.lang.invoke.MethodHandles;
911
import java.lang.invoke.MethodType;
1012
import java.lang.ProcessBuilder.Redirect;
1113
import java.lang.Thread;
14+
import java.lang.NoSuchFieldException;
1215
import java.math.BigDecimal;
1316
import java.math.BigInteger;
1417
import java.math.RoundingMode;
@@ -29,10 +32,12 @@
2932
import java.security.MessageDigest;
3033
import java.security.NoSuchAlgorithmException;
3134
import java.util.AbstractMap;
35+
import java.util.Arrays;
3236
import java.util.ArrayList;
3337
import java.util.Collections;
3438
import java.util.EnumSet;
3539
import java.util.HashMap;
40+
import java.util.Iterator;
3641
import java.util.List;
3742
import java.util.Map;
3843
import java.util.Properties;
@@ -4848,10 +4853,10 @@ public static long getpid(ThreadContext tc) {
48484853
*/
48494854
try {
48504855
java.lang.management.RuntimeMXBean runtime = java.lang.management.ManagementFactory.getRuntimeMXBean();
4851-
java.lang.reflect.Field jvm = runtime.getClass().getDeclaredField("jvm");
4856+
Field jvm = runtime.getClass().getDeclaredField("jvm");
48524857
jvm.setAccessible(true);
48534858
Object mgmt = jvm.get(runtime);
4854-
java.lang.reflect.Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
4859+
Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
48554860
pid_method.setAccessible(true);
48564861
return (Integer)pid_method.invoke(mgmt);
48574862
}
@@ -5942,9 +5947,36 @@ public static String join_literal(String[] parts) {
59425947
private static BigInteger getBI(ThreadContext tc, SixModelObject obj) {
59435948
if (obj instanceof P6bigintInstance)
59445949
return ((P6bigintInstance)obj).value;
5945-
/* What follows is a bit of a hack, relying on the first field being the
5946-
* big integer. */
5947-
obj.get_attribute_native(tc, null, null, 0);
5950+
/* What follows is a bit of a hack.
5951+
* Unlike previously, we cannot rely on field_0 being the bigint,
5952+
* because we might have an allomorph coming in.
5953+
* To correctly handle that case we need to find the field on obj
5954+
* which contains a BigInteger in field_0, in case we failed to
5955+
* find the BigInteger in field_0 of obj.
5956+
*/
5957+
try {
5958+
obj.get_attribute_native(tc, null, null, 0);
5959+
}
5960+
catch (RuntimeException RTE) {
5961+
List<Field> interestingFields = new ArrayList<Field>(Arrays.asList(obj.getClass().getFields()));
5962+
for( Iterator<Field> it = interestingFields.iterator(); it.hasNext(); ) {
5963+
if( !it.next().getName().startsWith("field_") ) {
5964+
it.remove();
5965+
}
5966+
}
5967+
5968+
for( Field field : interestingFields ) {
5969+
try {
5970+
SixModelObject curAttr = (SixModelObject) field.get(obj);
5971+
try {
5972+
curAttr.get_attribute_native(tc, null, null, 0);
5973+
} catch (RuntimeException innerRTE) {
5974+
}
5975+
} catch(IllegalAccessException iae) {
5976+
// this really shouldn't happen, but...
5977+
}
5978+
}
5979+
}
59485980
return (BigInteger)tc.native_j;
59495981
}
59505982

0 commit comments

Comments
 (0)