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 meador.inge
Recipients amaury.forgeotdarc, belopolsky, meador.inge
Date 2011-11-10.05:22:39
SpamBayes Score 3.459899e-12
Marked as misclassified No
Message-id <1320902561.22.0.487865927239.issue13380@psf.upfronthosting.co.za>
In-reply-to
Content
Currently it is possible to somewhat easily get false positives for reference leaks when running the ctypes regression tests with -R.  See issue13250 for an example where I got tripped up.  The reason is that the ctypes caches are not cleared in between test runs like they are with some of the other modules that cache objects.

The attached patch adds an internal function for reseting the ctypes caches.  regrtest.py is then fixed up to use it.  Finally, two tests
that previously relied on the caching being present to work in back-to-back runs have been fixed.  In particular, the tests were written to do something like:

# Global
dll = CDLL(_ctypes_test.__file__)

# Local to test
f = dll._testfunc_callback_i_if
f.restype = c_int

MyCallback = CFUNCTYPE(c_int, c_int)

def callback(value)
    return value

cb = MyCallback(callback)
result = f(-10, cb)

f.argtypes = [c_int, MyCallback]
cb = MyCallback(callback)
result = f(-10, cb)

Thus when run in back-to-back runs where caching is cleared in between you effectively get:

# Global
dll = CDLL(_ctypes_test.__file__)

# Local to test
f = dll._testfunc_callback_i_if
f.restype = c_int

MyCallback = CFUNCTYPE(c_int, c_int)

def callback(value):
    return value

cb = MyCallback(callback)
result = f(-10, cb)

f.argtypes = [c_int, MyCallback]
cb = MyCallback(callback)
result = f(-10, cb)

_reset_cache()

f = dll._testfunc_callback_i_if
f.restype = c_int

MyCallback = CFUNCTYPE(c_int, c_int)

cb = MyCallback(callback)
result = f(-10, cb)

which causes:

types.ArgumentError: argument 2: <class 'TypeError'>: expected CFunctionType instance instead of CFunctionType

because the final MyCallback instance passed to f is not of the same type as the MyCallback type saved in f.argtypes.  The fix is to set f.argtypes to None at the beginning of each test.

I would also like to commit this to 2.7 and 3.2.  It will make fixing true reference leaks in those branches easier.

OK?
History
Date User Action Args
2011-11-10 05:22:41meador.ingesetrecipients: + meador.inge, amaury.forgeotdarc, belopolsky
2011-11-10 05:22:41meador.ingesetmessageid: <1320902561.22.0.487865927239.issue13380@psf.upfronthosting.co.za>
2011-11-10 05:22:40meador.ingelinkissue13380 messages
2011-11-10 05:22:40meador.ingecreate