[Python-checkins] bpo-45061: Detect refcount bug on empty string singleton (GH-28504)

Victor Stinner vstinner at python.org
Wed Sep 22 05:24:25 EDT 2021


Hi,

I'm no longer sure why I did this change. So I just reverted it:
https://github.com/python/cpython/pull/28516/files

Victor

On Wed, Sep 22, 2021 at 9:44 AM Marc-Andre Lemburg <mal at egenix.com> wrote:
>
> On 21.09.2021 23:43, vstinner wrote:
> > bpo-45061: Detect refcount bug on empty string singleton (GH-28504)
> >
> > Detect refcount bugs in C extensions when the empty Unicode string
> > singleton is destroyed by mistake.
> >
> > * Move forward declarations to the top of unicodeobject.c.
> > * Simplifiy unicode_is_singleton().
> >
> > @@ -1982,11 +1994,8 @@ unicode_is_singleton(PyObject *unicode)
> >      if (unicode == state->empty_string) {
> >          return 1;
> >      }
> > -    PyASCIIObject *ascii = (PyASCIIObject *)unicode;
> > -    if (ascii->state.kind != PyUnicode_WCHAR_KIND && ascii->length == 1)
> > -    {
> > -        Py_UCS4 ch = PyUnicode_READ_CHAR(unicode, 0);
> > -        if (ch < 256 && state->latin1[ch] == unicode) {
> > +    for (Py_ssize_t i = 0; i < 256; i++) {
> > +        if (unicode == state->latin1[i]) {
> >              return 1;
> >          }
> >      }
>
> Why are you replacing a single pointer comparison with a loop over
> 256 comparisons ?
>
> That doesn't strike me as a simplification. It's just takes longer.
>
> --
> Marc-Andre Lemburg
> eGenix.com
>
> Professional Python Services directly from the Experts (#1, Sep 22 2021)
> >>> Python Projects, Coaching and Support ...    https://www.egenix.com/
> >>> Python Product Development ...        https://consulting.egenix.com/
> ________________________________________________________________________
>
> ::: We implement business ideas - efficiently in both time and costs :::
>
>    eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
>     D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
>            Registered at Amtsgericht Duesseldorf: HRB 46611
>                https://www.egenix.com/company/contact/
>                      https://www.malemburg.com/
>


-- 
Night gathers, and now my watch begins. It shall not end until my death.


More information about the Python-checkins mailing list