Hi Thomas, On 26 November 2016 at 03:32, Thomas Conway <drt...@gmail.com> wrote: > I realise this isn't exactly a pypy specific problem, by the standard array > module doesn't provide sort() on arrays.
I fear it's not PyPy's place to add such new methods to standard Python modules. You'd need to go to CPython and discuss the issue with them---which is not really a fun process imho. However, here are a few paths: * First, do you really need the array module? If you use a list containing only signed, machine-sized integers, then that list is represented in PyPy as compactly as an array of the 'l' type. It won't work if you really need more compact arrays, but if you don't, then one solution to your problem is simply to use lists and not arrays in the first place. * Or, use cffi to call qsort(). This is simpler (and most probably faster) than writing the sort in pure Python. It works with an array object from the array module, or anything supporting the buffer interface: ``lib.qsort(ffi.from_buffer(my_array), more_args...)``. You'd need to use the ``set_source()`` mode of CFFI in order to write an efficient comparison function in C to pass as argument. * (Additionally, you can use cffi's ``ffi.new("int[]", length)`` in the first place instead of the array module, as it is similar but more flexible: see http://cffi.readthedocs.io/en/latest/overview.html#struct-array-example-minimal-in-line . This does not really change anything though.) * The above seem like more general solutions than adding a sort method to the array module. However, if you really want to do that, then maybe create a function ``__pypy__.sort_buffer()`` instead, able to sort a buffer of integers of some size; it would not be on the array module specifically, and clearly it would be a pypy extension. A bientôt, Armin. _______________________________________________ pypy-dev mailing list pypy-dev@python.org https://mail.python.org/mailman/listinfo/pypy-dev