-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lib: add internal check macros #18852
Conversation
75bd7b6
to
3087898
Compare
lib/internal/bootstrap_node.js
Outdated
const check = (expr) => { | ||
if (expr) | ||
return; | ||
const e = new Error(`${expr} == true`); |
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.
this will just be a boolean for all the CHECK_* macros that use this, and won't be very descriptive, which might be kinda annoying.
3087898
to
e2612ed
Compare
configure
Outdated
if options.lib_debug: | ||
o['variables']['node_lib_debug'] = 1 | ||
else: | ||
o['variables']['node_lib_debug'] = 'false' |
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.
o['variables']['node_lib_debug'] = b(options.lib_debug)
(I get that you copied it from the http2 flags but that's a really unidiomatic way of doing it.)
node.gyp
Outdated
@@ -740,6 +740,9 @@ | |||
}], | |||
[ 'node_use_perfctr=="false"', { | |||
'inputs': [ 'src/noperfctr_macros.py' ] | |||
}], | |||
[ 'node_lib_debug=="false"', { | |||
'inputs': [ 'src/check_macros.py' ] |
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.
Better name: nocheck_macro.py
That said, if you're using macros anyway, have two files: one with no-ops and one with, uh, ops, I guess?
macro CHECK(x) = do { if (!(x)) throw new Error(`x`); } while (0);
For the no-ops, instead of evaluating to nothing, maybe emit something that is dead code but syntax-checked, to avoid bitrot:
macro CHECK(x) = while (x, 0) {};
And a third suggestion is to have a guard variable so you can enable/disable checks at run-time instead of compile time.
e2612ed
to
9dc1e9e
Compare
it looks like js2c has a bug with expanding the macros ( i honestly have no idea what is going on in js2c so if someone could help out that would be nice 😄 |
9dc1e9e
to
4495cf6
Compare
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 think it would be great to add a single "test" entry. That could of course also be in a separate commit.
@BridgeAR this isn't ready for ci or merge, it doesn't actually work yet, see #18852 (comment) |
@devsnek I was not sure if the comment would still apply because there was a code change after your comment. And it has often been unnoticed if something was addressed. So I just thought I start a CI, no matter if it still applies or not :-) Can someone help out? Ping @jasnell @addaleax @bnoordhuis |
Is there a way to combine this with |
Also it would be great if we have both I think we can even turn on |
I personally also want to replace all I do not think that we need a |
@BridgeAR If by throwing an error you are talking about creating public errors, I took a look at the |
@devsnek I added an |
@joyeecheung I agree that the current |
I believe monkey-patching is still inevitable in many cases (e.g. APM modules, but the async hooks and the upcoming loader hooks could help them with that), and these asserts is a way to help them make sure everything works on their own. |
@devsnek it seems like we use a very old version of js2c.py. Without any further knowledge about it: you could see if everything works if you update it to the v8 deps one. |
4495cf6
to
5555b67
Compare
@BridgeAR thanks for the tip, this is working now 🎉 |
5555b67
to
15e5618
Compare
Potential future follow-up: make stringification work so that |
15e5618
to
a6d6e56
Compare
@BridgeAR @bnoordhuis needs another lookover with the new commits |
a6d6e56
to
16af089
Compare
I personally would rather migrate those in a different PR |
16af089
to
3ab6635
Compare
@BridgeAR i removed them |
3ab6635
to
9165e85
Compare
9165e85
to
5dc47a4
Compare
failures appear unrelated: ubuntu1604_sharedlibs_debug_x6414:21:44 not ok 715 parallel/test-http-dump-req-when-res-ends 14:21:44 --- 14:21:44 duration_ms: 9.527 14:21:44 severity: fail 14:21:44 stack: |- 14:21:44 resume called 14:21:44 Mismatched function calls. Expected at least 1, actual 0. 14:21:44 at Object.exports.mustCallAtLeast (/home/iojs/build/workspace/node-test-commit-linux-containered/nodes/ubuntu1604_sharedlibs_debug_x64/test/common/index.js:431:10) 14:21:44 at IncomingMessage. (/home/iojs/build/workspace/node-test-commit-linux-containered/nodes/ubuntu1604_sharedlibs_debug_x64/test/parallel/test-http-dump-req-when-res-ends.js:12:27) 14:21:44 at IncomingMessage. (/home/iojs/build/workspace/node-test-commit-linux-containered/nodes/ubuntu1604_sharedlibs_debug_x64/test/common/index.js:467:15) 14:21:44 at IncomingMessage.emit (events.js:131:13) 14:21:44 at resume_ (_stream_readable.js:833:10) 14:21:44 at process._tickCallback (internal/process/next_tick.js:115:19) |
landed in 3ed363c |
PR-URL: #18852 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Should this be backported to |
Just noticed that |
@joyeecheung we can revise that. I personally do not really have a strong opinion either way. I would just like the assert calls be replaced. If we have to change the abort for that again, I am all for it. |
PR-URL: #18852 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
PR-URL: nodejs#18852 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Should this be backport to 8.x? If so, a separate backport PR is necessary. |
Refs #18851
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)