-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/builtinimport: Allow overriding of mp_builtin___import__. #9026
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
please use a static inline definition here, it's more robust than a #define
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.
Done and rebased. It does increase the code size by a few bytes (+4 on minimal embedded port).
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.
Ah! So the reason is because of this line:
which forces both the default and static-inline wrapper function to be linked in to the firmware (instead of just the default one).
I guess we need to go back to using the
#define
to make it efficient...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! I was wondering about that. I reverted it and rebased.
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.
Sorry to go back and forth on this.... We don't really have a consistent way to override an arbitrary function in the core, but there is some precedence set by
py/mphal.h
. Following the way it does things, we could do the following here:That would be pretty clean, and doesn't require an entry in
py/mpconfig.h
. It's also howports/stm32/boardctrl.h
does things.Then in your port you do:
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.
That's one of the first approaches I tried, but I got a bit stuck on where to do this exactly.
I'm able to make this work following the same
mphal
approach (theifndef
inpy/mphal.h
andcustom_import
inmphalport.h
), but I figured this one doesn't belong there since it doesn't concern hardware.It seems like the custom implementation would be provided via
mpconfigport.h
, but I'm not sure how since the declaration relies onmp_obj_t
which isn't defined at that point.What would be the right places to put the suggested snippets above?
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.
It should go here in
py/builtin.h
.How about this:
?
It's a bit tricky but should work.
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, that works! Updated and rebased.