Issue1831
Created on 2008-01-15 13:47 by arigo, last changed 2008-01-16 19:39 by theller.
| msg59964 (view) |
Author: Armin Rigo (arigo) |
Date: 2008-01-15 13:47 |
|
The constructor of ctypes structures should probably not silently accept
the bogus arguments shown in the attached example.
|
| msg59966 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-15 14:53 |
|
Do you have any idea how this could be implemented?
|
| msg59967 (view) |
Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) |
Date: 2008-01-15 14:58 |
|
What about PyArg_ParseTupleAndKeywords()?
|
| msg59968 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-15 15:03 |
|
This would require to build the 'char *format' string at runtime,
the 'char *keywords[]' array too, and pass a variable number of arguments
into the call.
|
| msg59969 (view) |
Author: Armin Rigo (arigo) |
Date: 2008-01-15 15:12 |
|
The pure Python implementation we just wrote in PyPy is:
for name, arg in zip(names, args):
if name in kwds:
raise TypeError("duplicate value for argument %r" % (
name,))
self.__setattr__(name, arg)
for name, arg in kwds.items():
self.__setattr__(name, arg)
It's the same logic as in _ctypes.c:Struct_init(), where you can add the
C equivalent of "if name in kwds" after getting the name.
|
| msg59971 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-15 15:21 |
|
Yes, I came up with a similar solution in the meantime; see the attached
patch.
|
| msg59972 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-15 15:23 |
|
Oops, uploaded the wrong file.
|
| msg59973 (view) |
Author: Armin Rigo (arigo) |
Date: 2008-01-15 16:54 |
|
The patch is missing Py_DECREF(name). Also, I'd raise TypeError
instead of ValueError, just like function calls do in a similar
situation.
|
| msg59981 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-15 18:29 |
|
Ok, added the missing Py_DECREF, changed to TypeError, and added a test.
|
| msg59997 (view) |
Author: Armin Rigo (arigo) |
Date: 2008-01-16 15:40 |
|
For the "too many arguments" case... Clearly (IMHO) it should also
be a TypeError. I have no clue about backward compatibility issues
though.
|
| msg60001 (view) |
Author: Thomas Heller (theller) |
Date: 2008-01-16 19:39 |
|
Committed as rev. 60003 in trunk. I'll also change the "too many
arguments..." exception to a TypeError.
Thanks.
|
|
| Date |
User |
Action |
Args |
| 2008-01-16 19:39:02 | theller | set | status: open -> closed assignee: theller resolution: fixed messages:
+ msg60001 |
| 2008-01-16 15:41:00 | arigo | set | messages:
+ msg59997 |
| 2008-01-15 18:31:53 | theller | set | files:
- ctypes-struct.patch |
| 2008-01-15 18:29:46 | theller | set | files:
+ ctypes-struct.patch messages:
+ msg59981 |
| 2008-01-15 16:54:01 | arigo | set | messages:
+ msg59973 |
| 2008-01-15 15:23:06 | theller | set | files:
+ ctypes-struct.patch messages:
+ msg59972 |
| 2008-01-15 15:22:28 | theller | set | files:
- ctypes-struct.patch |
| 2008-01-15 15:21:46 | theller | set | files:
+ ctypes-struct.patch messages:
+ msg59971 |
| 2008-01-15 15:12:33 | arigo | set | keywords:
+ easy messages:
+ msg59969 |
| 2008-01-15 15:03:45 | theller | set | messages:
+ msg59968 |
| 2008-01-15 14:58:27 | amaury.forgeotdarc | set | nosy:
+ amaury.forgeotdarc messages:
+ msg59967 |
| 2008-01-15 14:53:57 | theller | set | nosy:
+ theller messages:
+ msg59966 |
| 2008-01-15 13:48:03 | arigo | set | type: behavior |
| 2008-01-15 13:47:08 | arigo | create | |
|