-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-45636: Simpler design for BINARY_OP/INPLACE_OP
#29418
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 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
4b7125f
Merge BINARY_*/INPLACE_* into BINARY_OP/INPLACE_OP
brandtbucher 3a87083
Clean things up a bit
brandtbucher a2df29a
Improve the new _PyNumber_*Op implementations
brandtbucher 1b8934e
Add docs
brandtbucher 3137973
blurb add
brandtbucher 9905549
Fix API leak
brandtbucher f697036
Clean up the nb_info struct
brandtbucher 33f6e7c
Clean up some comments
brandtbucher bd8e9c7
Split up operator slots and names
brandtbucher 4cac17a
Apply feedback from code review
brandtbucher 3c2957b
Fix comment
brandtbucher 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
Split up operator slots and names
- Loading branch information
commit bd8e9c711664f2871c120a52e60965d9c8e40a83
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1716,43 +1716,58 @@ PyNumber_ToBase(PyObject *n, int base) | |
| } | ||
|
|
||
| typedef struct { | ||
| const int slot; | ||
| const uint16_t slot; | ||
| const uint16_t islot; | ||
| } nb_slot_info; | ||
|
|
||
| #define NB_SLOT_INFO(slot) {NB_SLOT(nb_##slot), NB_SLOT(nb_inplace_##slot)} | ||
|
|
||
| static const nb_slot_info nb_slot_infos[] = { | ||
| [NB_AND] = NB_SLOT_INFO(and), | ||
| [NB_FLOOR_DIVIDE] = NB_SLOT_INFO(floor_divide), | ||
| [NB_LSHIFT] = NB_SLOT_INFO(lshift), | ||
| [NB_MATRIX_MULTIPLY] = NB_SLOT_INFO(matrix_multiply), | ||
| [NB_OR] = NB_SLOT_INFO(or), | ||
| [NB_RSHIFT] = NB_SLOT_INFO(rshift), | ||
| [NB_SUBTRACT] = NB_SLOT_INFO(subtract), | ||
| [NB_TRUE_DIVIDE] = NB_SLOT_INFO(true_divide), | ||
| [NB_XOR] = NB_SLOT_INFO(xor), | ||
| }; | ||
|
|
||
| #undef NB_SLOT_INFO | ||
|
|
||
| typedef struct { | ||
| const char name[3]; | ||
| const int islot; | ||
| const char iname[4]; | ||
| } nb_info; | ||
|
|
||
| #define NB_INFO(name, slot) \ | ||
| {NB_SLOT(nb_##slot), name, NB_SLOT(nb_inplace_##slot), name "="} | ||
|
|
||
| static nb_info nb_infos[] = { | ||
| [NB_AND] = NB_INFO("&", and), | ||
| [NB_FLOOR_DIVIDE] = NB_INFO("//", floor_divide), | ||
| [NB_LSHIFT] = NB_INFO("<<", lshift), | ||
| [NB_MATRIX_MULTIPLY] = NB_INFO("@", matrix_multiply), | ||
| [NB_OR] = NB_INFO("|", or), | ||
| [NB_RSHIFT] = NB_INFO(">>", rshift), | ||
| [NB_SUBTRACT] = NB_INFO("-", subtract), | ||
| [NB_TRUE_DIVIDE] = NB_INFO("/", true_divide), | ||
| [NB_XOR] = NB_INFO("^", xor), | ||
| } nb_name_info; | ||
|
|
||
| #define NB_NAME_INFO(name) {name, name "="} | ||
|
|
||
| static const nb_name_info nb_name_infos[] = { | ||
| [NB_AND] = NB_NAME_INFO("&"), | ||
| [NB_FLOOR_DIVIDE] = NB_NAME_INFO("//"), | ||
| [NB_LSHIFT] = NB_NAME_INFO("<<"), | ||
| [NB_MATRIX_MULTIPLY] = NB_NAME_INFO("@"), | ||
| [NB_OR] = NB_NAME_INFO("|"), | ||
| [NB_RSHIFT] = NB_NAME_INFO(">>"), | ||
| [NB_SUBTRACT] = NB_NAME_INFO("-"), | ||
| [NB_TRUE_DIVIDE] = NB_NAME_INFO("/"), | ||
| [NB_XOR] = NB_NAME_INFO("^"), | ||
| }; | ||
|
|
||
| #undef NB_INFO | ||
| #undef NB_NAME_INFO | ||
|
|
||
| PyObject * | ||
| _PyNumber_Op(PyObject *o1, PyObject *o2, unsigned op) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just forwards to
|
||
| { | ||
| assert(op < sizeof(nb_infos) / sizeof(nb_info)); | ||
| nb_info *ni = &nb_infos[op]; | ||
| return binary_op(o1, o2, ni->slot, ni->name); | ||
| return binary_op(o1, o2, nb_slot_infos[op].slot, nb_name_infos[op].name); | ||
| } | ||
|
|
||
| PyObject * | ||
| _PyNumber_InPlaceOp(PyObject *o1, PyObject *o2, unsigned op) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as for |
||
| { | ||
| assert(op < sizeof(nb_infos) / sizeof(nb_info)); | ||
| nb_info *ni = &nb_infos[op]; | ||
| return binary_iop(o1, o2, ni->islot, ni->slot, ni->iname); | ||
| return binary_iop(o1, o2, nb_slot_infos[op].islot, nb_slot_infos[op].slot, | ||
| nb_name_infos[op].iname); | ||
| } | ||
|
|
||
|
|
||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.