Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctypes unwilling to allow pickling wide character #49299

Closed
jaraco opened this issue Jan 25, 2009 · 4 comments
Closed

ctypes unwilling to allow pickling wide character #49299

jaraco opened this issue Jan 25, 2009 · 4 comments
Assignees
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error

Comments

@jaraco
Copy link
Member

jaraco commented Jan 25, 2009

BPO 5049
Nosy @theller, @amauryfa, @jaraco

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 = 'https://github.com/theller'
closed_at = <Date 2009-04-24.20:18:37.478>
created_at = <Date 2009-01-25.02:52:25.483>
labels = ['ctypes', 'type-bug']
title = 'ctypes unwilling to allow pickling wide character'
updated_at = <Date 2009-04-24.20:18:37.373>
user = 'https://github.com/jaraco'

bugs.python.org fields:

activity = <Date 2009-04-24.20:18:37.373>
actor = 'theller'
assignee = 'theller'
closed = True
closed_date = <Date 2009-04-24.20:18:37.478>
closer = 'theller'
components = ['ctypes']
creation = <Date 2009-01-25.02:52:25.483>
creator = 'jaraco'
dependencies = []
files = []
hgrepos = []
issue_num = 5049
keywords = ['patch']
message_count = 4.0
messages = ['80493', '80494', '82289', '86428']
nosy_count = 4.0
nosy_names = ['theller', 'amaury.forgeotdarc', 'jaraco', 'jnoller']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5049'
versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7']

@jaraco
Copy link
Member Author

jaraco commented Jan 25, 2009

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.

@jaraco jaraco added topic-ctypes type-bug An unexpected behavior, bug, or error labels Jan 25, 2009
@jaraco
Copy link
Member Author

jaraco commented Jan 25, 2009

I just discovered that trying to pickle a structure with even just a
c_wchar (not an array) also fails.

@jaraco jaraco changed the title ctypes unwilling to allow pickling wide character array ctypes unwilling to allow pickling wide character Jan 25, 2009
@amauryfa
Copy link
Member

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;

@theller
Copy link

theller commented Apr 24, 2009

Thanks, amaury, for the patch.

Fixed in trunk, release26-maint, release30-maint, py3k branch.
SVN revisions 71847, 71848, 71849, 71851.

@theller theller closed this as completed Apr 24, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-ctypes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants