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

Use Py_NewRef & Py_XNewRef where applicable #86453

Closed
Jongy mannequin opened this issue Nov 8, 2020 · 6 comments
Closed

Use Py_NewRef & Py_XNewRef where applicable #86453

Jongy mannequin opened this issue Nov 8, 2020 · 6 comments
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@Jongy
Copy link
Mannequin

Jongy mannequin commented Nov 8, 2020

BPO 42287
Nosy @vstinner, @Jongy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2020-11-17.12:01:37.010>
created_at = <Date 2020-11-08.00:31:36.255>
labels = ['interpreter-core', 'type-feature', 'invalid', '3.10']
title = 'Use Py_NewRef & Py_XNewRef where applicable'
updated_at = <Date 2020-11-17.12:01:37.009>
user = 'https://github.com/Jongy'

bugs.python.org fields:

activity = <Date 2020-11-17.12:01:37.009>
actor = 'vstinner'
assignee = 'none'
closed = True
closed_date = <Date 2020-11-17.12:01:37.010>
closer = 'vstinner'
components = ['Interpreter Core']
creation = <Date 2020-11-08.00:31:36.255>
creator = 'Yonatan Goldschmidt'
dependencies = []
files = []
hgrepos = []
issue_num = 42287
keywords = []
message_count = 4.0
messages = ['380531', '380576', '381199', '381226']
nosy_count = 2.0
nosy_names = ['vstinner', 'Yonatan Goldschmidt']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue42287'
versions = ['Python 3.10']

@Jongy
Copy link
Mannequin Author

Jongy mannequin commented Nov 8, 2020

Following https://bugs.python.org/issue42262, I think it'd be nice to convert existing C code to use the more concise Py_NewRef() and Py_XNewRef() where possible. Increases readability and less bug prone.

Opening this new issue to track the conversion.

@Jongy Jongy mannequin added 3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Nov 8, 2020
@vstinner
Copy link
Member

vstinner commented Nov 9, 2020

Following https://bugs.python.org/issue42262, I think it'd be nice to convert existing C code to use the more concise Py_NewRef() and Py_XNewRef() where possible. Increases readability and less bug prone.

In general, we don't accept changes which are only coding style changes.

I don't see how Py_NewRef() or Py_XNewRef() is less error prone. In my experience, any change is more likely to introduce new bugs than leaving the code unchanged. See #23170 for a concrete case of a PR which converts code to Py_NewRef() / Py_XNewRef(): the PR introduced bugs (in early versions of the PR).

@Jongy
Copy link
Mannequin Author

Jongy mannequin commented Nov 17, 2020

I don't see how Py_NewRef() or Py_XNewRef() is less error prone. In my experience, any change is more likely to introduce new bugs than leaving the code unchanged.

Agree that inserting changes opens a door to introducing bugs.

However, the "end state" of having Py_NewRef() is desired, I think. It is more concise. It is less error prone because where you use it, you literally can't miss the "increment refcount" part when stealing a reference from another source. Py_INCREF has to come before/after stealing a ref, leaving room for error, IMHO.

In general, we don't accept changes which are only coding style changes.

Didn't know that. Well if that's the case, then obviously there is no reason to work specifically on this conversion.

@vstinner
Copy link
Member

Didn't know that. Well if that's the case, then obviously there is no reason to work specifically on this conversion.

If people want to use Py_NewRef(), I suggest to do while modifying the code for another reason. But not propose PRs just to use Py_NewRef().

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@erlend-aasland
Copy link
Contributor

Superseded by #99300

@vstinner
Copy link
Member

Well, I change my mind since 2020 :-) I used Py_NewRef() in more and more code and now I can see that it makes the code easier to understand and easier to maintain.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.10 only security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants