wren-lang / wren

The Wren Programming Language. Wren is a small, fast, class-based concurrent scripting language.
http://wren.io
MIT License
6.9k stars 552 forks source link

Calling wrenInterpret from Wren #783

Open mode777 opened 4 years ago

mode777 commented 4 years ago

I was trying to dynamically load modules at runtime. My first naive approach was to just expose wrenInterpret as a foreign method. This will cause a segfault (It did work in Wren 0.2 when putting the call in a Fiber - but not in Wren 0.3). I've not yet investigated what causes the segfault (it might be obvious to someone more familiar with the internal architecture), but this does not seem the correct way to do this. Does anyone have a better approach to solving this problem?

mhermier commented 4 years ago

Please describe what you are trying to do more, because what you are trying to do looks like re-entrancy which is not supposed.

ruby0x1 commented 4 years ago

The segfault might be an assert, did you try in debug mode?

mode777 commented 4 years ago

@mhermier I think re-entrancy is exactly what I'm trying to do here. I'm calling a foreign method from a wren script whose implementation then calls wrenInterpret. The loaded script actually executes just fine. The segfault occurs later, possibly the next method call. A first wild guess is, that I somehow corrupted the stack.

@ruby0x1 I built with -DDEBUG but got the same results. Assertions seem fine.

EDIT: @ruby0x1 #776 is exactly what I'm trying to do here. Seems like going to 0.3 broke my code as well

mhermier commented 4 years ago

Try to explain a little bit your strategy, because dynamic import path might because a thing in 0.4.0, the feature is currently discussed.