I had a working mex connection (on Windows) to julia a while back that I've been trying to resuscitate this week, but to no avail.
Whatever is going wrong, it's pretty nasty. I can't even get to the point of calling a function in libjulia. Merely linking to libjulia causes it to crash. For instance, I can write a simple hello world mexFunction that works fine. But if I put in the same module a function that refers to a julia function, but which is never called, I see this behavior. And gdb isn't giving me much to go on. I never hit any breakpoint in my module, and here's the error and backtrace I receieve: warning: Critical error detected c0000374 Program received signal SIGTRAP, Trace/breakpoint trap. 0x0000000077c140d0 in ntdll!RtlUnhandledExceptionFilter () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll (gdb) backtrace #0 0x0000000077c140d0 in ntdll!RtlUnhandledExceptionFilter () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll #1 0x0000000077c14746 in ntdll!EtwEnumerateProcessRegGuids () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll #2 0x0000000077c15952 in ntdll!RtlQueryProcessLockInformation () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll #3 0x0000000077c17604 in ntdll!RtlLogStackBackTrace () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll #4 0x0000000077bbdc1f in ntdll!RtlIsDosDeviceName_U () from /cygdrive/c/Windows/SYSTEM32/ntdll.dll Backtrace stopped: previous frame inner to this frame (corrupt stack?) The solution I had did work at one point. At some point I may attempt to see if I can reproduce this with a vanilla exe embedding and/or do a git bisect to find out what commit caused it to stop working. Meanwhile I'm just sad and discouraged. On Wed, Mar 4, 2015 at 9:53 AM, Eric Davies <[email protected]> wrote: > Thanks, hopefully that solves it! > > I've got a pretty good solution currently. It requires no Julia code and > seems pretty fast. My favourite part is that the Julia workspace persists > across calls, through some sort of MEX magic that I don't fully understand. > The one downside is that it requires all input data to be copied (MATLAB > will segfault if you don't; I had the same problem in my MEX PostgreSQL > wrapper). I'll check with work next week--I expect it to be pretty much > done then--whether I can post this as a public repo. I am optimistic. > > Overall I love the Julia API! My only complaints are being fixed by Jeff's > latest PR :) > > > On Wednesday, 4 March 2015 06:06:19 UTC-6, Tim Holy wrote: >> >> It seems possible we should add a second "boolean" argument to >> _julia_init (in >> init.c) that controls whether the signal handlers get set. But as a >> workaround: >> http://stackoverflow.com/questions/9495113/how-to-get- >> the-handlers-name-address-for-some-signals-e-g-sigint-in-postgres >> >> You could at least test whether that solves the problem, and then if so >> perhaps it would be worth opening an issue in julia about whether we need >> a >> better solution. >> >> BTW, I'm interested in this topic too; see also >> https://groups.google.com/d/msg/julia-users/dP_J5KilsEs/4CIERQ14vdgJ. We >> should collaborate on a single solution (and it sounds like you're >> farther >> along and perhaps more invested). I'm happy to pitch in if code gets >> posted >> somewhere. >> >> --Tim >> >> On Tuesday, March 03, 2015 09:18:04 PM Eric Davies wrote: >> > Hi all, >> > >> > I'm attempting to embed julia in a MATLAB MEX file. Everything is going >> > great, but MATLAB will sometimes segfault after having run some code >> > calling Julia.* I believe I have narrowed it down to this >> > issue: http://ubuntuforums.org/showthread.php?t=2093057 . Basically, I >> > believe Julia is registering a SIGSEGV (or maybe other signal?) handler >> > that overwrites the default for the JVM set by MATLAB. after the Julia >> > function is done, that memory is freed. Then a segfault (or maybe other >> > signal?) happens in the JVM and it tries to call Julia's handler but >> > segfaults (again) as it is no longer there. >> > >> > Can anyone help me find a workaround? Perhaps if there's a way to >> > "deregister" the handler, or if someone knows a way to get the current >> > handler (before calling into Julia) and then setting it back to that >> after >> > Julia is done. >> > >> > I've never dealt with signals in C before so I apologize if I'm >> describing >> > things incorrectly or missing something. >> > >> > Thanks, >> > Eric >> > >> > *I am able to reliably reproduce this by running any MEX function >> linking >> > to Julia and calling jl_init, then calling `help clear` in MATLAB. >> > >> > P.S.: I'm on Mac OS X 10.10 with MATLAB R2012b and Julia >> v0.3.6/v0.4.0-dev >> >>
