Skip to content
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

Opaque robj: add get/set methods and remove all robj->ptr refs #1658

Open
wants to merge 3 commits into
base: unstable
Choose a base branch
from

Conversation

SoftlyRaining
Copy link
Contributor

@SoftlyRaining SoftlyRaining commented Feb 3, 2025

I wanted to know if I could do this by quickly writing some scripts. It probably took twice as long as I thought, but only 4-5 hours so not terrible, and now I know. 🤷🏻‍♀️ All but the necessary references in object.c have been replaced using objectGetVal and objectSetVal.

I know we want to make robj opaque so it's easier to refactor it or change its internal structure. I thought there was an issue for this but I can't find it offhand.

Copy link

codecov bot commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 84.02226% with 201 lines in your changes missing coverage. Please review.

Project coverage is 71.01%. Comparing base (78bcc0a) to head (5b5de16).
Report is 5 commits behind head on unstable.

Files with missing lines Patch % Lines
src/sentinel.c 0.00% 73 Missing ⚠️
src/module.c 1.88% 52 Missing ⚠️
src/debug.c 78.26% 20 Missing ⚠️
src/object.c 84.52% 13 Missing ⚠️
src/rdb.c 94.44% 5 Missing ⚠️
src/t_list.c 91.22% 5 Missing ⚠️
src/cluster_legacy.c 88.23% 4 Missing ⚠️
src/replication.c 89.74% 4 Missing ⚠️
src/t_stream.c 94.44% 4 Missing ⚠️
src/db.c 95.89% 3 Missing ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #1658      +/-   ##
============================================
- Coverage     71.02%   71.01%   -0.02%     
============================================
  Files           121      121              
  Lines         65176    65218      +42     
============================================
+ Hits          46290    46313      +23     
- Misses        18886    18905      +19     
Files with missing lines Coverage Δ
src/bitops.c 93.77% <100.00%> (+0.30%) ⬆️
src/cluster_slot_stats.c 94.35% <100.00%> (ø)
src/commandlog.c 96.58% <100.00%> (ø)
src/config.c 78.40% <100.00%> (+0.01%) ⬆️
src/eval.c 57.06% <100.00%> (ø)
src/expire.c 96.59% <100.00%> (ø)
src/functions.c 94.50% <100.00%> (ø)
src/geo.c 93.58% <100.00%> (ø)
src/latency.c 81.21% <100.00%> (+0.29%) ⬆️
src/lazyfree.c 86.11% <100.00%> (ø)
... and 32 more

... and 7 files with indirect coverage changes

@zuiderkwast
Copy link
Contributor

Awesome! Tbh, I'd prefer the complete change in one PR so we can get the benefit in memory usage. A separate commit within the same PR for the assignments and then a final commit to actually save memory in the object struct.

Feel free to write down you regexes so we can review those instead of alongside the actual diff. :D

@SoftlyRaining
Copy link
Contributor Author

SoftlyRaining commented Feb 4, 2025

Ok, I added objectSetVal.

I could post the python scripts I used, but they're pretty bad. I only worked on them to the extent that it'd save me time - They mangle a few instances but did the bulk of the editing for me. Here's the one I used for the last objectSetVal commit. The json I load is derived from VS Code's "find all references" feature.

import json

with open('ptrrefs.json') as f:
    refs = json.load(f)

for file in list(refs.keys()):
    with open(file, 'r') as src:
        lines = src.readlines()
    print('====', file, '====')
    for (lineno, char) in refs[file]:
        lineno -= 1 # line number is 1-based
        char -= 1 # char number also 1-based

        line = lines[lineno]
        count = line.count('->ptr = ')
        if count == 0:
            continue
        assert(count == 1)
        (robj, val_ptr) = line.strip()[:-1].split('->ptr = ')
        whitespace = line[:len(line) - len(line.lstrip())]
        print(lineno, line[:-1])
        lines[lineno] =  f'{whitespace}objectSetVal({robj}, {val_ptr});\n'

    with open(file, 'w') as src:
        src.writelines(lines)

@SoftlyRaining SoftlyRaining changed the title Opaque robj: add objectGetVal and remove ~80% of all robj->ptr refs Opaque robj: add get/set methods and remove all robj->ptr refs besides 4 in object.c Feb 4, 2025
@SoftlyRaining SoftlyRaining changed the title Opaque robj: add get/set methods and remove all robj->ptr refs besides 4 in object.c Opaque robj: add get/set methods and remove all robj->ptr refs Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants