Since #254491-108: Standardize static caching we lost the version which stored the defaults and drupal_static_reset only resets inside drupal_static and does not affect the function that stores a reference to the drupal_static storage. The only reason we see drupal_static_reset working is that after the reset, we unconditionally call drupal_static with the default we want and because inside drupal_static the storage is now unset, the default gets stored. However, if the default would be a costly affair to calculate and we would take to care to pass it to drupal_static once, expecting it to hold for us, things would break. Or if a genius like Casey (really nice job!) wants to make sure we call drupal_static only once as in #619666: Make performance-critical usage of drupal_static() grokkable then suddenly things fall apart. I am attaching a patch that was RTBC'd in the original issue, carries the same amount of lines of code and works a hell lot better by storing the default and doing a real reset. Memory issues were cited -- given that the default is mostly just array() or FALSE, that's not a really good argument compared to the fact that the memory saving version is broken.
Comment | File | Size | Author |
---|---|---|---|
#17 | drupal_static_cleanup_17.patch | 3.03 KB | effulgentsia |
#15 | drupal_static_cleanup_15.patch | 3.04 KB | effulgentsia |
#12 | drupal_static_cleanup.patch | 1.81 KB | chx |
#10 | drupal_static_cleanup.patch | 1.67 KB | chx |
#8 | drupal_static_cleanup.patch | 1.23 KB | chx |
Comments
Comment #2
chx CreditAttribution: chx commentedSorry for the patch mixup.
Comment #4
chx CreditAttribution: chx commentedcatch gave me an important hint to what happens here. Thanks!
Comment #6
chx CreditAttribution: chx commentedYeah, yeah, if you reset before drupal_static is called w a default then now you get a notice...
Comment #8
chx CreditAttribution: chx commentedHm, right.
Comment #10
chx CreditAttribution: chx commentedOK, no more trying to fix. I rewrote it. The code flow now is a lot clearer, too. First we handle the reset-all case, then the reset-one case and explicitly deal with the "reset called before we have a default" case.
Comment #11
sunIf this would be wrong, then a lot of tests would fail. So it seems this is almost RTBC.
Could we add some inline comments here as well?
(Please also note the trailing whites-pace.)
Inline comments here, too, as this seems to be the main static/reference handling.
I'm on crack. Are you, too?
Comment #12
chx CreditAttribution: chx commentedAdded even more comments. It's now (way) more comments than code.
Comment #13
sunAlright, I'm more happy with this.
Comment #14
Dries CreditAttribution: Dries commentedLooks good to me too. Committed.
Comment #15
effulgentsia CreditAttribution: effulgentsia commenteddrupal_static_reset() is still broken when called globally (without passing a $name parameter). This was the case prior to this issue, but I'm attaching the patch here, since it's related to this issue. The bug hasn't manifested yet, because we have no places within core where drupal_static_reset() is called without passing $name. This patch includes a test that fails unless this patch is applied.
Comment #16
chx CreditAttribution: chx commentedNice! But can't you simply do
foreach ($default as $name => $value) $data[$name] = $value;
?Comment #17
effulgentsia CreditAttribution: effulgentsia commentedYes.
Comment #18
effulgentsia CreditAttribution: effulgentsia commentedCross-linking this to #601584: setUp() function for unit and web test cases should reset all resettable statics, because that issue now includes this same fix. If that issue lands first, then this one can be marked "fixed" again as per #14. On the other hand, if this issue lands first, then that one will need to be re-rolled.
Comment #19
chx CreditAttribution: chx commentedThanks.
Comment #20
webchickCommitted to HEAD with some minor comment/whitespace clean-up.
Comment #21
effulgentsia CreditAttribution: effulgentsia commentedAwesome! So, now that global drupal_static_reset() isn't broken, can anyone here help get #601584: setUp() function for unit and web test cases should reset all resettable statics to RTBC level?