You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
callback function on win64 results in bad behavior. mem corruption? #52522
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2011-01-31.21:48:33.283>created_at=<Date2010-03-31.18:53:44.080>labels= ['ctypes', 'type-crash']
title='callback function on win64 results in bad behavior. mem corruption?'updated_at=<Date2011-01-31.21:48:33.282>user='https://bugs.python.org/ocrush'
I am testing a wrapper on Windows 64 and it seems to result in an null pointer access error ONLY when I insert a print statement in the C code. I have tested the wrapper with Python 2.6 and Python 2.7a4. In addition, I have compiled Python 2.6.5 source code and ONLY the release version results in an error. I think the issue is with memcpy(obj->b_ptr, *pArgs, dict->size) (callbacks.c). pArgs seem to be corrupted. However, I am only looking at the code for the first time and I might be off base.
The following is Python and C code to reproduce the bug. To resolve, please comment printf statement in jfunc (C function).
Python Code:
from ctypes import *
def fcn(m,n,x,f):
print "IN Python function fcn ................"
print f[0]
changed the title [-]callback function on win64 results in bad behavior. mem leak?[/-][+]callback function on win64 results in bad behavior. mem corruption?[/+]on Mar 31, 2010
ocrush commented on Apr 7, 2010
ocrushmannequin
MannequinAuthor
More actions
I was able to fix the issue by modifying and re-compiling ctypes project in Visual Studio 2008. The following properties were modified:
Release:
configuration Properties->C/C++->Optimization->Optimization: Disabled(/Od)
configuration Properties->C/C++->Optimization->Enable Intrinsic Functions: No
srid commented on Dec 22, 2010
sridmannequin
Mannequin
More actions
Attaching a patch for the configuration changes mentioned in msg102544
Thank you. The new patch works and it also fixes a crash of the python-2.5.4.amd64 interpreter at startup when ctypes 1.0.2 and pyreadline 1.6.2 are installed.
stanmihai commented on Jan 31, 2011
stanmihaimannequin
Mannequin
More actions
attached patch with tests
I have no experience with python development so the tests will actually need a more detailed review. Also I only checked it on win64.
Patch verified to work under Linux and win32. It looks good, except for tab characters in the Modules/_ctypes/_ctypes_test.c (indentation of C files should use 4 spaces); that's a detail that we can fix ourselves.
ok, please also fix the first parameter of the tests. Because it has the same value in the first call and the callback it will always be right by accident, since the first call puts the value in both standard and floating point registers.
Activity
ocrush commentedon Mar 31, 2010
I am testing a wrapper on Windows 64 and it seems to result in an null pointer access error ONLY when I insert a print statement in the C code. I have tested the wrapper with Python 2.6 and Python 2.7a4. In addition, I have compiled Python 2.6.5 source code and ONLY the release version results in an error. I think the issue is with memcpy(obj->b_ptr, *pArgs, dict->size) (callbacks.c). pArgs seem to be corrupted. However, I am only looking at the code for the first time and I might be off base.
The following is Python and C code to reproduce the bug. To resolve, please comment printf statement in jfunc (C function).
Python Code:
from ctypes import *
def fcn(m,n,x,f):
print "IN Python function fcn ................"
print f[0]
m=3
n=1
pydlltest=cdll.pydlltest
pydlltest.jfunc.restype = POINTER(c_double)
evalstring = 'pydlltest.jfunc('
TMP_FCN=CFUNCTYPE(None,c_int,c_int,POINTER(c_double),POINTER(c_double))
tmp_fcn=TMP_FCN(fcn)
state=[TMP_FCN,tmp_fcn]
evalstring += 'tmp_fcn'
evalstring +=','
evalstring +='c_int(m)'
evalstring +=','
evalstring +='c_int(n)'
evalstring += ')'
print "evalstring=",evalstring
result = eval(evalstring)
[-]callback function on win64 results in bad behavior. mem leak?[/-][+]callback function on win64 results in bad behavior. mem corruption?[/+]ocrush commentedon Apr 7, 2010
I was able to fix the issue by modifying and re-compiling ctypes project in Visual Studio 2008. The following properties were modified:
Release:
configuration Properties->C/C++->Optimization->Optimization: Disabled(/Od)
configuration Properties->C/C++->Optimization->Enable Intrinsic Functions: No
srid commentedon Dec 22, 2010
Attaching a patch for the configuration changes mentioned in msg102544
cgohlke commentedon Jan 21, 2011
This patch fixes issue bpo-9884 and possibly bpo-9266.
stanmihai commentedon Jan 26, 2011
Disabling optimizations doesn't really fix the issue, just hides it, for now.
The problem was an uninitialized variable. Attached is the patch that fixes it.
pitrou commentedon Jan 26, 2011
Would it be possible to add a test case to the patch?
cgohlke commentedon Jan 26, 2011
Thank you. The new patch works and it also fixes a crash of the python-2.5.4.amd64 interpreter at startup when ctypes 1.0.2 and pyreadline 1.6.2 are installed.
stanmihai commentedon Jan 31, 2011
attached patch with tests
I have no experience with python development so the tests will actually need a more detailed review. Also I only checked it on win64.
pitrou commentedon Jan 31, 2011
Patch verified to work under Linux and win32. It looks good, except for tab characters in the Modules/_ctypes/_ctypes_test.c (indentation of C files should use 4 spaces); that's a detail that we can fix ourselves.
stanmihai commentedon Jan 31, 2011
ok, please also fix the first parameter of the tests. Because it has the same value in the first call and the callback it will always be right by accident, since the first call puts the value in both standard and floating point registers.
pitrou commentedon Jan 31, 2011
Ok, committed in r88284 (3.2), r88285 (3.1) and r88286 (2.7). Thank you!