Skip to content

Commit 7c6726c

Browse files
modify the user context
1 parent a5fbb3a commit 7c6726c

File tree

7 files changed

+9
-9
lines changed

7 files changed

+9
-9
lines changed

libudpard/udpard.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,13 @@ typedef struct udpard_bytes_mut_t
162162
/// allowing the application to associate its own data with various entities inside the library.
163163
typedef struct udpard_user_context_t
164164
{
165-
void (*fun)(void); // NOLINT(*-void-arg)
166-
void* obj;
165+
void* data[6];
167166
} udpard_user_context_t;
168167
#ifdef __cplusplus
169168
#define UDPARD_USER_CONTEXT_NULL \
170169
udpard_user_context_t {}
171170
#else
172-
#define UDPARD_USER_CONTEXT_NULL ((udpard_user_context_t){ .fun = NULL, .obj = NULL })
171+
#define UDPARD_USER_CONTEXT_NULL ((udpard_user_context_t){ .data = { NULL } })
173172
#endif
174173

175174
/// Zeros if invalid/unset/unavailable.

tests/src/helpers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ static inline udpard_bytes_scattered_t make_scattered(const void* const data, co
6767
// Wraps an application pointer for user context plumbing.
6868
static inline udpard_user_context_t make_user_context(void* const obj)
6969
{
70-
udpard_user_context_t out = { .fun = NULL, .obj = obj };
70+
udpard_user_context_t out = UDPARD_USER_CONTEXT_NULL;
71+
out.data[0] = obj;
7172
return out;
7273
}
7374

tests/src/test_e2e_api.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ constexpr udpard_tx_vtable_t tx_vtable{ .eject = &capture_tx_frame };
7272
// Feedback callback records completion.
7373
void record_feedback(udpard_tx_t*, const udpard_tx_feedback_t fb)
7474
{
75-
auto* st = static_cast<FeedbackState*>(fb.user.obj);
75+
auto* st = static_cast<FeedbackState*>(fb.user.data[0]);
7676
if (st != nullptr) {
7777
st->count++;
7878
st->success = fb.success;

tests/src/test_e2e_edge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ constexpr udpard_tx_vtable_t tx_vtable{ .eject = &capture_tx_frame };
5555

5656
void fb_record(udpard_tx_t*, const udpard_tx_feedback_t fb)
5757
{
58-
auto* st = static_cast<FbState*>(fb.user.obj);
58+
auto* st = static_cast<FbState*>(fb.user.data[0]);
5959
if (st != nullptr) {
6060
st->count++;
6161
st->success = fb.success;

tests/src/test_e2e_random.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ constexpr udpard_tx_vtable_t tx_vtable{ .eject = &capture_tx_frame };
107107

108108
void record_feedback(udpard_tx_t*, const udpard_tx_feedback_t fb)
109109
{
110-
auto* ctx = static_cast<Context*>(fb.user.obj);
110+
auto* ctx = static_cast<Context*>(fb.user.data[0]);
111111
if (ctx != nullptr) {
112112
if (fb.success) {
113113
ctx->reliable_feedback_success++;

tests/src/test_e2e_responses.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ struct FeedbackState
6363

6464
void record_feedback(udpard_tx_t*, const udpard_tx_feedback_t fb)
6565
{
66-
auto* st = static_cast<FeedbackState*>(fb.user.obj);
66+
auto* st = static_cast<FeedbackState*>(fb.user.data[0]);
6767
if (st != nullptr) {
6868
st->count++;
6969
st->success = fb.success;

tests/src/test_intrusive_tx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ static bool eject_with_log(udpard_tx_t* const tx, const udpard_tx_ejection_t eje
5858
static void record_feedback(udpard_tx_t* const tx, const udpard_tx_feedback_t fb)
5959
{
6060
(void)tx;
61-
feedback_state_t* const st = (feedback_state_t*)fb.user.obj;
61+
feedback_state_t* const st = (feedback_state_t*)fb.user.data[0];
6262
if (st != NULL) {
6363
st->count++;
6464
st->last = fb;

0 commit comments

Comments
 (0)