-
Notifications
You must be signed in to change notification settings - Fork 792
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
Conversation
There was a problem hiding this 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
// if interpreter_config.version.minor.unwrap_or(0) < 9 { | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dead code?
// if interpreter_config.version.minor.unwrap_or(0) < 9 { | |
// } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
// if interpreter_config.version.minor.unwrap_or(0) < 9 { | |
// } |
There was a problem hiding this comment.
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.
There was a problem hiding this 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()); |
There was a problem hiding this comment.
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:
// find CFLAGS to whether contains the COUNT_ALLOCS then set | |
// config_map.insert("COUNT_ALLOCS".to_owned(), "1".to_owned()); |
There was a problem hiding this comment.
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
// if interpreter_config.version.minor.unwrap_or(0) < 9 { | ||
// } |
There was a problem hiding this comment.
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.
// 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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest the following:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
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()); | ||
} |
There was a problem hiding this comment.
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
.
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()); | |
} |
There was a problem hiding this comment.
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.
4654243
to
3e2a5b7
Compare
refactor the pr code: pass the minor version; fix some code by suggestion. |
There was a problem hiding this 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
// 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()); | ||
// } |
There was a problem hiding this comment.
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 👍
// 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
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()); |
There was a problem hiding this comment.
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:
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()); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice.
There was a problem hiding this 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.
b77ba36
to
c780aa9
Compare
There is some change for the trace refs . So fix it .
Since COUNT_ALLOCS used rarely, leave it unimpl now.