This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author itsgk92
Recipients amaury.forgeotdarc, belopolsky, itsgk92, meador.inge
Date 2020-06-18.09:26:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1592472376.78.0.985098642017.issue41021@roundup.psfhosted.org>
In-reply-to
Content
Python Process crashes with unauthorised memory access when the C++ DLL callback has arguments as structures. Happens in python 3.8. python 3.7 works fine with same source code. Initial investigations revels that the structure is called back as a pointer instead of plain python object. Callbacks with Primitive types are successful. This might be something to do with vector calling in python 3.8?

>>>Replicate:

>>>A c++ DLL with "subscribe_cb" function and a callback "listen_cb"; where FILETIME is windows FILETIME structure (it can be any structure for that matter)

extern "C" CBFUNC(void, listen_cb)(int value, FILETIME ts );
extern "C" EXFUNC(void) subscribe_cb(listen_cb);

EXFUNC(void) subscribe_cb(listen_cb cb)
{
	
	int i = 0;
	while (true) {
		FILETIME systime;
		GetSystemTimeAsFileTime(&systime);
		i++;
		Sleep(1000);
		cb(i, systime);
   }
}


>>>Python client for the dll

class FT(Structure):
    _fields_ = [("dwLowDateTime", c_ulong, 32),
                ("dwHighDateTime", c_ulong, 32)]


@WINFUNCTYPE(c_void_p, c_int, FT)
def cb(val, ft):
    print(f"callback {val} {ft.dwLowDateTime} {ft.dwHighDateTime}")


lib = WinDLL(r"C:\Temp\CBsimulate\CbClient\CbClient\Debug\DummyCb.dll")

lib.subscribe_cb(cb)

while 1:
    sleep(5)
History
Date User Action Args
2020-06-18 09:26:16itsgk92setrecipients: + itsgk92, amaury.forgeotdarc, belopolsky, meador.inge
2020-06-18 09:26:16itsgk92setmessageid: <1592472376.78.0.985098642017.issue41021@roundup.psfhosted.org>
2020-06-18 09:26:16itsgk92linkissue41021 messages
2020-06-18 09:26:16itsgk92create