New submission from Neil Schemenauer <nas-pyt...@arctrix.com>:

My long term goal is to make it possible to make PyObject an opaque structure.  
Obviously that would break nearly every 3rd party extension at this point.  
However, to allow freedom on certain interpreter implementation strategies, it 
is helpful if code does not access ob_type, ob_refcnt and ob_size directly.  
Cleaning up core Python is not too hard.

There is closed bug #26824 which proposed a similar change.  There was two main 
issues with that patch.  One, it causes a fair amount of code churn.  This 
patch does that too.  Second, replace ob->ob_type with Py_TYPE(ob) adds an 
extra type-cast to PyObject*.  That's not good.

In this patch, I introduce Py_TP() as a non-typecast version of Py_TYPE().  I 
think the name is nice as it is short and matches the struct field prefix.

This change overlaps with Victor's proposed %t or %T format code change.  The 
code churn is mostly caused by code that does ob->ob_type->tp_name.  I'm not 
against the format code idea but personally I think trying to remove borrowed 
references is a difficult problem and it should not hold up the relatively 
simple task of allowing PyObject to be opaque.

Also, I doesn't see any immediate need to make PyTypeObject opaque.  The tp_* 
are used everywhere and so making access macros or functions for those would be 
hugely disruptive.  PyTypeObject is already opaque for the limited API.  I 
think that's good enough for now.

If this change gets accepted, I have follow-up patches to fix access to 
ob_refcnt and ob_size.  Those are much smaller patches since those fields are 
not often accessed.

----------
components: Interpreter Core
files: py_tp_macro.txt
keywords: needs review, patch
messages: 325482
nosy: nascheme, serhiy.storchaka, vstinner
priority: normal
severity: normal
stage: patch review
status: open
title: Do not access ob_type directly, introduce Py_TP
type: enhancement
Added file: https://bugs.python.org/file47806/py_tp_macro.txt

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34704>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to