The problem must be caused by this 4.0.8 change noted in the changelog:

    Embind's val now requires a pointer policy when using pointers. e.g. (val 
v(pointer, allow_raw_pointers()).

https://emscripten.org/docs/api_reference/val.h.html does not even mention 
allow_raw_pointers. I have looked at val.h and at the commit which made this 
change but I remain at a loss how to change my declaration, below, to 
incorporate `allow_raw_pointers()`. 
 

val ret = val::object();

Please enlighten me.

This is a public API so I need to continue returning the pointer in the field 
“transcodedImage” of the return val;

Regards

    -Mark


> On May 23, 2025, at 22:29, キャロウ マーク <git...@callow.im> wrote:
> 
> I hit the send button too soon. The example error I intended to include is
> 
> [ 79%] Building CXX object 
> CMakeFiles/msc_basis_transcoder_js.dir/interface/js_binding/transcoder_wrapper.cpp.o
> /src/interface/js_binding/transcoder_wrapper.cpp:333:49: error: no viable 
> conversion from 'TranscodedImage *' to 'allow_raw_pointer<TranscodedImage *>'
>   333 |             allow_raw_pointer<TranscodedImage*> dst = new 
> TranscodedImage(tiByteLength));
>       |                                                 ^     
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /emsdk/upstream/emscripten/cache/sysroot/include/emscripten/bind.h:329:8: 
> note: candidate constructor (the implicit copy constructor) not viable: no 
> known conversion from 'TranscodedImage *' to 'const 
> allow_raw_pointer<msc::TranscodedImage *> &' for 1st argument
> 
> I do not know how to do a conversion to allow_raw_pointer<TranscodedImage*>. 
> I also want to avoid a copy on returning this from the native function as the 
> image is potentially large.
> 
> Regards
> 
>     -Mark
> 
>> On May 23, 2025, at 22:04, キャロウ マーク <git...@callow.im> wrote:
>> 
>> I have embind code that does the following to return something from native 
>> to JS.
>> 
>>             val ret = val::object();
>>             if (status) {
>>                 ret.set("transcodedImage", dst);
>>             }
>>             return ret;
>> 
>> where dst is
>> 
>>       TranscodedImage* dst
>> 
>> Since 4.0.9 I get (I've removed the backtrace from my code to the assertion 
>> statement)
>> 
>> /emsdk/upstream/emscripten/cache/sysroot/include/emscripten/wire.h:124:19: 
>> error: static assertion failed due to requirement 
>> '!std::is_pointer<msc::TranscodedImage *>::value': Implicitly binding raw 
>> pointers is illegal.  Specify allow_raw_pointer<arg<?>>
>>   124 |     static_assert(!std::is_pointer<T*>::value, "Implicitly binding 
>> raw pointers is illegal.  Specify allow_raw_pointer<arg<?>>");
>>       |                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
>> ...
>> /src/interface/js_binding/transcoder_wrapper.cpp:277:21: note: in 
>> instantiation of function template specialization 
>> 'emscripten::val::set<char[16], msc::TranscodedImage *>' requested here
>>   277 |                 ret.set("transcodedImage", dst);
>>       |                     ^
>> 
>> 
>> I cannot figure out how to specify `allow_raw_pointer`.  I added `, 
>> allow_raw_pointers()`  to the end of the function declaration in the 
>> EMSCRIPTEN_BINDINGS section but I got the same error. I have tried to use 
>> `allow_raw_pointer` template with TranscodedImage* as the arg in various 
>> ways but I am clearly not doing it the right way. I get a log of different 
>> errors. For example 
>> 
>> What is the right way?
>> 
>> The documentation did not help. 
>> https://emscripten.org/docs/api_reference/bind.h.html#how-to-use-this-api 
>> just says "type allow_raw_pointer” under a heading of “Policies.” 
>> https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#embind
>>  does not even mention `allow_raw_pointer`.
>> 
>> For reference the declaration of TranscodeImage is
>> 
>>     class TranscodedImage {
>>       public:
>>         TranscodedImage(size_t size) : image(size) { }
>> 
>>         uint8_t* data() { return image.data(); }
>>         size_t size() { return image.size(); }
>> 
>>         val get_typed_memory_view() {
>>            return val(typed_memory_view(image.size(), image.data()));
>>         }
>> 
>>       protected:
>>         std::vector<uint8_t> image;
>>     };
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "emscripten-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to emscripten-discuss+unsubscr...@googlegroups.com 
>> <mailto:emscripten-discuss+unsubscr...@googlegroups.com>.
>> To view this discussion visit 
>> https://groups.google.com/d/msgid/emscripten-discuss/62902311-A081-4F3C-A2F1-389655F18E5E%40callow.im
>>  
>> <https://groups.google.com/d/msgid/emscripten-discuss/62902311-A081-4F3C-A2F1-389655F18E5E%40callow.im?utm_medium=email&utm_source=footer>.
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to emscripten-discuss+unsubscr...@googlegroups.com 
> <mailto:emscripten-discuss+unsubscr...@googlegroups.com>.
> To view this discussion visit 
> https://groups.google.com/d/msgid/emscripten-discuss/1E5EADD3-6669-49A8-8B11-8EC752B5721B%40callow.im
>  
> <https://groups.google.com/d/msgid/emscripten-discuss/1E5EADD3-6669-49A8-8B11-8EC752B5721B%40callow.im?utm_medium=email&utm_source=footer>.

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to emscripten-discuss+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/emscripten-discuss/A4BF8344-260C-44AD-9781-7E1ACC917E6D%40callow.im.

Attachment: signature.asc
Description: Message signed with OpenPGP

Reply via email to