Timsort in Cpython

Ian Kelly ian.g.kelly at gmail.com
Sun Jun 16 16:33:17 EDT 2013


On Sat, Jun 15, 2013 at 10:05 PM,  <alphonse23 at gmail.com> wrote:
> Yes I've read it. Very interesting read. There are other resources too online that make it very clear, for instance the wikipedia articles is pretty good.
>
> Though, if anyone would be interested in helping me out further -- though by all means, I'm not lazy, I can figure it myself. But, I wanted to pass in variables into listsort and watch timsort work line by line in gdb.
>
> listsort(PyListObject *self, PyObject *args, PyObject *kwds)
>
> I've never worked with Cpython source before, but it looks like PyObject is just some type of general strut.. I think anyway. How does python represent a list of ints in source? and what are the two second arguments for, assuming the first is the list strut.

A PyObject* generally references any Python object.  The subtype
PyListObject* more specifically references a Python list.  The above
signature corresponds to this Python function signature:

    def listsort(self, *args, **kwds):

The first argument self is the list object to be operated on.  The
second argument args is a Python tuple containing any other positional
arguments that were passed into the method.  The third argument kwds
is a Python dict containing any keyword arguments that were passed
into the method.



More information about the Python-list mailing list