@@ -265,7 +265,21 @@ class c_wchar_p(_SimpleCData):
265265class c_wchar (_SimpleCData ):
266266 _type_ = "u"
267267
268- POINTER (c_wchar ).from_param = c_wchar_p .from_param #_SimpleCData.c_wchar_p_from_param
268+ def _reset_cache ():
269+ _pointer_type_cache .clear ()
270+ _c_functype_cache .clear ()
271+ if _os .name in ("nt" , "ce" ):
272+ _win_functype_cache .clear ()
273+ # _SimpleCData.c_wchar_p_from_param
274+ POINTER (c_wchar ).from_param = c_wchar_p .from_param
275+ # _SimpleCData.c_char_p_from_param
276+ POINTER (c_char ).from_param = c_char_p .from_param
277+ _pointer_type_cache [None ] = c_void_p
278+ # XXX for whatever reasons, creating the first instance of a callback
279+ # function is needed for the unittests on Win64 to succeed. This MAY
280+ # be a compiler bug, since the problem occurs only when _ctypes is
281+ # compiled with the MS SDK compiler. Or an uninitialized variable?
282+ CFUNCTYPE (c_int )(lambda : None )
269283
270284def create_unicode_buffer (init , size = None ):
271285 """create_unicode_buffer(aString) -> character array
@@ -285,7 +299,6 @@ def create_unicode_buffer(init, size=None):
285299 return buf
286300 raise TypeError (init )
287301
288- POINTER (c_char ).from_param = c_char_p .from_param #_SimpleCData.c_char_p_from_param
289302
290303# XXX Deprecated
291304def SetPointerType (pointer , cls ):
@@ -445,8 +458,6 @@ def WinError(code=None, descr=None):
445458 descr = FormatError (code ).strip ()
446459 return WindowsError (code , descr )
447460
448- _pointer_type_cache [None ] = c_void_p
449-
450461if sizeof (c_uint ) == sizeof (c_void_p ):
451462 c_size_t = c_uint
452463 c_ssize_t = c_int
@@ -529,8 +540,4 @@ def DllCanUnloadNow():
529540 elif sizeof (kind ) == 8 : c_uint64 = kind
530541del (kind )
531542
532- # XXX for whatever reasons, creating the first instance of a callback
533- # function is needed for the unittests on Win64 to succeed. This MAY
534- # be a compiler bug, since the problem occurs only when _ctypes is
535- # compiled with the MS SDK compiler. Or an uninitialized variable?
536- CFUNCTYPE (c_int )(lambda : None )
543+ _reset_cache ()
0 commit comments