Skip to content

Fix hevent_set_cb for named callbacks - #929

Open
radkesvat wants to merge 1 commit into
ithewei:masterfrom
radkesvat:fix/hevent-set-cb
Open

radkesvat wants to merge 1 commit into
ithewei:masterfrom
radkesvat:fix/hevent-set-cb

Conversation

@radkesvat

Copy link
Copy Markdown
Contributor

A C or C++ caller trying to register a named event callback gets a compiler error for this ordinary call.

hevent_set_cb(&event, on_ready);

Today the macro uses cb for both its second parameter and the event's struct field. The preprocessor replaces both occurrences. With the call above, the compiler sees an assignment to event.on_ready and reports that hevent_t has no such member.

This change names the macro parameter callback. The field name stays cb, so the call stores on_ready in event.cb.

Regression test

The new test sets a named function on a stack-allocated event, then checks that hevent_cb(&event) returns that function. It failed to compile against the old header with GCC. With the fix it compiled and passed on Linux as C99 and as C++11. The C++ check used the public header copied by CMake. The Windows x64 C regression also compiled with MinGW and passed under Wine.

The C test can be run on Linux with these commands.

cmake -S . -B build -DBUILD_UNITTEST=ON -DBUILD_EXAMPLES=OFF
cmake --build build --target hevent_set_cb_test
build/bin/hevent_set_cb_test

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.

1 participant