Message3222

Author arnebef
Recipients arnebef, r_walter
Date 2008-06-03.21:56:43
SpamBayes Score 0.015911771
Marked as misclassified No
Message-id <1212530205.08.0.536907194776.issue1835099@psf.upfronthosting.co.za>
In-reply-to
Content
Ok, this should be a better patch (not beautiful, but should work).

The problem is in merge_lo/merge_hi in mergestate. These have been
copied from listobject.c
(http://svn.python.org/projects/python/trunk/Objects/listobject.c). 

In listobject.c there are these lines:
static Py_ssize_t merge_lo(... {
  <snip>
  --na;
  if (na == 0)
    goto Succeed;
  <snip>
  Succeed:
    result = 0;
  Fail:
    if (nb)
      memcpy(dest-(nb-1), baseb, nb * sizeof(PyObject*));
    return result;
}

Because of gotos fall through, when Succeed is jumped, Fail is also
performed.

In MergeState it has been convert to these lines:
void merge_lo(...) {
  <snip>
  --nb;
  if (nb == 0)
    return;
  <snip>
  try { ... }
  finally {
    if (na != 0)
      System.arraycopy(this.a, pa, this.kvdata, dest, na);
  }
}

Basically, in the C implementation, Fail will also be performed when
Succeed is performed, while in the Java implementation, the finally tag
will never be entered if nb == 1 when starting. This means that
this.kvdata[pa] = this.kvdata[pb], and the sort is not a sort anymore ;)

Patch attached (sorterror_updated)
History
Date User Action Args
2008-06-03 21:56:45arnebefsetspambayes_score: 0.0159118 -> 0.015911771
messageid: <1212530205.08.0.536907194776.issue1835099@psf.upfronthosting.co.za>
2008-06-03 21:56:45arnebefsetspambayes_score: 0.0159118 -> 0.0159118
recipients: + arnebef, r_walter
2008-06-03 21:56:44arnebeflinkissue1835099 messages
2008-06-03 21:56:44arnebefcreate