GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: kickstart addon by calling its constructor by gabrielschulhof · Pull Request #20114 · nodejs/node

Conversation

@gabrielschulhof

@gabrielschulhof gabrielschulhof commented Apr 17, 2018

Copy link
Copy Markdown
Contributor

If the addon does not self-register and a well-known Init symbol cannot
be found, look for a version-agnostic symbol which calls the library
constructor and call it if found.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. labels Apr 17, 2018
@gabrielschulhof

gabrielschulhof commented Apr 17, 2018

Copy link
Copy Markdown
Contributor Author

I'll add the documentation if this modification is accepted.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Apr 17, 2018
@Trott

Trott commented Apr 17, 2018

Copy link
Copy Markdown
Member

@nodejs/addon-api

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 18, 2018

Copy link
Copy Markdown
Member

Couldn't you simply emit multiple node_register_module_vXX symbols instead of devising a third add-on loading mechanism?

I assume the goal is to be automatically forward-compatible but that's not necessarily a good idea. For starters, it cements the layout of struct node_module - that could never be changed again if this lands.

That said... that ship may have sailed already because nm_version == -1 is treated specially. Kinda frustrating #11975, #14902 and #19262 were reviewed by nine or ten people and no one called it out.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof

gabrielschulhof commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

@bnoordhuis I don't understand why this particular PR would cement struct node_module. This merely simulates upon subsequent load what the library loader would do upon first load. The only thing this cements AFAICT is that we expect a newly loaded addon to call a function exposed by Node.js either in response to a "stimulus" by the library loader, or, with this change, in response to a "stimulus" by Node.js.

This PR makes no assumption about which Node.js function the addon calls, nor about the structure of the data it passes to that function.

For N-API purposes, I don't know that it would help that I scanned over a range of node_register_module_vXX symbols, because when you build the N-API module, you don't know ahead of time what values of XX to cover. Also, scanning over a range of symbols would only be useful if we could call any of them that we find. So, I guess we could do a bunch of special cases like

if (found-v-46) {
  // call it like this
} else if (found-v-47) {
  // call it some other way
} else if (found-v-63) {
  // call it yet another way
}

but since all these symbols take V8 objects, we can only call one such symbol, and only in such a way as is compatible with the current V8 ABI. So, scanning over a range of symbols would only make sense if we controlled the signature of those symbols.

I think the lowest common denominator, as with the library constructor, is void (*)(void);. The only missing piece is that dlopen() doesn't run the constructor again. So, come to think of it, the ability to save multiple versions of an addon into a single shared object is actually kind of orthogonal to this PR and useful in its own right.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof

gabrielschulhof commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

Wait a sec - this short-circuits the search for the version-specific init special symbol. I need to fix that.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof

gabrielschulhof commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

Like, what if the module self-registers, but with the wrong version? It should still look for the version-specific Init.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bnoordhuis

bnoordhuis commented Apr 18, 2018

Copy link
Copy Markdown
Member

I don't understand why this particular PR would cement struct node_module.

It links a struct node_module into the linked list. That means Node.js and the add-on need to agree on its layout because Node.js queries it later on.

Since there is no version number to sanity-check on when mp->nm_version == -1, any change to the struct breaks existing add-ons because they'll be using the old, incompatible layout.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof

gabrielschulhof commented Apr 18, 2018

Copy link
Copy Markdown
Contributor Author

@bnoordhuis this PR doesn't add the module to the linked list. It merely invokes the library constructor the second time around.

Can we not retain the old structure for the case where mp->nm_version == -1?

Whatever problems there are with the addon loading we will have whether or not this PR lands, and AFAICT this PR doesn't add to them.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Gabriel Schulhof
src: kickstart addon by calling its constructor
6740cdf
If the addon does not self-register and a well-known Init symbol cannot
be found, look for a version-agnostic symbol which calls the library
constructor and call it if found.
@gabrielschulhof
gabrielschulhof force-pushed the kickstart-addon branch from 21d4a1c to 6740cdf Compare April 18, 2018 21:24
@bnoordhuis

bnoordhuis commented Apr 19, 2018

Copy link
Copy Markdown
Member

Can we not retain the old structure for the case where mp->nm_version == -1?

No, that's pinning us down for all eternity. Early Node.js releases were unversioned but we explicitly moved away from that because it's untenable in the long run.

this PR doesn't add to them

It adds a second API that exploits what is essentially an oversight. It'll make it twice as hard to fix in the future.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof

gabrielschulhof commented Apr 20, 2018

Copy link
Copy Markdown
Contributor Author

@bnoordhuis I've tried a different tack. Let's see where that leads us.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gabrielschulhof gabrielschulhof closed this Apr 20, 2018
@gabrielschulhof
gabrielschulhof deleted the kickstart-addon branch April 23, 2018 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs involving general changes in the lib/ or src/ directories. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@gabrielschulhof @Trott @bnoordhuis @nodejs-github-bot
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.