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 unwilling to allow pickling wide character
Type: behavior Stage:
Components: ctypes Versions: Python 3.0, Python 3.1, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: theller Nosy List: amaury.forgeotdarc, jaraco, jnoller, theller
Priority: normal Keywords: patch

Created on 2009-01-25 02:52 by jaraco, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg80493 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2009-01-25 02:52
Using Python 2.6.1, I'm unable to pickle a simple object with an array
of wide characters.

import ctypes, pickle

class MyStruct(ctypes.Structure):
  _fields_ = [('name', ctypes.c_wchar*2)]

s = MyStruct('DC')

pickle.dumps(s) # raises ValueError.

Replace ctypes.c_wchar with ctypes.c_char and the pickling works fine.
msg80494 - (view) Author: Jason R. Coombs (jaraco) * (Python committer) Date: 2009-01-25 02:56
I just discovered that trying to pickle a structure with even just a
c_wchar (not an array) also fails.
msg82289 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-02-17 00:27
the "case 'u':" in Module/_ctypes/_ctypes.c (function SimpleType_new)
seems misplaced: u is a scalar type, not a pointer.
Maybe a 's' was intended instead?

Index: Modules/_ctypes/_ctypes.c
===================================================================
--- Modules/_ctypes/_ctypes.c   (revision 68667)
+++ Modules/_ctypes/_ctypes.c   (working copy)
@@ -1951,7 +1951,7 @@
                        ml = &c_void_p_method;
                        stgdict->flags |= TYPEFLAG_ISPOINTER;
                        break;
-               case 'u':
+               case 's':
                case 'X':
                case 'O':
                        ml = NULL;
msg86428 - (view) Author: Thomas Heller (theller) * (Python committer) Date: 2009-04-24 20:18
Thanks, amaury, for the patch.

Fixed in trunk, release26-maint, release30-maint, py3k branch.
SVN revisions 71847, 71848, 71849, 71851.
History
Date User Action Args
2022-04-11 14:56:44adminsetgithub: 49299
2009-04-24 20:18:37thellersetstatus: open -> closed
versions: + Python 3.1, Python 2.7
messages: + msg86428

keywords: - needs review
resolution: fixed
2009-02-17 00:28:12amaury.forgeotdarcsetkeywords: + patch, needs review
2009-02-17 00:27:40amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg82289
2009-01-25 03:21:50jnollersetnosy: + jnoller
2009-01-25 02:56:05jaracosetmessages: + msg80494
title: ctypes unwilling to allow pickling wide character array -> ctypes unwilling to allow pickling wide character
2009-01-25 02:52:25jaracocreate