Giter Site home page Giter Site logo

Comments (5)

bnoordhuis avatar bnoordhuis commented on July 17, 2024

Confirmed, thanks for reporting.

http://github.com/ry/node/blob/81f5ed5c654c7b06e11563c36c79024265bcb7e7/src/node_buffer.cc#L150

It seems the call to NewInstance() returns a (wrapped) NULL pointer when there is stack pressure. The easy way out is to allocate memory on the heap but this might be a bug in V8 so I'm going to take a closer look.

from node-iconv.

stevebest avatar stevebest commented on July 17, 2024

I added a test case for this issue:

stevebest/node-iconv@b5ccf1c

from node-iconv.

stevebest avatar stevebest commented on July 17, 2024

Easy way lead to a great success! The original bug is still puzzling, but as long as we don't put convert() 100.000 calls deep down the call stack, it will probably work. :)

stevebest/node-iconv@776b712

Also, allocating memory in 4K chunks is probably suboptimal in terms of efficiency, especially since we can predict that the size of the output is roughly the same as the size of the input. But for now I think it's OK.

from node-iconv.

bnoordhuis avatar bnoordhuis commented on July 17, 2024

I'd written a patch already so I didn't use yours (sorry about that) but your unit test is much better than the thingy I whipped up so I added it.

I've created a nice test case on that Node bug (didn't turn out to be V8 after all). I'll keep you posted if you want.

from node-iconv.

bnoordhuis avatar bnoordhuis commented on July 17, 2024

PS: I bumped the temp buffers from 4 to 32K. It wasn't an issue with alloca() because that function simply bumps the stack pointer but heap allocation is rather more expensive.

we can predict that the size of the output is roughly the same as the size of the input

Hah! I originally wrote the iconv bindings to convert UTF-32 to UTF-8 (yes, there are people that actually use UTF-32. I didn't know either). dst = malloc(strlen(src)) would waste a lot of memory in such cases. But I agree that smarter heuristics won't hurt.

from node-iconv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.