Repository navigation
feat(examples): the timer example for the poll model - #279
Draft
Ivansete-status wants to merge 2 commits into
Draft
Ivansete-status wants to merge 2 commits into
Ivansete-status wants to merge 2 commits into
Conversation
This was referenced Nov 21, 2026
…un_examples The poll mode had no example, and nothing had run its generated C++ client against a real library. cpp_poll_bindings/main.cpp is the timer example's C++ program step for step, built from the same timer.nim with -d:ffiPollMode, so the two models can be compared side by side; it adds a reverse call answered through a Responder and a runLoop() thread. The generated CMakeLists of poll-model bindings builds the library in poll mode and in its own build directory, since the callback model's build of the same library has the same file name and would be overwritten. A dylib built by nim_ffi_lib.cmake also gets an rpath for the executables linked against it, since CMake adds none on macOS for a dylib that does not exist yet at configure time, which a first build in a clean tree hits. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Ivansete-status
force-pushed
the
feat/poll-examples
branch
from
November 21, 2026 01:45
ead82c3 to
152efcc
Compare
| runOrQuit genBindingsCmd(nimFlagsOrc, timerSrc, "cpp") | ||
| runOrQuit genBindingsCmd(nimFlagsRefc, timerSrc, "cpp") | ||
|
|
||
| task genbindings_cpp_poll, "Generate the timer example's C++ bindings for the poll model": |
Contributor
There was a problem hiding this comment.
[nph] reported by reviewdog 🐶
Suggested change
| task genbindings_cpp_poll, "Generate the timer example's C++ bindings for the poll model": | |
| task genbindings_cpp_poll, | |
| "Generate the timer example's C++ bindings for the poll model": |
Comment on lines
+1022
to
+1026
| let pollBuild = | ||
| when defined(ffiPollMode): | ||
| PollBuildCMake | ||
| else: | ||
| "" |
Contributor
There was a problem hiding this comment.
[nph] reported by reviewdog 🐶
Suggested change
| let pollBuild = | |
| when defined(ffiPollMode): | |
| PollBuildCMake | |
| else: | |
| "" | |
| let pollBuild = when defined(ffiPollMode): PollBuildCMake else: "" |
The poll example had a reverse-call step the callback example lacked, so the two could not be compared step for step. Add it: setFetchHostClockImpl answers the library's question with call.reply from the worker thread the library calls it on, and the program expects the same "UTC@1234567" as the poll example. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #278 (base is
feat/poll-cpp-reverse; retarget to master as the stack merges). Last of the four PRs that complete the first poll-mode version: #271 (C++ host), #276 (typed client), #278 (typed reverse-call handlers), this one. Part of #266.The timer example, for the poll model, so the two can be compared side by side:
examples/timer/cpp_poll_bindings/main.cppiscpp_bindings/main.cppstep for step ([1]–[7], same checks), built from the sametimer.nimwith-d:ffiPollMode. Comments marked "poll:" explain what differs: no...Asyncvariants (a call serves the queue while it waits), events arrive on the thread that serves, errors name the call. Both programs make a reverse call in [8] (the callback one answers withsetFetchHostClockImpl, the poll one through a typed handler and aResponder); the poll one adds [9], an event served while arunLoop()thread runs.nimble genbindings_cpp_poll, not checked in.nimble run_examples_pollbuilds and runs it, andnimble run_examples(CI's "Run C and C++ examples") includes it.examples/timer/README.mdhas a short section on it.What it needed:
CMakeLists.txtof poll-model bindings builds the library with-d:ffiPollMode, in its own build directory: the callback build of the same library has the same file name (libmy_timer), so a shared output would be overwritten and later callback runs could link the wrong one.nim_ffi_lib.cmakegives executables an rpath to the dylib. On macOS CMake adds none for a dylib that does not exist at configure time, which a first build in a clean tree hit; the existing examples only worked because something had built the dylib earlier.This is the first run of the generated poll client against a real library, and it found two bugs in #278 (a callback-mode compile error, a helper returning an empty reverse registry) and one gap (a doc-only
{.ffiReverse.}body), all fixed there.Measured on macOS (a
pthread_createinterposer): the callback program creates 8 threads (peak 5 alive plus main), the poll one 2 (peak 2 plus main).Verified locally on macOS from a clean tree:
nimble run_examples(C, C++ callback, C++ poll) exits 0 and the checked-in callback bindings regenerate unchanged. Linux and Windows runs are CI's first.🤖 Generated with Claude Code