mmap extended slicing ignores the step; negative steps raise java.lang.IndexOutOfBoundsException

Ouverte
#1,367 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
64/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java, python
Domaine
backend

Piste de recherche

Start by running the three-line reproduction script on GraalPy and comparing it with CPython's output. The payload names no source files, so locate the mmap implementation by searching for the slice handling. CPython's test_mmap.MmapTests.test_extended_getslice is the target. Done when extended slices with positive and negative steps match bytearray and the negative-step case no longer raises a Java IndexOutOfBoundsException.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

I found this while benchmarking the conformance of alternative Python implementations against CPython: the same standard library cases and selected CPython tests run on CPython, PyPy, GraalPy and RustPython.

Reading a mmap.mmap slice with a step other than 1 returns the contiguous bytes instead of every n-th byte. A negative step raises a Java IndexOutOfBoundsException that is not catchable as a Python exception. mmap objects are documented to behave like bytearray, and CPython's test_mmap.MmapTests.test_extended_getslice covers this; it fails on GraalPy.

Reproduction
import mmap

data = bytes(range(10))
region = mmap.mmap(-1, len(data))
region[:] = data
print(region[::2].hex(), data[::2].hex())
print(region[1:7:3].hex(), data[1:7:3].hex())
print(region[::-1].hex(), data[::-1].hex())

CPython 3.12.15:

0002040608 0002040608
0104 0104
09080706050403020100 09080706050403020100

GraalPy:

0001020304 0002040608
0102 0104
java.lang.IndexOutOfBoundsException

The length of the result is right; the step is not applied. Assigning to an extended slice (region[::2] = b"xyz") works.

Versions
  • GraalPy 25.2.4 Community (Python 3.12.8), Linux x86-64 and macOS aarch64 standalone builds
  • GraalPy 25.6.5 Community (Python 3.13.14), macOS aarch64 standalone build

This report was drafted with the help of AI. The reproductions were run on the GraalPy versions listed above, and on CPython 3.12.15 for the expected output.

Langage dominant
Python
Étoiles
1.7k
Forks
167
Merge moyen
3 j 11 h
PR mergées (30 j)
68

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de oracle/graalpython

Toutes les issues de oracle/graalpython

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.