Skip to content

ffi: add getCurrentEventLoop.#64323

Open
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:ffi-get-event-loop
Open

ffi: add getCurrentEventLoop.#64323
ShogunPanda wants to merge 1 commit into
nodejs:mainfrom
ShogunPanda:ffi-get-event-loop

Conversation

@ShogunPanda

@ShogunPanda ShogunPanda commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

This add getCurrentEventLoop to node:ffi.
Together with the dlopen(null, ...) to interact with the current worker/main thread event loop.

Assisted-By: OpenAI:GPT-5.5 <openai/gpt-5.5>

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run. labels Jul 6, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/ffi

Signed-off-by: Paolo Insogna <paolo@cowtech.it>
Assisted-By: OpenAI:GPT-5.5 <openai/gpt-5.5>
@ShogunPanda ShogunPanda force-pushed the ffi-get-event-loop branch from ac99814 to 260f152 Compare July 6, 2026 13:12
@ShogunPanda ShogunPanda added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2026

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@ShogunPanda ShogunPanda added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Jul 6, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 6, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment thread doc/api/ffi.md
This is unsafe and dangerous. The returned pointer is only valid for the lifetime
of the current environment. Using it after the environment exits, or from native
code that assumes a different thread or lifetime, can crash the process or
corrupt memory.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Heh, I love this comment. "Here you go! Have fun cutting yourself!" 😆

Is there someway we could make this safer by returning an opaque value that becomes invalid when the environment exits or if it is used from the wrong thread?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Lol. Thanks!

Unfortunately not. In FFI I'm avoiding abstractions to eventually get to a real value. The pointer is a raw memory address, with all its danger, a-la C style :)

@ShogunPanda ShogunPanda added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 7, 2026
@Renegade334 Renegade334 added the semver-minor PRs that contain new features and should be released in the next minor version. label Jul 7, 2026
Comment thread test/ffi/test-ffi-module.js
@geeksilva97 geeksilva97 added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue Add this label to land a pull request using GitHub Actions. ffi Issues and PRs related to experimental Foreign Function Interface support. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants