Skip to content

Is well-known symbol the recommended way to build addon? #21291

Description

@fs-eire

The change #18934 introduced a new interface enabling addon to initialize itself for multiple context using symbol node_register_module_v${NODE_MODULE_VERSION}.

However I didn't find much more information about this feature:
no related documents on https://nodejs.org/dist/latest-v10.x/docs/api/addons.html;
no examples ( only one simple test );
no related macro definition in node.h;
no n-api equivalent

I think the feature is still in experimental.. will it become a preferred and recommended way for addon, or it just going to be remove in some future version?

Activity

  1. joyeecheung commented on Jun 12, 2018

    @joyeecheung
    Member
  2. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor
  3. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    @joyeecheung I wrote the previous comment wrong. In step 1. I meant to say "... you would normally store in global static variables."

  4. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    @joyeecheung AFAIK currently exports objects are never gc-ed, because we never unload modules. But then again, global static variables aren't de-allocated either, for the same reason.

  5. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    @joyeecheung the N-API documentation on master mentions the macro NAPI_MODULE_INIT under the section Module registration.

  6. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    This has not been back-ported though, AFAIK.

  7. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    @joyeecheung the hello world addon test already tests multiple loading of an addon.

  8. fs-eire commented on Jun 12, 2018

    @fs-eire
    ContributorAuthor

    thanks @gabrielschulhof for the detailed information.

    The steps show HOW to avoid using global static data, but I don't understand WHY should avoid using global static data. Sometimes I want to have a shared state (like a singleton pattern), I believe this scenario is OK to have.

    So the good news is, the N-API macro NAPI_MODULE_INIT is already there ready for this kind of scenario. Is it a good idea to create a corresponding macro NODE_MODULE_INIT for the usage?

  9. gabrielschulhof commented on Jun 12, 2018

    @gabrielschulhof
    Contributor

    @fs-eire I guess it boils down to whether the global static singleton contains any references to JavaScript values. Since the module may be loaded multiple times from different contexts, and perhaps even different isolates, the JavaScript value(s) stored in the singleton may not be valid. Thus, if you want to have a singleton, it should only contain native data.

    NODE_MODULE_INIT() may indeed be worth a PR.

  10. jasnell commented on Jun 19, 2020

    @jasnell
    Member

    There's been no further discussion here and it's not clear if there's anything actionable. Closing. Can reopen if necessary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    addonsIssues and PRs related to native addons.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions