Coder Social home page Coder Social logo

Comments (4)

sbc100 avatar sbc100 commented on May 29, 2024

With -sWASM64 we convert all incoming pointers to number (technically a 53 bit integer which we refer to as int53 internally) when they arrive on the JS side. In other words, from JS code, pointers should still be number.

How are you receiving the pointer value that you are passing to UTF8ToString?

from emscripten.

tbuchs avatar tbuchs commented on May 29, 2024

That's very interesting, maybe it's just my fault. I tried to narrow it down to a very simple PoC:

main.cpp

#include <vector>

extern "C" {
extern int testWasm64ToString(const char **pUrls);
}

int main() {
    std::vector<const char*> v = {"abc", "abc"};
    return testWasm64ToString(v.data());   
}

helper.js

(function() {
	var Test = {
  		testWasm64ToString: function(data) {
        var result = UTF8ToString(data);
        return 0;
      },
    };
    mergeInto(LibraryManager.library, Test);
  })();

I compiled the program with: em++ main.cpp -sMEMORY64=1 --js-library helper.js -o test.html

Thank you for your ongoing support!

from emscripten.

sbc100 avatar sbc100 commented on May 29, 2024

The fix here would be to add a __sig entry to your testWasm64ToString function in the JS library.

Something like testWasm64ToString__sig: 'ip'. This says the return value is an i (integer) and the first and only argument is ap (pointer). This will enable emscripten to automatically convert the incoming bigint value to an integer.

from emscripten.

tbuchs avatar tbuchs commented on May 29, 2024

Thanks, that works perfectly!

from emscripten.

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.