Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bpo-40170: Hide implementation detail of Py_TRASHCAN_BEGIN macro #23235

Merged
merged 6 commits into from
Nov 24, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,11 @@ New Features
* The :c:func:`PyType_GetSlot` function can accept static types.
(Contributed by Hai Shi and Petr Viktorin in :issue:`41073`.)

* The ``Py_TRASHCAN_BEGIN`` macro no longer accesses PyTypeObject attributes,
but now can get the condition by calling the new private
:c:func:`_PyTrash_cond()` function which hides implementation details.
(Contributed by Hai Shi in :issue:`40170`.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that it's worth it to mention in What's New in Python 3.10. End users will not notice and don't care ;-)

Copy link
Member Author

@shihai1991 shihai1991 Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed.
I decided add this news because I saw you have written the description info of _PyTrash_begin() and _PyTrash_end() in whatsnew. Lol~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote a changelog entry, but nothing in What's New in Python 3.9 or What's New in Python 3.10, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I saw this info in https://github.com/python/cpython/blob/master/Misc/NEWS.d/3.9.0a5.rst.
Looks like I confused the news file with relese file : (, sorry.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem.

I consider that "What's New in Python X.Y" should be short and only describe the public API, but the Changelog should describe every single change and private functions can be mentioned there.

Copy link
Member Author

@shihai1991 shihai1991 Nov 13, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, This great. I am very confused when I start write the whatsnew file in the first time.
It's more like a double copy operation.

In fact, I don't know how release manager to archieve those change log.
My simple thought: Maybe we can create some labels to tag what's info should be added in release file or not. When release manager archive those change log, those taged changeinfo chould be archieved in release file automatically.

If this thought have any value, I can add this in my TODO list. Lol~



Porting to Python 3.10
----------------------
Expand Down
5 changes: 3 additions & 2 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ struct _ts;
/* Python 3.9 private API, invoked by the macros below. */
PyAPI_FUNC(int) _PyTrash_begin(struct _ts *tstate, PyObject *op);
PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
/* Python 3.10 private API, invoked by the macros below. */
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved
PyAPI_FUNC(int) _PyTrash_cond(void *op_raw, void *dealloc);
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved

#define PyTrash_UNWIND_LEVEL 50

Expand All @@ -537,8 +539,7 @@ PyAPI_FUNC(void) _PyTrash_end(struct _ts *tstate);
} while (0);

#define Py_TRASHCAN_BEGIN(op, dealloc) \
Py_TRASHCAN_BEGIN_CONDITION(op, \
Py_TYPE(op)->tp_dealloc == (destructor)(dealloc))
Py_TRASHCAN_BEGIN_CONDITION(op, _PyTrash_cond(op, dealloc));
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved

/* For backwards compatibility, these macros enable the trashcan
* unconditionally */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The ``Py_TRASHCAN_BEGIN`` macro no longer accesses PyTypeObject attributes,
but now can get the condition by calling the new private
:c:func:`_PyTrash_cond()` function which hides implementation details.
9 changes: 9 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2134,6 +2134,15 @@ _PyTrash_end(PyThreadState *tstate)
}


int
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment explaining that it is used by the Py_TRASHCAN_BEGIN macro.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, updated.

_PyTrash_cond(void *op_raw, void *dealloc)
{
PyObject *op = _PyObject_CAST(op_raw);
PyTypeObject *tp = Py_TYPE(op);
return tp->tp_dealloc == (destructor)dealloc;
shihai1991 marked this conversation as resolved.
Show resolved Hide resolved
}


void _Py_NO_RETURN
_PyObject_AssertFailed(PyObject *obj, const char *expr, const char *msg,
const char *file, int line, const char *function)
Expand Down