Git Product home page Git Product logo

Comments (3)

 avatar commented on September 25, 2024

Might I suggest std::unique_ptr<std::span<T>> for the C++ API instead?

No UB, no weird code (e.g. reinterpreting casts), perfectly safe, allows directly passing the pointer to C without a full copy, but it would break the "nothing after C++11" restriction that the API currently imposes.

from wasm-c-api.

rossberg avatar rossberg commented on September 25, 2024

Do you mean std::span<std::unique_ptr<T>>? For C++ alone, that would be possible, but I'm afraid it will make it harder to implement the C API on top of it efficiently, which currently relies on being able to reinterpret_cast a C++ API's vec to a C API's vec and vice_versa, which requires controlling the former's representation. That could be avoided, but I think only for the price of extra copying of the span pair.

Anyway, at this point I'd be comfortable requiring C++14 or 17, but it's a bit early to force everybody onto C++20.

from wasm-c-api.

 avatar commented on September 25, 2024

Actually, neither std::span<std::unique_ptr<T>>, nor std::unique_ptr<std::span<T>>, make sense in this situation; one would need a union between the classes, i.e., a custom class. Note, unique_ptr<unique_ptr<T>[]> wouldn't be safe either: if std::unique_ptr were implemented in any stdlib as a struct larger than just the single pointer, then reinterpretation could be UB (not 100% sure, but if it's not, the results would be nonsense anyway).

As for updating the minimum language standard in use, I'd suggest at least checking out what versions implementations are currently using for their own Wasm VMs and other code. If no Wasm VM is written <= C++11, it would be wierd for the API to be in <= C++11.

(and yes, as having seen many libraries' reactions to C++20, I agree that it may be too new to push)

But, considering the lack of attention that this issue has been given, maybe the vec type does an okay job after all?

from wasm-c-api.

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.