New submission from Aravindhan <arvindh92...@yahoo.com>:

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)

----------
components: ctypes
messages: 371796
nosy: amaury.forgeotdarc, belopolsky, itsgk92, meador.inge
priority: normal
severity: normal
status: open
title: Ctype callback with Structures crashes on python 3.8 on windows.
type: crash
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue41021>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to