GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-117953: Work Relative to Specific Extension Kinds in the Import Machinery by ericsnowcurrently · Pull Request #118205 · python/cpython Conversation
|
|
@encukou, aside from the other things this PR does, it should also take care of the problem with |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thank you! I have a few comments of the nitpicky kind.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| static bool | ||
| check_multiphase_preinit(PyModuleDef *def) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: consider making these do the assert, and naming them assert_multiphase_preinit & assert_singlephase. “check” is ambigous (should it do the assert?), and there aren't really suitable for anything but asserts.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| // XXX Two modules should not share the same def->m_base. | ||
| //assert(def->m_base.m_init == NULL | ||
| // || def->m_base.m_init == singlephase->m_init); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't remember why this is here.
Let's have the tests find where this was needed? A debug-build assert probably is the best tool.
| // XXX Two modules should not share the same def->m_base. | |
| //assert(def->m_base.m_init == NULL | |
| // || def->m_base.m_init == singlephase->m_init); | |
| // The following assert used to be skipped if | |
| // def->m_base.m_init == singlephase->m_init | |
| // but two modules should not share the same def->m_base. | |
| assert(def->m_base.m_init == NULL); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that isn't very clear and the commented-out assert isn't helping matters. I'll clarify the comment and drop the rest.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return NULL; | ||
| } | ||
| assert(!PyErr_Occurred()); | ||
| assert(!PyErr_Occurred() && res.err == NULL); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Let this tell you which one went wrong.
| assert(!PyErr_Occurred() && res.err == NULL); | |
| assert(!PyErr_Occurred()); | |
| assert(res.err == NULL); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| // XXX __file__ doesn't get set! |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is now solved, file gets set elsewhere.
| // XXX __file__ doesn't get set! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
While the import machinery (in importlib._bootstrap) does set __file__, the only place it gets set for a single-phase init module via _imp.load_dynamic (ergo ExtensionFileLoader.exec_module()) is the first time it is loaded, in import_run_extension(). In the above case, the module was found in the global cache and gets reloaded from the cached init function.
I was going to clarify the comment, but it would be just as easy to actually set __file__ and be done with it. 😄
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| goto finally; | ||
| } | ||
| assert(!PyErr_Occurred()); | ||
| assert(!PyErr_Occurred() && res.err == NULL); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| assert(!PyErr_Occurred() && res.err == NULL); | |
| assert(!PyErr_Occurred()); | |
| assert(res.err == NULL); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| if (err->exc != NULL) { | ||
| PyErr_SetRaisedException(err->exc); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Consider warning the reader about that function's quirk:
| PyErr_SetRaisedException(err->exc); | |
| PyErr_SetRaisedException(err->exc); | |
| err->exc = NULL; /* SetRaisedException stole our reference */ |
Maybe it would be better to merge _Py_ext_module_loader_result_apply_error and _Py_ext_module_loader_result_clear? They're effectively always used together (with apply skipped on success).
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| assert(!PyErr_Occurred()); | ||
| assert(!PyErr_Occurred() && res.err == NULL); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
| assert(!PyErr_Occurred() && res.err == NULL); | |
| assert(!PyErr_Occurred()); | |
| aeesrt(res.err == NULL); |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…sult_apply_error().
…ort Machinery (pythongh-118205) This change will make some later changes simpler.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.