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: add context-aware helpers and init macro by gabrielschulhof · Pull Request #21318 · nodejs/node

Conversation

@gabrielschulhof

@gabrielschulhof gabrielschulhof commented Jun 13, 2018

Copy link
Copy Markdown
Contributor

Introduces macro NODE_MODULE_INIT() which creates the boilerplate for
a context-aware module which can be loaded multiple times via the
special symbol mechanism.

Also introduces class node::WeakData with which one can weakly
associate a native class instance with a JavaScript object, and
convenience methods node::SetMethodWithData() and
node::SetPrototypeMethodWithData() which pass a native pointer
through to bindings.

Together, these APIs allow one to avoid using global static data in
an addon.

Re: #21291 (comment)

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 commented Jun 13, 2018

Copy link
Copy Markdown
Collaborator

@gabrielschulhof build started: https://ci.nodejs.org/blue/organizations/jenkins/node-test-pull-request-lite-pipeline/detail/node-test-pull-request-lite-pipeline/56/pipeline

All reactions

Sorry, something went wrong.

Uh oh!

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

@nodejs-github-bot nodejs-github-bot added the c++ Issues and PRs that require attention from people who are familiar with C++. label Jun 13, 2018
@gabrielschulhof
gabrielschulhof requested review from addaleax and bnoordhuis June 13, 2018 18:09
@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch 2 times, most recently from e292f6d to f25f30b Compare June 13, 2018 18:29
addaleax
addaleax reviewed Jun 13, 2018
View reviewed changes
Comment thread src/node.h Outdated

@addaleax addaleax Jun 13, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I wouldn’t be a fan of including this in our public API, unless there’s a reason why we would export it from core

We originally had more core of this sort around (e.g. node_object_wrap.h), but it’s a good idea that this generally moved into Nan territory? I’d suggest PR’ing it there

Sorry, something went wrong.

Uh oh!

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

bnoordhuis reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
vsemozhetbyt
vsemozhetbyt reviewed Jun 15, 2018
View reviewed changes
Comment thread doc/api/addons.md Outdated

@vsemozhetbyt vsemozhetbyt Jun 15, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

node-gyp -> `node-gyp` for consistency with other mentions?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread doc/api/addons.md Outdated

@vsemozhetbyt vsemozhetbyt Jun 15, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Missing final backtick and period?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread doc/api/addons.md Outdated

@vsemozhetbyt vsemozhetbyt Jun 15, 2018

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Should the first letter case be unified in this list?

Sorry, something went wrong.

Uh oh!

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

All reactions
@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch from e83beeb to 0f7d65d Compare June 20, 2018 22:28
@gabrielschulhof

gabrielschulhof commented Jun 20, 2018

Copy link
Copy Markdown
Contributor Author

@addaleax @bnoordhuis I have reduced the scope of the PR to the NODE_MODULE_INIT() macro, documentation pertaining to context-aware modules, and an example illustrating its use in a situation where data is stored per addon instance.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jun 20, 2018

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt I have fixed the issues you mention.

vsemozhetbyt reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@vsemozhetbyt

vsemozhetbyt commented Jun 20, 2018

Copy link
Copy Markdown
Contributor

Doc format LGTM.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch 2 times, most recently from 237c4f3 to ac20ee3 Compare June 20, 2018 22:40
jasnell
jasnell reviewed Jun 21, 2018
View reviewed changes
Comment thread doc/api/addons.md Outdated

@jasnell jasnell Jun 21, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

nit: "When building addons with..."

Sorry, something went wrong.

Uh oh!

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

All reactions

@gabrielschulhof gabrielschulhof Jun 21, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yep, I let that one slip :) Thanks!

Sorry, something went wrong.

Uh oh!

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

All reactions
@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch from ac20ee3 to 49360b2 Compare June 21, 2018 17:33
jasnell
jasnell approved these changes Jun 22, 2018
View reviewed changes
@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch from 49360b2 to 6b68df1 Compare June 22, 2018 20:34
@gabrielschulhof

gabrielschulhof commented Jun 22, 2018

Copy link
Copy Markdown
Contributor Author

CI: https://ci.nodejs.org/job/node-test-pull-request/15568/

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

Another CI before I land: https://ci.nodejs.org/job/node-test-pull-request/15639/

All reactions

Sorry, something went wrong.

Uh oh!

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

@devsnek

devsnek commented Jun 26, 2018

Copy link
Copy Markdown
Member

this needs another approval to land

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jun 26, 2018

Copy link
Copy Markdown
Contributor Author

@devsnek aaah, thank you! Wasn't sure.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vsemozhetbyt

vsemozhetbyt commented Jun 27, 2018

Copy link
Copy Markdown
Contributor

It seems our docs state only one approving is needed to land a not fast-track PR.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jun 27, 2018

Copy link
Copy Markdown
Contributor Author

@vsemozhetbyt actually, it says it must be two if a Collaborator is the originator of the PR. I checked after @devsnek's reminder: https://github.com/nodejs/node/blob/master/COLLABORATOR_GUIDE.md#code-reviews

All reactions

Sorry, something went wrong.

Uh oh!

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

@vsemozhetbyt

vsemozhetbyt commented Jun 27, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Do you refer this sentence?

In the case of pull requests proposed by an existing Collaborator, an additional Collaborator is required for sign-off.

I read it as "One Collaborator is the PR author, another Collaborator is a reviewer".

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@vsemozhetbyt vsemozhetbyt mentioned this pull request Jun 27, 2018
meta: number of approval ambiguity #21565
Closed
@gabrielschulhof

gabrielschulhof commented Jun 27, 2018 via email

Copy link
Copy Markdown
Contributor Author
I don't read it that way, because I know that the PR's author may not approve. Therefore, since all PRs need at least one approver, and a Collaborator's PR needs and additional approver, I conclude that a Collaborator's PR needs to approvers. Still, it should maybe state explicitly that a Collaborator's PR needs the approver of two Collaborators.
…
On Wed, Jun 27, 2018 at 10:29 AM, Vse Mozhet Byt ***@***.***> wrote: Do you refer this sentence? In the case of pull requests proposed by an existing Collaborator, an additional Collaborator is required for sign-off. I read it as "One Collaborator is the PR author, another Collaborator is a reviewer". — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#21318 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AA7k0YUDmU2AqXPuk33Qw_GV-exV3InLks5uA5awgaJpZM4UmriR> .
All reactions

Sorry, something went wrong.

Uh oh!

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

@vsemozhetbyt

vsemozhetbyt commented Jun 27, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Let's see how others understand this. It seems we have a bit confusing wording here.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott

Trott commented Jun 28, 2018

Copy link
Copy Markdown
Member

This does not need a second reviewer, although I would try pinging a relevant team or two before landing, just to get a second one.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jun 28, 2018

Copy link
Copy Markdown
Contributor Author

@nodejs/collaborators in the spirit of #21565 (comment), could somebody else please have a look? 🙂

All reactions

Sorry, something went wrong.

Uh oh!

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

@ryzokuken

ryzokuken commented Jun 28, 2018

Copy link
Copy Markdown
Contributor

Aww, the dreaded mention.

P.S. I'll take a look :)

mmarchini reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

mcollina
mcollina approved these changes Jun 28, 2018
View reviewed changes

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread doc/api/addons.md Outdated

@mcollina mcollina Jun 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you please articulate what could be those cases?

Sorry, something went wrong.

Uh oh!

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

gabrielschulhof reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@gabrielschulhof gabrielschulhof Jun 28, 2018

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

@mcollina how about the new paragraph I added?

Sorry, something went wrong.

Uh oh!

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

All reactions

@mcollina mcollina Jun 28, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

That’s perfect!

Sorry, something went wrong.

Uh oh!

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

All reactions
ryzokuken
ryzokuken approved these changes Jun 28, 2018
View reviewed changes

@ryzokuken ryzokuken left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM, but if I were you, I'd wait for @addaleax's review.

Sorry, something went wrong.

Uh oh!

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

All reactions
@gabrielschulhof

gabrielschulhof commented Jun 29, 2018

Copy link
Copy Markdown
Contributor Author

@addaleax could you please take another look?

All reactions

Sorry, something went wrong.

Uh oh!

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

Gabriel Schulhof added 3 commits June 30, 2018 20:24
Gabriel Schulhof
src: add context-aware init macro and doc
e9a452b
Introduces macro `NODE_MODULE_INIT()` which creates the boilerplate for
a context-aware module which can be loaded multiple times via the
special symbol mechanism.

Additionally, provides an example of using the new macro to construct
an addon which stores per-addon-instance data in a heap-allocated
structure that gets passed to each binding, rather than in a collection
of global static variables.

Re: nodejs#21291 (comment)
Gabriel Schulhof
address review comments
a9d8063
Gabriel Schulhof
document NODE_MODULE_INITIALIZER
9402ca1
@gabrielschulhof
gabrielschulhof force-pushed the node-addon-init branch from f81217c to 9402ca1 Compare July 1, 2018 01:48
@gabrielschulhof

gabrielschulhof commented Jul 1, 2018

Copy link
Copy Markdown
Contributor Author

Rebased and added doc for NODE_MODULE_INITIALIZER.

All reactions

Sorry, something went wrong.

Uh oh!

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

@Trott

Trott commented Jul 1, 2018

Copy link
Copy Markdown
Member

CI: https://ci.nodejs.org/job/node-test-pull-request/15698/

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jul 3, 2018

Copy link
Copy Markdown
Contributor Author

New CI: https://ci.nodejs.org/job/node-test-pull-request/15716/

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jul 3, 2018

Copy link
Copy Markdown
Contributor Author

Landed in 602da64.

All reactions

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof gabrielschulhof closed this Jul 3, 2018
gabrielschulhof pushed a commit to gabrielschulhof/node that referenced this pull request Jul 3, 2018
Gabriel Schulhof
src: add context-aware init macro and doc
602da64
Introduces macros `NODE_MODULE_INITIALIZER` which expands to the name
of the special symbol that process.dlopen() will look for to initialize
an addon, and `NODE_MODULE_INIT()` which creates the boilerplate for
a context-aware module which can be loaded multiple times via the
special symbol mechanism.

Additionally, provides an example of using the new macro to construct
an addon which stores per-addon-instance data in a heap-allocated
structure that gets passed to each binding, rather than in a collection
of global static variables.

Re: nodejs#21291 (comment)
PR-URL: nodejs#21318
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
@gabrielschulhof
gabrielschulhof deleted the node-addon-init branch July 3, 2018 22:35
@Trott

Trott commented Jul 3, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

CI was not green. I think we need stronger wording in our docs about not landing stuff when CI is not green. I'll open a PR for that right now.

If you have a mostly-green node-test-pull-request, you're fairly certain the not-green stuff isn't relevant to your changes, and you want to re-run just the things that aren't green, use "Resume Build" on the left menu. It will create a new node-test-pull-request, copy over all the green stuff, and only re-run the red/yellow/grey stuff.

Post-landing CI: https://ci.nodejs.org/job/node-test-pull-request/15717/

EDIT: Can't re-run CI because the branch has been deleted. So in lieu of that, here's a node-daily-master run manually kicked off to re-test this: https://ci.nodejs.org/job/node-daily-master/1203/

gibfahn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@gabrielschulhof

gabrielschulhof commented Jul 3, 2018

Copy link
Copy Markdown
Contributor Author

@Trott sorry about that! One job failed on what looked like an infra issue (unable to create a directory). Using "Resume Build" is an awesome option! I didn't know about it.

Trott and gibfahn reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

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

@Trott

Trott commented Jul 3, 2018 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

@Trott sorry about that! One job failed on what looked like an infra issue (unable to create a directory). Using "Resume Build" is an awesome option! I didn't know about it.

Sorry, didn't mean to pick on you! No need to apologize. You're far from alone. I'm just trying to spread the word about Resume Build. :-D (I didn't know about it until someone else on Build showed it to me...I think it was @refack.)

All reactions

Sorry, something went wrong.

Uh oh!

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

targos pushed a commit that referenced this pull request Jul 4, 2018
Gabriel Schulhof @targos
src: add context-aware init macro and doc
3a627c8
Introduces macros `NODE_MODULE_INITIALIZER` which expands to the name
of the special symbol that process.dlopen() will look for to initialize
an addon, and `NODE_MODULE_INIT()` which creates the boilerplate for
a context-aware module which can be loaded multiple times via the
special symbol mechanism.

Additionally, provides an example of using the new macro to construct
an addon which stores per-addon-instance data in a heap-allocated
structure that gets passed to each binding, rather than in a collection
of global static variables.

Re: #21291 (comment)
PR-URL: #21318
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ujjwal Sharma <[email protected]>
@targos targos mentioned this pull request Jul 17, 2018
v10.7.0 proposal #21851
Merged
This was referenced Jul 18, 2018
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#207
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#208
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#209
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#210
Closed
2018-07-18 Version 10.7.0 (Current) @targos beevelop/docker-nodejs#211
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@mcollina mcollina mcollina approved these changes
@addaleax addaleax addaleax left review comments
@jasnell jasnell jasnell approved these changes
@bnoordhuis bnoordhuis Awaiting requested review from bnoordhuis
+2 more reviewers
@vsemozhetbyt vsemozhetbyt vsemozhetbyt left review comments
@ryzokuken ryzokuken ryzokuken approved these changes
Reviewers whose approvals may not affect merge requirements

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++.

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.

9 participants

@gabrielschulhof @nodejs-github-bot @vsemozhetbyt @devsnek @Trott @ryzokuken @mcollina @jasnell @addaleax
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 01402775 — 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.