Skip to content
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

zlib: add ArrayBuffer support #16042

Closed
wants to merge 1 commit into from
Closed

zlib: add ArrayBuffer support #16042

wants to merge 1 commit into from

Conversation

jemjam
Copy link

@jemjam jemjam commented Oct 6, 2017

Refs: #1826

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
Affected core subsystem(s)

zlib, src

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. zlib Issues and PRs related to the zlib subsystem. labels Oct 6, 2017
@Trott Trott added the code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. label Oct 6, 2017
Copy link
Member

@TimothyGu TimothyGu left a comment

Choose a reason for hiding this comment

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

We'll have to run this through CI before landing, but CI is currently busy with the 220+ code+learn PRs... so let's wait a bit.

doc/api/zlib.md Outdated
@@ -308,7 +311,7 @@ ignored by the decompression classes.
* `level` {integer} (compression only)
* `memLevel` {integer} (compression only)
* `strategy` {integer} (compression only)
* `dictionary` {Buffer|TypedArray|DataView} (deflate/inflate only, empty dictionary by
* `dictionary` {Buffer|TypedArray|DataView|ArrayBuffer} (deflate/inflate only, empty dictionary by
Copy link
Member

Choose a reason for hiding this comment

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

Looks like this line might exceed 80 characters... either you can re-wrap, or we can do it while landing this.

src/util.h Outdated
v8::ArrayBuffer::Contents name##_c = name->GetContents(); \
name##_length = name##_c.ByteLength(); \
name##_data = \
static_cast<char*>(name##_c.Data()); \
Copy link
Member

Choose a reason for hiding this comment

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

These two lines can be joined into one. Again, it would be great if you could fix that, but if not we can fix that while landing.

lib/zlib.js Outdated
@@ -238,7 +241,7 @@ function Zlib(opts, mode) {
}

dictionary = opts.dictionary;
if (dictionary !== undefined && !isArrayBufferView(dictionary)) {
if (dictionary !== undefined && !isArrayBufferView(dictionary) && !isAnyArrayBuffer(dictionary)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This line needs to be wrapped at 80 characters as well.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

LGTM

I know this is tricky, but can we actually split the non-zlib changes into its own commit? Can happen while landing as well :)

@addaleax
Copy link
Member

addaleax commented Oct 7, 2017

@jemjam
Copy link
Author

jemjam commented Oct 7, 2017

I addressed those couple of line length issues. Is there a code style guide somewhere that I should reference in the future? (I just ran my changes through eslint to get an idea of what to change.)

@addaleax did you link to some CI issues there? Looks like some failures. I had a glance but am not certain about the output there.

Also: when you suggested splitting were you talking the C++ code for the ArrayBuffers? Big thanks to @TimothyGu for holding my hand during my updating those; however I thought the work was pretty interrelated? If you want that part split, can it happen "during landing" as you suggested.

@addaleax addaleax added the semver-minor PRs that contain new features and should be released in the next minor version. label Oct 7, 2017
@addaleax
Copy link
Member

addaleax commented Oct 7, 2017

@JemBijoux I started CI jobs for this, yes. The failures look like this:

    assert.js:45
      throw new errors.AssertionError({
      ^
    
    AssertionError [ERR_ASSERTION]: 'The "buffer" argument must be one of type string, Buffer, TypedArray, DataView, or ArrayBuffer' === 'The "buffer" argument must be one of type string, Buffer, TypedArray, or DataView'
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:723:16)
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:517:15)
        at expectedException (assert.js:651:19)
        at innerThrows (assert.js:685:21)
        at Function.throws (assert.js:702:3)
        at Object.expectsError (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/common/index.js:745:12)
        at __dirname.forEach (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/parallel/test-zlib-not-string-or-buffer.js:10:10)
        at Array.forEach (<anonymous>)
        at Object.<anonymous> (/home/iojs/build/workspace/node-test-commit-linux/nodes/ubuntu1610-x64/test/parallel/test-zlib-not-string-or-buffer.js:9:65)
        at Module._compile (module.js:600:30)

Can you reproduce those by running make test?

And, what I’m basically thinking is that the changes to src/node_buffer.cc could be in their own commit, because they are worth calling out explicitly in the changelog: They change the API for all native addon authors, and that’s not really obvious if the commit is referring only to zlib. That’s basically all. :)

@jemjam
Copy link
Author

jemjam commented Oct 9, 2017

Hey! So I was able to confirm the issue with the test and make that fix no problem. All tests passing again.

I also moved that node_buffer.cc file into it's own commit now (#16111). However, when I did that, one of the changes to a test I had here started to fail also in test/parallel/test-zlib-convenience-methods.js so I've removed that change for now.

@lpinca
Copy link
Member

lpinca commented Oct 14, 2017

@TimothyGu TimothyGu self-assigned this Oct 14, 2017
@BridgeAR
Copy link
Member

I think this is ready to land. Ping @TimothyGu

@addaleax
Copy link
Member

@BridgeAR See also the discussion in #16111 … I am not quite at the point where I think extending the Buffer code for this is necessarily a great idea …

I think for now it might be nicer to let this be a zlib-only thing and create an Uint8Array for passed ArrayBuffers, then work with that, if we want support?

@BridgeAR
Copy link
Member

BridgeAR commented Oct 18, 2017

I see. In that case I just mark this accordingly for now. Thanks for the heads up!

@BridgeAR BridgeAR added discuss Issues opened for discussions and feedbacks. blocked PRs that are blocked by other issues or PRs. labels Oct 18, 2017
@Trott Trott added code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. and removed code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. labels Oct 27, 2017
@Trott
Copy link
Member

Trott commented Oct 27, 2017

I'm a little unsure what the situation is here. What would have to happen for this to get unblocked?

@Trott
Copy link
Member

Trott commented Oct 29, 2017

I'm a little unsure what the situation is here. What would have to happen for this to get unblocked?

Ping @BridgeAR @addaleax

@gireeshpunathil
Copy link
Member

ping @BridgeAR and @addaleax again to have another look ( one of 3 remaining code-and-learn PRs!)

@addaleax
Copy link
Member

This is blocked on #16111, that’s all.

I think for zlib this might make more sense than for the general case of all Buffer-taking APIs (although “compress a chunk of memory” is still going to be exceedingly rare compared to “compress a chunk of data”, conceptually).

It might be a nicer approach to create a Uint8Array over it when an ArrayBuffer is passed to the API? @TimothyGu ?

@TimothyGu TimothyGu removed c++ Issues and PRs that require attention from people who are familiar with C++. discuss Issues opened for discussions and feedbacks. labels Dec 6, 2017
@TimothyGu
Copy link
Member

I've rebased this patch to be minimally invasive with regards to public APIs. @addaleax, @jasnell, @joyeecheung, @lpinca, @BridgeAR, @cjihrig, PTAL.

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

@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 13, 2017
addaleax pushed a commit to addaleax/node that referenced this pull request Dec 13, 2017
PR-URL: nodejs#16042
Refs: nodejs#1826
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@addaleax
Copy link
Member

Landed in 2848718 🎉

@addaleax addaleax closed this Dec 13, 2017
@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 13, 2017
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
PR-URL: #16042
Refs: #1826
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Jan 10, 2018
MylesBorins added a commit that referenced this pull request Jan 10, 2018
Notable change:

* async_hooks:
  - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither
    API were documented. (Andreas Madsen)
    #16972
* deps:
  - update nghttp2 to 1.29.0 (James M Snell)
    #17908
  - upgrade npm to 5.6.0 (Kat Marchán)
    #17535
  - cherry-pick 50f7455 from upstream V8 (Michaël Zasso)
    #16591
* events:
  - remove reaches into _events internals (Anatoli Papirovski)
    #17440
* http:
  - add rawPacket in err of `clientError` event (XadillaX)
    #17672
* http2:
  - implement maxSessionMemory (James M Snell)
    #17967
  - add initial support for originSet (James M Snell)
    #17935
  - add altsvc support (James M Snell)
    #17917
  - perf_hooks integration (James M Snell)
    #17906
* net:
  - remove Socket.prototype.write (Anna Henningsen)
    #17644
  - remove Socket.prototype.listen (Ruben Bridgewater)
    #13735
* repl:
  - show lexically scoped vars in tab completion (Michaël Zasso)
    #16591
* stream:
  - rm {writeable/readable}State.length (Calvin Metcalf)
    #12857
  - add flow and buffer properties to streams (Calvin Metcalf)
    #12855
* util:
  - allow wildcards in NODE_DEBUG variable (Tyler)
    #17609
* zlib:
  - add ArrayBuffer support (Jem Bezooyen)
    #16042
* Addedew collaborator**
  - [starkwang](https://github.com/starkwang) Weijia Wang
* Addedew TSC member**
  - [danbev](https://github.com/danbev) Daniel Bevenius

PR-URL: #18069
MylesBorins added a commit that referenced this pull request Jan 10, 2018
Notable change:

* async_hooks:
  - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither
    API were documented. (Andreas Madsen)
    #16972
* deps:
  - update nghttp2 to 1.29.0 (James M Snell)
    #17908
  - upgrade npm to 5.6.0 (Kat Marchán)
    #17535
  - cherry-pick 50f7455 from upstream V8 (Michaël Zasso)
    #16591
* events:
  - remove reaches into _events internals (Anatoli Papirovski)
    #17440
* http:
  - add rawPacket in err of `clientError` event (XadillaX)
    #17672
* http2:
  - implement maxSessionMemory (James M Snell)
    #17967
  - add initial support for originSet (James M Snell)
    #17935
  - add altsvc support (James M Snell)
    #17917
  - perf_hooks integration (James M Snell)
    #17906
  - Refactoring and cleanup of Http2Session and Http2Stream destroy
    (James M Snell) #17406
* net:
  - remove Socket.prototype.write (Anna Henningsen)
    #17644
  - remove Socket.prototype.listen (Ruben Bridgewater)
    #13735
* repl:
  - show lexically scoped vars in tab completion (Michaël Zasso)
    #16591
* stream:
  - rm {writeable/readable}State.length (Calvin Metcalf)
    #12857
  - add flow and buffer properties to streams (Calvin Metcalf)
    #12855
* util:
  - allow wildcards in NODE_DEBUG variable (Tyler)
    #17609
* zlib:
  - add ArrayBuffer support (Jem Bezooyen)
    #16042
* Addedew collaborator**
  - [starkwang](https://github.com/starkwang) Weijia Wang
* Addedew TSC member**
  - [danbev](https://github.com/danbev) Daniel Bevenius

PR-URL: #18069
MylesBorins added a commit that referenced this pull request Jan 10, 2018
Notable change:

* async_hooks:
  - deprecate AsyncHooks Sensitive API and runInAsyncIdScope. Neither
    API were documented. (Andreas Madsen)
    #16972
* deps:
  - update nghttp2 to 1.29.0 (James M Snell)
    #17908
  - upgrade npm to 5.6.0 (Kat Marchán)
    #17535
  - cherry-pick 50f7455 from upstream V8 (Michaël Zasso)
    #16591
* events:
  - remove reaches into _events internals (Anatoli Papirovski)
    #17440
* http:
  - add rawPacket in err of `clientError` event (XadillaX)
    #17672
* http2:
  - implement maxSessionMemory (James M Snell)
    #17967
  - add initial support for originSet (James M Snell)
    #17935
  - add altsvc support (James M Snell)
    #17917
  - perf_hooks integration (James M Snell)
    #17906
  - Refactoring and cleanup of Http2Session and Http2Stream destroy
    (James M Snell) #17406
* net:
  - remove Socket.prototype.write (Anna Henningsen)
    #17644
  - remove Socket.prototype.listen (Ruben Bridgewater)
    #13735
* repl:
  - show lexically scoped vars in tab completion (Michaël Zasso)
    #16591
* stream:
  - rm {writeable/readable}State.length (Calvin Metcalf)
    #12857
  - add flow and buffer properties to streams (Calvin Metcalf)
    #12855
* util:
  - allow wildcards in NODE_DEBUG variable (Tyler)
    #17609
* zlib:
  - add ArrayBuffer support (Jem Bezooyen)
    #16042
* Addedew collaborator**
  - [starkwang](https://github.com/starkwang) Weijia Wang
* Addedew TSC member**
  - [danbev](https://github.com/danbev) Daniel Bevenius

PR-URL: #18069
@MylesBorins
Copy link
Contributor

Would we want to backport to v8.x? If so this will need a manual backport

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buffer Issues and PRs related to the buffer subsystem. code-and-learn Issues related to the Code-and-Learn events and PRs submitted during the events. semver-minor PRs that contain new features and should be released in the next minor version. zlib Issues and PRs related to the zlib subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.