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

Fix the pydebug with trace refs and count_allocs for python > 3.7 #1334

Merged
merged 1 commit into from Dec 25, 2020

Conversation

cecini
Copy link
Contributor

@cecini cecini commented Dec 21, 2020

There is some change for the trace refs . So fix it .
Since COUNT_ALLOCS used rarely, leave it unimpl now.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

I have a couple of questions... see my other comments...

build.rs Outdated
Comment on lines 245 to 246
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }
Copy link
Member

Choose a reason for hiding this comment

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

Dead code?

Suggested change
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }

Copy link
Contributor Author

@cecini cecini Dec 21, 2020

Choose a reason for hiding this comment

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

Since COUNT_ALLOCS used rarely, leave it unimpl now. If some one want to use it ,can continue from here.

Copy link
Member

Choose a reason for hiding this comment

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

Let's delete this code then. COUNT_ALLOCS will still work anyway; this fix_config_map function was only trying to add COUNT_ALLOCS if Py_Debug was set, which I now think was incorrect.

Suggested change
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }

Copy link
Contributor Author

@cecini cecini Dec 22, 2020

Choose a reason for hiding this comment

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

This code is for 3.8 only.
Yes, it was incorret, just as i said that according the CFlags to decide whether to set COUNT_ALLOCS as 1., no by the Py_DEBUG,
Again, Of course, if we decide never support COUNT_ALLOCS( we know >= 3.9 have remove COUNT_ALLOCS this code), we just delete this comment.

build.rs Outdated Show resolved Hide resolved
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thanks for the explanation!

I would like to see some simplifications before we merge this. Please see my other comments.

build.rs Outdated
// find CFLAGS to whether contains the COUNT_ALLOCS then set
// config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned());
Copy link
Member

Choose a reason for hiding this comment

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

I think this code might originally have been wrong (I can't see any suggestion that Py_DEBUG would set COUNT_ALLOCS in documentation), so please just delete:

Suggested change
// find CFLAGS to whether contains the COUNT_ALLOCS then set
// config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned());

Copy link
Contributor Author

@cecini cecini Dec 22, 2020

Choose a reason for hiding this comment

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

The if block is for the <= py 3.6.

Yes, I also said according the CFlags to decide whether to set COUNT_ALLOCS as 1, not by the Py_DEBUG.
But always we build python with pydebug, with debug python , we then can decide to enable COUNT_ALLOCS or disable(default disable). So i place the comment in the if Py_DEBUG block.

Of course, if decide never support COUNT_ALLOCS( we know > 3.9 have remove this code), we just delete this code.

build.rs Outdated
Comment on lines 245 to 246
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }
Copy link
Member

Choose a reason for hiding this comment

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

Let's delete this code then. COUNT_ALLOCS will still work anyway; this fix_config_map function was only trying to add COUNT_ALLOCS if Py_Debug was set, which I now think was incorrect.

Suggested change
// if interpreter_config.version.minor.unwrap_or(0) < 9 {
// }

build.rs Outdated
mut config_map: HashMap<String, String>,
interpreter_config: &InterpreterConfig,
) -> HashMap<String, String> {
if interpreter_config.version.major == 3 && interpreter_config.version.minor.unwrap_or(0) > 7 {
Copy link
Member

Choose a reason for hiding this comment

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

I suggest the following:

Suggested change
if interpreter_config.version.major == 3 && interpreter_config.version.minor.unwrap_or(0) > 7 {
assert_eq!(interpreter_config.version.major, 3);
if interpreter_config.version.minor.unwrap_or(0) >= 8 {

Because we only support Python 3, I think it's good to just make this code fail if we ever try to run it on Python 4.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but is this a proper place to do this assertion....?
I'd rather pass only the mimor version to this function.

Copy link
Member

Choose a reason for hiding this comment

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

Passing just the minor version instead of the full interpreter_config to this function also seems like a good idea!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will we support python 4? if support, we should keep the interpreter_config as the function argument. and leave room for the possible change in the python 4.

build.rs Outdated
Comment on lines 241 to 242
if let Some("1") = config_map.get("Py_TRACE_REFS").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
}
Copy link
Member

Choose a reason for hiding this comment

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

This code looks like a no-op, please delete? It just sets Py_TRACE_REFS to 1 if Py_TRACE_REFS == 1.

Suggested change
if let Some("1") = config_map.get("Py_TRACE_REFS").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, you are right. get config can get this info. I will fix.

@cecini cecini force-pushed the prfixbuildrs branch 3 times, most recently from 4654243 to 3e2a5b7 Compare December 22, 2020 16:54
@cecini
Copy link
Contributor Author

cecini commented Dec 22, 2020

refactor the pr code: pass the minor version; fix some code by suggestion.
Again, if we plan not support count_allocs, must delete the last comment in the pr.
Please give your suggestions.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Perfect, thanks! See my final suggestions, then let's merge 👍

build.rs Outdated
Comment on lines 247 to 251
// py3.9 remove the COUNT_ALLOCS related code
// if interpreter_config.version.minor.unwrap_or(0) <= 8 {
// // find CFLAGS to whether contains the COUNT_ALLOCS then set
// // config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned());
// }
Copy link
Member

Choose a reason for hiding this comment

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

Yes let's delete this 👍

Suggested change
// py3.9 remove the COUNT_ALLOCS related code
// if interpreter_config.version.minor.unwrap_or(0) <= 8 {
// // find CFLAGS to whether contains the COUNT_ALLOCS then set
// // config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned());
// }

build.rs Outdated
Comment on lines 238 to 244
if version_minor.unwrap_or(0) >= 8 {
if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned());
}
} else if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned());
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
Copy link
Member

Choose a reason for hiding this comment

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

I suggest this version with less repetition:

Suggested change
if version_minor.unwrap_or(0) >= 8 {
if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned());
}
} else if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned());
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
if let Some("1") = config_map.get("Py_DEBUG").as_ref().map(|s| s.as_str()) {
config_map.insert("Py_REF_DEBUG".to_owned(), "1".to_owned());
if version_minor.map_or(false, |minor| minor <= 7) {
// Py_DEBUG only implies Py_TRACE_REFS until Python 3.7
config_map.insert("Py_TRACE_REFS".to_owned(), "1".to_owned());
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice.

Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

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

Thank you very much for this, looks good!

I'm going to push a CHANGELOG entry to this branch and then will proceed to merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants