HaxeFoundation / HaxeFoundation/hxcpp
@:nativeGen interface use leads to crash
- Dominant language
- C++
- Stars
- 330
- Forks
- 227
- Avg merge
- 2d 16h
- Merged PRs (30d)
- 18
Description
When investigating https://github.com/HaxeFoundation/haxe/issues/10427, I discovered that this program using native interfaces crashes:
```haxe
@:nativeGen
interface IFirst {
public function doFirst():Void;
}
@:nativeGen
interface ISecond {
public function doSecond():Void;
}
class Main implements IFirst implements ISecond {
public var data:Array = [1, 2, 3];
public function new() {}
public function doFirst() {
trace(data);
}
public function doSecond() {
trace(data);
}
static function main() {
final obj = new Main();
final interfaceRef:ISecond = obj;
cpp.vm.Gc.run(true);
interfaceRef.doSecond();
}
}
```
Compiled on linux with:
```
haxe -m Main --cpp bin
```
This crashes while trying to join the Array because the `->length` field has become garbage.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by compiling the supplied Main program on Linux with `haxe -m Main --cpp bin` and reproduce the crash after `cpp.vm.Gc.run(true)`. Then inspect the generated C++ around the ISecond dispatch and Array access; done means the program completes without the Array length becoming corrupted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100