Skip to content

Commit 687efcc

Browse files
committed
Fix: negative factor on sequence always returns empty sequence.
1 parent 6aa5c76 commit 687efcc

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/foreign/TruffleObjectBuiltins.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ static Object doForeignArray(Object left, Object right,
315315
Object[] repeatedData = new Object[Math.max(0, Math.multiplyExact(unpackForeignArray.length, rightInt))];
316316

317317
// repeat data
318-
for (int i = 0; i < unpackForeignArray.length; i++) {
318+
for (int i = 0; i < repeatedData.length; i++) {
319319
repeatedData[i] = unpackForeignArray[i % rightInt];
320320
}
321321

@@ -340,12 +340,40 @@ static Object doForeignArrayForeignBoolean(Object left, Object right,
340340
}
341341
}
342342

343+
@SuppressWarnings("unused")
344+
@Specialization(insertBefore = "doGeneric", guards = {"lib.hasArrayElements(left)", "isNegativeNumber(lib, right)"})
345+
static Object doForeignArrayNegativeMult(Object left, Object right,
346+
@Cached PythonObjectFactory factory,
347+
@CachedLibrary(limit = "3") InteropLibrary lib) {
348+
349+
return factory.createList();
350+
}
351+
343352
@SuppressWarnings("unused")
344353
@Specialization(insertBefore = "doGeneric", guards = {"!lib.fitsInDouble(left)", "!lib.fitsInLong(left)", "!lib.isBoolean(left)", "!lib.hasArrayElements(left)"})
345354
PNotImplemented doForeignGeneric(Object left, Object right,
346355
@CachedLibrary(limit = "3") InteropLibrary lib) {
347356
return PNotImplemented.NOT_IMPLEMENTED;
348357
}
358+
359+
protected static boolean isNegativeNumber(InteropLibrary lib, Object right) {
360+
long val = 0;
361+
try {
362+
if (lib.fitsInByte(right)) {
363+
val = lib.asByte(right);
364+
} else if (lib.fitsInShort(right)) {
365+
val = lib.asShort(right);
366+
} else if (lib.fitsInInt(right)) {
367+
val = lib.asInt(right);
368+
} else if (lib.fitsInLong(right)) {
369+
val = lib.asLong(right);
370+
}
371+
return val < 0;
372+
} catch (UnsupportedMessageException e) {
373+
// fall through
374+
}
375+
return false;
376+
}
349377
}
350378

351379
@Builtin(name = __RMUL__, minNumOfPositionalArgs = 2)

0 commit comments

Comments
 (0)