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.

classification
Title: Ctypes bug windows
Type: crash Stage: resolved
Components: Windows Versions: Python 3.3, Python 3.4, Python 3.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: PlatonAdCo, eryksun, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords:

Created on 2016-09-23 16:25 by PlatonAdCo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
toxygen_video_test.zip PlatonAdCo, 2016-10-25 18:01
Messages (14)
msg277286 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-09-23 16:25
I'm wrapping C function using ctypes. Function has following prototype:
bool func(some_struct* pointer, uint32_t a, uint16_t b, uint16_t c, const uint8_t *d, const uint8_t *e, const uint8_t *f, some_enum *e);
I tried a lot of variants of wrapper but on windows I always have "access violation reading 0x00000000" in console. On Linux everything works fine. I tested it with different versions of Python, it presents at least in 3.3 - 3.5. I think bug is in passing uint8_t *d, uint8_t *e, uint8_t *f, because wrapper for almost the same function with 1 pointer instead of 3 works as expected.
msg277760 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-09-30 16:35
Are you using 64-bit? There was an issue passing structs a while back, but I don't recall when or if we've merged the patch.
msg277762 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-09-30 17:14
I use 32-bit python on 64-bit windows
msg277787 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-10-01 01:23
You keep removing the Windows component - is this not actually a bug on Windows?
msg277806 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-01 10:44
Oh it's ctypes bug on windows only
msg277957 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-10-03 13:25
Since this is 32-bit, are you using CDLL (cdecl) or WinDLL (stdcall)? Either way, I made a simple test for the given function prototype, and it worked fine in 32-bit 3.5.2 on Windows 10 for both calling conventions. You'll have to provide a minimal example that reproduces the problem.
msg277990 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-03 18:52
CDLL. I didn't test it on Python 3.5.2, 3.3 - 3.4 only. And btw my OS is windows 7. Lib is also used by some apps (not Python apps) and there this function works well.
msg277998 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2016-10-03 19:47
If you want a resolution to this issue, then you need to provide a minimal example that reproduces the problem. It would also be helpful if you could provide a download link for the library that you're wrapping. If not, at least upload a dump file, preferably from 3.5 since 3.4 is no longer actively maintained.
msg278061 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-04 17:09
Unfortunately in my case "minimal" example is extremely long. Do you really need it&
msg278122 - (view) Author: Steve Dower (steve.dower) * (Python committer) Date: 2016-10-05 13:13
Ultimately we need something to put in the test suite to make sure it's fixed and doesn't regress in the future. It's asking a lot of our volunteers to investigate a bug on very little information.
msg278143 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-05 18:13
I will write (as short as possible) example. Hope to finish it in ~ 1 week.
msg279434 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-25 18:01
Sorry for delay. I tried to write as small as possible example. Sorry if it is too big
Usage: run 2 consoles, cd to dir with sources. In first console type 'python3 main.py test1.tox', and in second type 'python3 main.py test2.tox'. Wait 1-2 min until apps connect and you will see a lot of "access violation reading 0x0000" when consoles start video call. sometimes apps crashes too. crashes fine on both win 7 an win 8 for me
msg279715 - (view) Author: Aristotel (PlatonAdCo) Date: 2016-10-30 09:40
Any update on this? It blocks development of my project.
msg388162 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-03-05 20:49
I didn't have time to look deeper into this. I'm sorry for not getting back to you. The rather-large example that you uploaded didn't and doesn't run for me, so I wasn't able to reproduce the problem.

The one bit of advice I have is to always declare required argument types in the `argtypes` attribute of ctypes functions. It can be very useful to take advantage of the type checking that ctypes provides in order to catch problems before they lead to stack or heap corruption, or bad values that lead to corruption later on. 

I'm closing this issue as not a bug. ctypes and libffi have been used in a broad range of cases in 32-bit Windows for many years, and I wasn't able to reproduce the problem with a function of the given call signature when I checked in 2016.
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72446
2021-03-05 20:49:15eryksunsetstatus: open -> closed
resolution: not a bug
messages: + msg388162

stage: test needed -> resolved
2016-10-30 09:40:56PlatonAdCosetmessages: + msg279715
2016-10-25 18:01:41PlatonAdCosetfiles: + toxygen_video_test.zip

messages: + msg279434
2016-10-05 18:13:11PlatonAdCosetmessages: + msg278143
2016-10-05 13:13:20steve.dowersetmessages: + msg278122
stage: test needed
2016-10-04 17:09:31PlatonAdCosetmessages: + msg278061
versions: + Python 3.5
2016-10-03 19:47:11eryksunsetmessages: + msg277998
versions: - Python 3.5
2016-10-03 18:52:51PlatonAdCosetmessages: + msg277990
2016-10-03 13:25:06eryksunsetnosy: + eryksun
messages: + msg277957
2016-10-01 10:44:39PlatonAdCosetmessages: + msg277806
2016-10-01 10:43:12PlatonAdCosetcomponents: + Windows, - ctypes
2016-10-01 01:23:40steve.dowersetmessages: + msg277787
2016-09-30 17:14:23PlatonAdCosetmessages: + msg277762
components: - Windows
2016-09-30 16:35:50steve.dowersetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
messages: + msg277760
components: + Windows
2016-09-23 16:25:46PlatonAdCocreate