-
Notifications
You must be signed in to change notification settings - Fork 1k
Replace ATTRIB, SET_ATTRIB
#7487
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
Conversation
Instead, backport and use CLEAR_ATTRIB (R >= 4.5).
Use SHALLOW_DUPLICATE_ATTRIB (R >= 3.3) for the simple case. Also, Backport ANY_ATTRIB (R >= 4.5) instead of testing !isNull(ATTRIB(.)).
Instead of trying to walk ATTRIB in search of the compact 'rownames' attribute to modify, install it anew, take note of the returned reference to the value being installed (a different one!) and modify that.
Instead of walking the attribute list directly, use R_mapAttrib(). Create a hash table of index names instead of relying on chin() and a temporary string vector. Move all temporary allocations onto the R heap.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7487 +/- ##
==========================================
+ Coverage 98.99% 99.02% +0.03%
==========================================
Files 87 87
Lines 16729 16750 +21
==========================================
+ Hits 16561 16587 +26
+ Misses 168 163 -5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Generated via commit 069560c Download link for the artifact containing the test results: ↓ atime-results.zip
|
HughParsonage
left a 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.
Maybe add some brief documentation about what each function does and returns if time permits.
|
This is expected to become more of a problem around end of January. |
| R_len_t ngrp, nrowgroups, njval=0, ngrpcols, ansloc=0, maxn, estn=-1, thisansloc, grpn, thislen, igrp; | ||
| int nprotect=0; | ||
| SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, rownames, s, RHS, target, source; | ||
| SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, s, RHS, target, source; |
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.
| SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, s, RHS, target, source; | |
| SEXP ans=NULL, jval, thiscol, BY, N, I, GRP, iSD, xSD, RHS, target, source; |
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.
Co-authored-by: Benjamin Schwendinger <[email protected]>
Otherwise the callback could remove the attribute and end up with the value unprotected. Protect the attribute tag as well for uniformity. Co-Authored-By: HughParsonage <[email protected]>
This solution is closer to the working approach previously taken by the code.
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.
LGTM, TY!
(Besides missing news ofc)

Towards #6180.
Replace remaining uses of
SET_ATTRIBwithSHALLOW_DUPLICATE_ATTRIBorCLEAR_ATTRIB. Replace remaining uses ofATTRIBtesting withANY_ATTRIB; use the newR_mapAttribinterface to walk the attributes.assign.cwhereattr(., 'index')is adjusted following a by-reference operation that could invalidate some indices. What used to be afor (cons = ATTRIB(x); !isNull(cons); cons = CDR(cons))loop now has to construct a contextstructto share between the caller and the map callback. On the plus side, I simplified the memory management and string operations a bit, getting rid of things likememset(string, '\0', 1)and making use of the new hash table to look up the indices.rownamesattribute indogroups.cis also a bit tricky. Nowdogroupscreates a throwawayINTSXPc(NA_integer, -whatever), gives it tosetAttrib(SD, R_RowNamesSymbol, decoy), and obtains the actual compactrownamesattribute that R re-creates from the return value. I think this is simpler than walking the attribute list by hand in search of the correct attribute, and the end result is the same: we can modifyrownamesby reference without spilling it into a large string vector.