Using std::map in functions the second time crashes

Bug #1644017 reported by Jay
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Cheerp
Fix Committed
Undecided
Unassigned

Bug Description

I am having a very large problem.

I have a map which is identified with "std::map<string,string (*)(string,vector<string>)>".
The map contains a name of the function that maps to the actual function.
I have to make several calls to this map. The map is in global scope.

One of my functions contains an std::map<string,string>. The map executes correctly if ran the first time, however, the second time it executes a function it errors out: "Uncaught TypeError: Cannot read property 'a0' of undefined" . I manage to find the cause of the problem and it seems to be including any type of std::map in a function. If I remove the std::map it executes fully and correctly. If I add it to any other function that is also has a pointer from "std::map<string,string (*)(string,vector<string>)>". it gives me an error on second execution. So for now, I am using vectors which seem to work. However, I would really love to use std::map<string,string> for several of my functions. Again, it executes once, but fails to execute second time. Perhaps this is due to Cheerp Preprocesser optimizing the std::map that executes first time and then after it completes the execution, the second time, it somehow tries to overwrite that object?

I am not sure, but it would be great if it gets fixed.

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

Hello Jay, could you attach your test case? It would be very helpful.

Revision history for this message
Jay (jayjay2016) wrote :

I've attached the test case. The code attached works correctly in C++ (with modification of main and web). The code also compiles without any errors. However, when I run in the browser, I get the following error:
juliar.js:1 Uncaught ReferenceError: da is not defined(…)

This seem to happen at compilation step. Because if I compile it, sometimes it gives this type of error. However, at times when I compile with same script and same exact file no errors are generated.

(This seems to be a Cheerp error because it appears depending whether the C++ file gets compiled correctly or not. Please advise)

The original code used for this test case can be found at: https://github.com/juliarLang/juliar/tree/master/binaries/WebsiteAlpha

Thanks,
Jay

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

Hello,

I am not sure that I properly reproduced your bug. From my preliminary analysis it would seem that the only problem is that Juliar_core::hide is not defined. I would suggest that you use the -cheerp-pretty-code command line option to generate more readable and debuggable code.

Revision history for this message
Jay (jayjay2016) wrote :

I have compiled with pretty-code and included relevant source.
(Open zip and go to binaries/WebsiteAlpha to see the juliar.js)

In a file src/core_module/math.cpp all I did was added was some std::map variable.

Please keep in mind, using vectors works perfectly!

If I remove the std::map it works perfectly no javascript errors are given and file executes to the finish. However, if I add an std::map to any of functions in namespace it freaks out. g++/clang++ compilation works well (no errors are given) However, when I compile a cheerp, it gives me such error in javascript.

Please advice.

Revision history for this message
Alessandro Pignotti (a-pignotti) wrote :

I suggest that you try again with out nightly builds if possible:

https://launchpad.net/~leaningtech-dev/+archive/ubuntu/cheerp-nightly-ppa/+packages

The problem seems not to happen with current master

Changed in cheerp:
status: New → Fix Released
status: Fix Released → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.