Skip to content

Conversation

@JimB123
Copy link
Member

@JimB123 JimB123 commented Oct 31, 2025

In entry.c, the entry is a block of memory with variable contents. The structure can be difficult to understand. A new header comment more clearly documents the contents/layout of the entry.

Also, in entry.h, the entry was defined by typedef void entry. This allows blind casting to the entry type. It defeats compiler type checking.

Even though the entry has a variable definition, we can define entry as a legitimate type which allows the compiler to perform type checking. By performing typedef struct _entry entry, now the entry is understood to be a pointer to some type of undefined structure. We can pass a pointer and the compiler can typecheck the pointer. (Of course we can't dereference it, because we haven't actually defined the struct.)

@codecov
Copy link

codecov bot commented Oct 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.46%. Comparing base (f54818c) to head (fbc7d09).
⚠️ Report is 6 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #2794      +/-   ##
============================================
+ Coverage     72.30%   72.46%   +0.16%     
============================================
  Files           128      128              
  Lines         70211    70224      +13     
============================================
+ Hits          50763    50888     +125     
+ Misses        19448    19336     -112     
Files with missing lines Coverage Δ
src/entry.c 95.37% <100.00%> (+0.02%) ⬆️
src/server.h 100.00% <ø> (ø)
src/t_hash.c 96.08% <100.00%> (+<0.01%) ⬆️

... and 17 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JimB123 JimB123 marked this pull request as ready for review November 1, 2025 00:40
Copy link
Member

@ranshid ranshid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement and it does improve correctness

/* The entry pointer is the field sds. We encode the entry layout type
* in the field SDS header. Field type SDS_TYPE_5 doesn't have any spare bits to
* encode this so we use it only for the first layout type.
/* There are 3 different formats for the "entry". In all cases, the "entry" pointer points into the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are 4 right? expiration existence only multiply the past 2 encoding types (embedded value and non-embedded value)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In types 2 and 3, the expiration is optional. I didn't consider/document these as fundamentally different types. If we do that, there would be 5 types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O.K I understand it better now. LGTM

@ranshid ranshid merged commit a99c636 into valkey-io:unstable Nov 3, 2025
55 checks passed
eifrah-aws pushed a commit to eifrah-aws/valkey that referenced this pull request Nov 6, 2025
…-io#2794)

In `entry.c`, the `entry` is a block of memory with variable contents.
The structure can be difficult to understand. A new header comment more
clearly documents the contents/layout of the `entry`.

Also, in `entry.h`, the `entry` was defined by `typedef void entry`.
This allows blind casting to the `entry` type. It defeats compiler type
checking.

Even though the `entry` has a variable definition, we can define entry
as a legitimate type which allows the compiler to perform type checking.
By performing `typedef struct _entry entry`, now the `entry` is
understood to be a pointer to some type of undefined structure. We can
pass a pointer and the compiler can typecheck the pointer. (Of course we
can't dereference it, because we haven't actually defined the struct.)

Signed-off-by: Jim Brunner <[email protected]>
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