[Checkins] [zopefoundation/zope.proxy] 43814c: Simplify getting the char* in get/setattro for cla...

GitHub noreply at github.com
Tue Nov 7 17:27:10 CET 2017


  Branch: refs/heads/master
  Home:   https://github.com/zopefoundation/zope.proxy
  Commit: 43814c7caaa0c377dac4f06067080d7916fa3980
      https://github.com/zopefoundation/zope.proxy/commit/43814c7caaa0c377dac4f06067080d7916fa3980
  Author: Jason Madden <jamadden at gmail.com>
  Date:   2017-11-07 (Tue, 07 Nov 2017)

  Changed paths:
    M CHANGES.rst
    M src/zope/proxy/_zope_proxy_proxy.c

  Log Message:
  -----------
  Simplify getting the char* in get/setattro for clarity and performance

Under Python 2, we were doing
PyUnicode_check->PyUnicode_AsEncodedString->PyString_Check->PyString_ASSTRING.

This can be simplified to PyString_AsString(). Internally it does the
same unicode check if needed. It produces a better error message if
the object is not a string or unicode. It is able to use the *cached*
byte string, and it doesn't allocate a new object. Because we don't
allocate a new object (sometimes) anymore, the extra INCREF/DECREF can
go away. We're also able to drop one type check.

Under Python 3, we were doing PyUnicode_Check->PyUnicode_AsUTF8String ->
PyBytes_AS_STRING. This can be simified to PyUnicode_AsUTF8. This
avoids an intermediate object and can use the cached byte string. We
can also drop the extra INCREF/DECREF since we don't ever have a new
object.

Python 2 docs claimed that the underlying tp_getattro slots need a
string object, but the unicode->string handling is done internally in
Python's PyObject_GetAttr now, AFAICS. (It's difficult to get a
unicode object in to these methods in the first place; someone must be
explicitly calling the __getattribute__ dunder method.)


  Commit: 2602ed62388af8a1ed59e67cdcdd84d35fa9d72a
      https://github.com/zopefoundation/zope.proxy/commit/2602ed62388af8a1ed59e67cdcdd84d35fa9d72a
  Author: Jason Madden <jason+github at nextthought.com>
  Date:   2017-11-07 (Tue, 07 Nov 2017)

  Changed paths:
    M CHANGES.rst
    M src/zope/proxy/_zope_proxy_proxy.c

  Log Message:
  -----------
  Merge pull request #25 from zopefoundation/unicode_simplification

Simplify getting the char* in get/setattro for clarity and performance


Compare: https://github.com/zopefoundation/zope.proxy/compare/c155a0ffe294...2602ed62388a


More information about the checkins mailing list