Skip to main content.

Saturday, November 15, 2008

Look at this code:

GarbageString *str = new GarbageString( vm, (const wchar_t *) Sys::dynlib_voidp_call( fa->m_fAddress, bufpos, bufsize ), -1 );
vm->retval( str );

It sounds equivalent to this:

const wchar_t *ws = (const wchar_t *) Sys::dynlib_voidp_call( fa->m_fAddress, bufpos, bufsize )
GarbageString *str = new GarbageString( vm, ws, -1 );
vm->retval( str );

But for Visual C 2005 it's not so equivalent. In release build the second one crashes; the reason is in the fact that dynlib_voidp_call() mangles with some registers via assembly, apparently, but a wise compiler should not rely on register persistence across foreign function calls. Also, the problem is in the ws variable. It seems its value gets lost between the return from dynlib_voidp_call and the call on the next line. Be warned...

Comments

No comments yet

Add Comment

This item is closed, it's not possible to add new comments to it or to vote on it