Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5c6af808
Commit
5c6af808
authored
Apr 24, 2009
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #3102: All global symbols that the _ctypes extension defines are
now prefixed with 'Py' or '_ctypes'.
parent
ec21ccde
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
529 additions
and
525 deletions
+529
-525
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+336
-335
Modules/_ctypes/callbacks.c
Modules/_ctypes/callbacks.c
+13
-13
Modules/_ctypes/callproc.c
Modules/_ctypes/callproc.c
+41
-41
Modules/_ctypes/cfield.c
Modules/_ctypes/cfield.c
+46
-46
Modules/_ctypes/ctypes.h
Modules/_ctypes/ctypes.h
+64
-64
Modules/_ctypes/malloc_closure.c
Modules/_ctypes/malloc_closure.c
+2
-2
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+24
-24
No files found.
Misc/NEWS
View file @
5c6af808
...
@@ -244,6 +244,9 @@ Core and Builtins
...
@@ -244,6 +244,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #3102: All global symbols that the _ctypes extension defines
are now prefixed with 'Py' or '_ctypes'.
- Issue #5041: ctypes does now allow pickling wide character.
- Issue #5041: ctypes does now allow pickling wide character.
- Issue #5812: For the two-argument form of the Fraction constructor,
- Issue #5812: For the two-argument form of the Fraction constructor,
...
...
Modules/_ctypes/_ctypes.c
View file @
5c6af808
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
/*
/*
ToDo:
ToDo:
Get rid of the checker (and also the converters) field in CFuncPtrObject and
Get rid of the checker (and also the converters) field in
Py
CFuncPtrObject and
StgDictObject, and replace them by slot functions in StgDictObject.
StgDictObject, and replace them by slot functions in StgDictObject.
think about a buffer-like object (memory? bytes?)
think about a buffer-like object (memory? bytes?)
...
@@ -28,20 +28,20 @@
...
@@ -28,20 +28,20 @@
Name methods, members, getsets
Name methods, members, getsets
==============================================================================
==============================================================================
StructType_Type __new__(), from_address(), __mul__(), from_param()
PyC
StructType_Type __new__(), from_address(), __mul__(), from_param()
UnionType_Type __new__(), from_address(), __mul__(), from_param()
UnionType_Type __new__(), from_address(), __mul__(), from_param()
PointerType_Type __new__(), from_address(), __mul__(), from_param(), set_type()
P
yCP
ointerType_Type __new__(), from_address(), __mul__(), from_param(), set_type()
ArrayType_Type __new__(), from_address(), __mul__(), from_param()
PyC
ArrayType_Type __new__(), from_address(), __mul__(), from_param()
SimpleType_Type __new__(), from_address(), __mul__(), from_param()
PyC
SimpleType_Type __new__(), from_address(), __mul__(), from_param()
CData_Type
Py
CData_Type
Struct_Type __new__(), __init__()
Struct_Type __new__(), __init__()
Pointer_Type __new__(), __init__(), _as_parameter_, contents
P
yCP
ointer_Type __new__(), __init__(), _as_parameter_, contents
Array_Type __new__(), __init__(), _as_parameter_, __get/setitem__(), __len__()
PyC
Array_Type __new__(), __init__(), _as_parameter_, __get/setitem__(), __len__()
Simple_Type __new__(), __init__(), _as_parameter_
Simple_Type __new__(), __init__(), _as_parameter_
CField_Type
Py
CField_Type
StgDict_Type
PyC
StgDict_Type
==============================================================================
==============================================================================
...
@@ -87,20 +87,20 @@ bytes(cdata)
...
@@ -87,20 +87,20 @@ bytes(cdata)
*/
*/
/*
/*
* StgDict_Type
*
PyC
StgDict_Type
* StructType_Type
*
PyC
StructType_Type
* UnionType_Type
* UnionType_Type
* PointerType_Type
* P
yCP
ointerType_Type
* ArrayType_Type
*
PyC
ArrayType_Type
* SimpleType_Type
*
PyC
SimpleType_Type
*
*
* CData_Type
*
Py
CData_Type
* Struct_Type
* Struct_Type
* Union_Type
* Union_Type
* Array_Type
*
PyC
Array_Type
* Simple_Type
* Simple_Type
* Pointer_Type
* P
yCP
ointer_Type
* CField_Type
*
Py
CField_Type
*
*
*/
*/
...
@@ -130,15 +130,15 @@ bytes(cdata)
...
@@ -130,15 +130,15 @@ bytes(cdata)
PyObject
*
PyExc_ArgError
;
PyObject
*
PyExc_ArgError
;
/* This dict maps ctypes types to POINTER types */
/* This dict maps ctypes types to POINTER types */
PyObject
*
_
pointer_
type_cache
;
PyObject
*
_
ctypes_ptr
type_cache
;
static
PyTypeObject
Simple_Type
;
static
PyTypeObject
Simple_Type
;
/* a callable object used for unpickling */
/* a callable object used for unpickling */
static
PyObject
*
_unpickle
;
static
PyObject
*
_unpickle
;
char
*
conversion_mode
_encoding
=
NULL
;
char
*
_ctypes_conversion
_encoding
=
NULL
;
char
*
conversion_mode
_errors
=
NULL
;
char
*
_ctypes_conversion
_errors
=
NULL
;
/****************************************************************/
/****************************************************************/
...
@@ -300,7 +300,7 @@ PyDict_GetItemProxy(PyObject *dict, PyObject *key)
...
@@ -300,7 +300,7 @@ PyDict_GetItemProxy(PyObject *dict, PyObject *key)
already be set.
already be set.
*/
*/
char
*
char
*
alloc_format_string
(
const
char
*
prefix
,
const
char
*
suffix
)
_ctypes_
alloc_format_string
(
const
char
*
prefix
,
const
char
*
suffix
)
{
{
size_t
len
;
size_t
len
;
char
*
result
;
char
*
result
;
...
@@ -324,7 +324,7 @@ alloc_format_string(const char *prefix, const char *suffix)
...
@@ -324,7 +324,7 @@ alloc_format_string(const char *prefix, const char *suffix)
}
}
/*
/*
StructType_Type - a meta type/class. Creating a new class using this one as
PyC
StructType_Type - a meta type/class. Creating a new class using this one as
__metaclass__ will call the contructor StructUnionType_new. It replaces the
__metaclass__ will call the contructor StructUnionType_new. It replaces the
tp_dict member with a new instance of StgDict, and initializes the C
tp_dict member with a new instance of StgDict, and initializes the C
accessible fields somehow.
accessible fields somehow.
...
@@ -336,7 +336,7 @@ StructUnionType_paramfunc(CDataObject *self)
...
@@ -336,7 +336,7 @@ StructUnionType_paramfunc(CDataObject *self)
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
StgDictObject
*
stgdict
;
StgDictObject
*
stgdict
;
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -372,7 +372,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
...
@@ -372,7 +372,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
if
(
PyDict_GetItemString
(
result
->
tp_dict
,
"_abstract_"
))
if
(
PyDict_GetItemString
(
result
->
tp_dict
,
"_abstract_"
))
return
(
PyObject
*
)
result
;
return
(
PyObject
*
)
result
;
dict
=
(
StgDictObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
StgDict_Type
,
NULL
);
dict
=
(
StgDictObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
dict
)
{
if
(
!
dict
)
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
return
NULL
;
return
NULL
;
...
@@ -386,7 +386,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
...
@@ -386,7 +386,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
}
}
Py_DECREF
(
result
->
tp_dict
);
Py_DECREF
(
result
->
tp_dict
);
result
->
tp_dict
=
(
PyObject
*
)
dict
;
result
->
tp_dict
=
(
PyObject
*
)
dict
;
dict
->
format
=
alloc_format_string
(
NULL
,
"B"
);
dict
->
format
=
_ctypes_
alloc_format_string
(
NULL
,
"B"
);
if
(
dict
->
format
==
NULL
)
{
if
(
dict
->
format
==
NULL
)
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
return
NULL
;
return
NULL
;
...
@@ -401,7 +401,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
...
@@ -401,7 +401,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
if
(
basedict
==
NULL
)
if
(
basedict
==
NULL
)
return
(
PyObject
*
)
result
;
return
(
PyObject
*
)
result
;
/* copy base dict */
/* copy base dict */
if
(
-
1
==
StgDict_clone
(
dict
,
basedict
))
{
if
(
-
1
==
PyC
StgDict_clone
(
dict
,
basedict
))
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
return
NULL
;
return
NULL
;
}
}
...
@@ -418,7 +418,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
...
@@ -418,7 +418,7 @@ StructUnionType_new(PyTypeObject *type, PyObject *args, PyObject *kwds, int isSt
}
}
static
PyObject
*
static
PyObject
*
StructType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
PyC
StructType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
return
StructUnionType_new
(
type
,
args
,
kwds
,
1
);
return
StructUnionType_new
(
type
,
args
,
kwds
,
1
);
}
}
...
@@ -444,7 +444,7 @@ CDataType_from_address(PyObject *type, PyObject *value)
...
@@ -444,7 +444,7 @@ CDataType_from_address(PyObject *type, PyObject *value)
buf
=
(
void
*
)
PyLong_AsVoidPtr
(
value
);
buf
=
(
void
*
)
PyLong_AsVoidPtr
(
value
);
if
(
PyErr_Occurred
())
if
(
PyErr_Occurred
())
return
NULL
;
return
NULL
;
return
CData_AtAddress
(
type
,
buf
);
return
Py
CData_AtAddress
(
type
,
buf
);
}
}
static
char
from_buffer_doc
[]
=
static
char
from_buffer_doc
[]
=
...
@@ -491,7 +491,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
...
@@ -491,7 +491,7 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
return
NULL
;
return
NULL
;
}
}
result
=
CData_AtAddress
(
type
,
(
char
*
)
buffer
+
offset
);
result
=
Py
CData_AtAddress
(
type
,
(
char
*
)
buffer
+
offset
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -507,7 +507,7 @@ static char from_buffer_copy_doc[] =
...
@@ -507,7 +507,7 @@ static char from_buffer_copy_doc[] =
"C.from_buffer_copy(object, offset=0) -> C instance
\n
create a C instance from a readable buffer"
;
"C.from_buffer_copy(object, offset=0) -> C instance
\n
create a C instance from a readable buffer"
;
static
PyObject
*
static
PyObject
*
GenericCData_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
);
Generic
Py
CData_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
);
static
PyObject
*
static
PyObject
*
CDataType_from_buffer_copy
(
PyObject
*
type
,
PyObject
*
args
)
CDataType_from_buffer_copy
(
PyObject
*
type
,
PyObject
*
args
)
...
@@ -548,7 +548,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
...
@@ -548,7 +548,7 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
return
NULL
;
return
NULL
;
}
}
result
=
GenericCData_new
((
PyTypeObject
*
)
type
,
NULL
,
NULL
);
result
=
Generic
Py
CData_new
((
PyTypeObject
*
)
type
,
NULL
,
NULL
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
NULL
;
return
NULL
;
memcpy
(((
CDataObject
*
)
result
)
->
b_ptr
,
memcpy
(((
CDataObject
*
)
result
)
->
b_ptr
,
...
@@ -610,7 +610,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
...
@@ -610,7 +610,7 @@ CDataType_in_dll(PyObject *type, PyObject *args)
return
NULL
;
return
NULL
;
}
}
#endif
#endif
return
CData_AtAddress
(
type
,
address
);
return
Py
CData_AtAddress
(
type
,
address
);
}
}
static
char
from_param_doc
[]
=
static
char
from_param_doc
[]
=
...
@@ -678,7 +678,7 @@ CDataType_repeat(PyObject *self, Py_ssize_t length)
...
@@ -678,7 +678,7 @@ CDataType_repeat(PyObject *self, Py_ssize_t length)
"Array length must be >= 0, not %zd"
,
"Array length must be >= 0, not %zd"
,
#endif
#endif
length
);
length
);
return
CreateArrayT
ype
(
self
,
length
);
return
PyCArrayType_from_ct
ype
(
self
,
length
);
}
}
static
PySequenceMethods
CDataType_as_sequence
=
{
static
PySequenceMethods
CDataType_as_sequence
=
{
...
@@ -714,7 +714,7 @@ CDataType_traverse(PyTypeObject *self, visitproc visit, void *arg)
...
@@ -714,7 +714,7 @@ CDataType_traverse(PyTypeObject *self, visitproc visit, void *arg)
}
}
static
int
static
int
StructType_setattro
(
PyObject
*
self
,
PyObject
*
key
,
PyObject
*
value
)
PyC
StructType_setattro
(
PyObject
*
self
,
PyObject
*
key
,
PyObject
*
value
)
{
{
/* XXX Should we disallow deleting _fields_? */
/* XXX Should we disallow deleting _fields_? */
if
(
-
1
==
PyType_Type
.
tp_setattro
(
self
,
key
,
value
))
if
(
-
1
==
PyType_Type
.
tp_setattro
(
self
,
key
,
value
))
...
@@ -722,7 +722,7 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
...
@@ -722,7 +722,7 @@ StructType_setattro(PyObject *self, PyObject *key, PyObject *value)
if
(
value
&&
PyString_Check
(
key
)
&&
if
(
value
&&
PyString_Check
(
key
)
&&
0
==
strcmp
(
PyString_AS_STRING
(
key
),
"_fields_"
))
0
==
strcmp
(
PyString_AS_STRING
(
key
),
"_fields_"
))
return
StructUnionType_update_stgdict
(
self
,
value
,
1
);
return
PyC
StructUnionType_update_stgdict
(
self
,
value
,
1
);
return
0
;
return
0
;
}
}
...
@@ -736,14 +736,14 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
...
@@ -736,14 +736,14 @@ UnionType_setattro(PyObject *self, PyObject *key, PyObject *value)
if
(
PyString_Check
(
key
)
&&
if
(
PyString_Check
(
key
)
&&
0
==
strcmp
(
PyString_AS_STRING
(
key
),
"_fields_"
))
0
==
strcmp
(
PyString_AS_STRING
(
key
),
"_fields_"
))
return
StructUnionType_update_stgdict
(
self
,
value
,
0
);
return
PyC
StructUnionType_update_stgdict
(
self
,
value
,
0
);
return
0
;
return
0
;
}
}
PyTypeObject
StructType_Type
=
{
PyTypeObject
PyC
StructType_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.StructType"
,
/* tp_name */
"_ctypes.
PyC
StructType"
,
/* tp_name */
0
,
/* tp_basicsize */
0
,
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_dealloc */
...
@@ -759,7 +759,7 @@ PyTypeObject StructType_Type = {
...
@@ -759,7 +759,7 @@ PyTypeObject StructType_Type = {
0
,
/* tp_call */
0
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
StructType_setattro
,
/* tp_setattro */
PyC
StructType_setattro
,
/* tp_setattro */
0
,
/* tp_as_buffer */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
"metatype for the CData Objects"
,
/* tp_doc */
"metatype for the CData Objects"
,
/* tp_doc */
...
@@ -779,7 +779,7 @@ PyTypeObject StructType_Type = {
...
@@ -779,7 +779,7 @@ PyTypeObject StructType_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
StructType_new
,
/* tp_new */
PyC
StructType_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
...
@@ -830,20 +830,20 @@ static PyTypeObject UnionType_Type = {
...
@@ -830,20 +830,20 @@ static PyTypeObject UnionType_Type = {
/*
/*
The PointerType_Type metaclass must ensure that the subclass of Pointer can be
The P
yCP
ointerType_Type metaclass must ensure that the subclass of Pointer can be
created. It must check for a _type_ attribute in the class. Since are no
created. It must check for a _type_ attribute in the class. Since are no
runtime created properties, a CField is probably *not* needed ?
runtime created properties, a CField is probably *not* needed ?
class IntPointer(Pointer):
class IntPointer(Pointer):
_type_ = "i"
_type_ = "i"
The Pointer_Type provides the functionality: a contents method/property, a
The P
yCP
ointer_Type provides the functionality: a contents method/property, a
size property/method, and the sequence protocol.
size property/method, and the sequence protocol.
*/
*/
static
int
static
int
PointerType_SetProto
(
StgDictObject
*
stgdict
,
PyObject
*
proto
)
P
yCP
ointerType_SetProto
(
StgDictObject
*
stgdict
,
PyObject
*
proto
)
{
{
if
(
!
proto
||
!
PyType_Check
(
proto
))
{
if
(
!
proto
||
!
PyType_Check
(
proto
))
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
...
@@ -862,11 +862,11 @@ PointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
...
@@ -862,11 +862,11 @@ PointerType_SetProto(StgDictObject *stgdict, PyObject *proto)
}
}
static
PyCArgObject
*
static
PyCArgObject
*
PointerType_paramfunc
(
CDataObject
*
self
)
P
yCP
ointerType_paramfunc
(
CDataObject
*
self
)
{
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -879,7 +879,7 @@ PointerType_paramfunc(CDataObject *self)
...
@@ -879,7 +879,7 @@ PointerType_paramfunc(CDataObject *self)
}
}
static
PyObject
*
static
PyObject
*
PointerType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
P
yCP
ointerType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
PyTypeObject
*
result
;
PyTypeObject
*
result
;
StgDictObject
*
stgdict
;
StgDictObject
*
stgdict
;
...
@@ -894,18 +894,18 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -894,18 +894,18 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
stgdict->proto has info about the pointed to type!
stgdict->proto has info about the pointed to type!
*/
*/
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
(
PyObject
*
)
&
StgDict_Type
,
NULL
);
(
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
stgdict
)
if
(
!
stgdict
)
return
NULL
;
return
NULL
;
stgdict
->
size
=
sizeof
(
void
*
);
stgdict
->
size
=
sizeof
(
void
*
);
stgdict
->
align
=
getentry
(
"P"
)
->
pffi_type
->
alignment
;
stgdict
->
align
=
_ctypes_get_fielddesc
(
"P"
)
->
pffi_type
->
alignment
;
stgdict
->
length
=
1
;
stgdict
->
length
=
1
;
stgdict
->
ffi_type_pointer
=
ffi_type_pointer
;
stgdict
->
ffi_type_pointer
=
ffi_type_pointer
;
stgdict
->
paramfunc
=
PointerType_paramfunc
;
stgdict
->
paramfunc
=
P
yCP
ointerType_paramfunc
;
stgdict
->
flags
|=
TYPEFLAG_ISPOINTER
;
stgdict
->
flags
|=
TYPEFLAG_ISPOINTER
;
proto
=
PyDict_GetItemString
(
typedict
,
"_type_"
);
/* Borrowed ref */
proto
=
PyDict_GetItemString
(
typedict
,
"_type_"
);
/* Borrowed ref */
if
(
proto
&&
-
1
==
PointerType_SetProto
(
stgdict
,
proto
))
{
if
(
proto
&&
-
1
==
P
yCP
ointerType_SetProto
(
stgdict
,
proto
))
{
Py_DECREF
((
PyObject
*
)
stgdict
);
Py_DECREF
((
PyObject
*
)
stgdict
);
return
NULL
;
return
NULL
;
}
}
...
@@ -918,7 +918,7 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -918,7 +918,7 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
'pointer to bytes' in this case. XXX Better would be to
'pointer to bytes' in this case. XXX Better would be to
fix the format string later...
fix the format string later...
*/
*/
stgdict
->
format
=
alloc_format_string
(
"&"
,
stgdict
->
format
=
_ctypes_
alloc_format_string
(
"&"
,
itemdict
->
format
?
itemdict
->
format
:
"B"
);
itemdict
->
format
?
itemdict
->
format
:
"B"
);
if
(
stgdict
->
format
==
NULL
)
{
if
(
stgdict
->
format
==
NULL
)
{
Py_DECREF
((
PyObject
*
)
stgdict
);
Py_DECREF
((
PyObject
*
)
stgdict
);
...
@@ -948,14 +948,14 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -948,14 +948,14 @@ PointerType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static
PyObject
*
static
PyObject
*
PointerType_set_type
(
PyTypeObject
*
self
,
PyObject
*
type
)
P
yCP
ointerType_set_type
(
PyTypeObject
*
self
,
PyObject
*
type
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
dict
=
PyType_stgdict
((
PyObject
*
)
self
);
dict
=
PyType_stgdict
((
PyObject
*
)
self
);
assert
(
dict
);
assert
(
dict
);
if
(
-
1
==
PointerType_SetProto
(
dict
,
type
))
if
(
-
1
==
P
yCP
ointerType_SetProto
(
dict
,
type
))
return
NULL
;
return
NULL
;
if
(
-
1
==
PyDict_SetItemString
((
PyObject
*
)
dict
,
"_type_"
,
type
))
if
(
-
1
==
PyDict_SetItemString
((
PyObject
*
)
dict
,
"_type_"
,
type
))
...
@@ -968,7 +968,7 @@ PointerType_set_type(PyTypeObject *self, PyObject *type)
...
@@ -968,7 +968,7 @@ PointerType_set_type(PyTypeObject *self, PyObject *type)
staticforward
PyObject
*
_byref
(
PyObject
*
);
staticforward
PyObject
*
_byref
(
PyObject
*
);
static
PyObject
*
static
PyObject
*
PointerType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
P
yCP
ointerType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
StgDictObject
*
typedict
;
StgDictObject
*
typedict
;
...
@@ -1006,19 +1006,19 @@ PointerType_from_param(PyObject *type, PyObject *value)
...
@@ -1006,19 +1006,19 @@ PointerType_from_param(PyObject *type, PyObject *value)
return
CDataType_from_param
(
type
,
value
);
return
CDataType_from_param
(
type
,
value
);
}
}
static
PyMethodDef
PointerType_methods
[]
=
{
static
PyMethodDef
P
yCP
ointerType_methods
[]
=
{
{
"from_address"
,
CDataType_from_address
,
METH_O
,
from_address_doc
},
{
"from_address"
,
CDataType_from_address
,
METH_O
,
from_address_doc
},
{
"from_buffer"
,
CDataType_from_buffer
,
METH_VARARGS
,
from_buffer_doc
,
},
{
"from_buffer"
,
CDataType_from_buffer
,
METH_VARARGS
,
from_buffer_doc
,
},
{
"from_buffer_copy"
,
CDataType_from_buffer_copy
,
METH_VARARGS
,
from_buffer_copy_doc
,
},
{
"from_buffer_copy"
,
CDataType_from_buffer_copy
,
METH_VARARGS
,
from_buffer_copy_doc
,
},
{
"in_dll"
,
CDataType_in_dll
,
METH_VARARGS
,
in_dll_doc
},
{
"in_dll"
,
CDataType_in_dll
,
METH_VARARGS
,
in_dll_doc
},
{
"from_param"
,
(
PyCFunction
)
PointerType_from_param
,
METH_O
,
from_param_doc
},
{
"from_param"
,
(
PyCFunction
)
P
yCP
ointerType_from_param
,
METH_O
,
from_param_doc
},
{
"set_type"
,
(
PyCFunction
)
PointerType_set_type
,
METH_O
},
{
"set_type"
,
(
PyCFunction
)
P
yCP
ointerType_set_type
,
METH_O
},
{
NULL
,
NULL
},
{
NULL
,
NULL
},
};
};
PyTypeObject
PointerType_Type
=
{
PyTypeObject
P
yCP
ointerType_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.PointerType"
,
/* tp_name */
"_ctypes.P
yCP
ointerType"
,
/* tp_name */
0
,
/* tp_basicsize */
0
,
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_dealloc */
...
@@ -1044,7 +1044,7 @@ PyTypeObject PointerType_Type = {
...
@@ -1044,7 +1044,7 @@ PyTypeObject PointerType_Type = {
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
PointerType_methods
,
/* tp_methods */
P
yCP
ointerType_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
...
@@ -1054,17 +1054,17 @@ PyTypeObject PointerType_Type = {
...
@@ -1054,17 +1054,17 @@ PyTypeObject PointerType_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
PointerType_new
,
/* tp_new */
P
yCP
ointerType_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
/******************************************************************/
/******************************************************************/
/*
/*
ArrayType_Type
PyC
ArrayType_Type
*/
*/
/*
/*
ArrayType_new ensures that the new Array subclass created has a _length_
PyC
ArrayType_new ensures that the new Array subclass created has a _length_
attribute, and a _type_ attribute.
attribute, and a _type_ attribute.
*/
*/
...
@@ -1122,8 +1122,8 @@ CharArray_set_value(CDataObject *self, PyObject *value)
...
@@ -1122,8 +1122,8 @@ CharArray_set_value(CDataObject *self, PyObject *value)
if
(
PyUnicode_Check
(
value
))
{
if
(
PyUnicode_Check
(
value
))
{
value
=
PyUnicode_AsEncodedString
(
value
,
value
=
PyUnicode_AsEncodedString
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
-
1
;
return
-
1
;
}
else
if
(
!
PyString_Check
(
value
))
{
}
else
if
(
!
PyString_Check
(
value
))
{
...
@@ -1182,8 +1182,8 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
...
@@ -1182,8 +1182,8 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
}
}
if
(
PyString_Check
(
value
))
{
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
-
1
;
return
-
1
;
}
else
if
(
!
PyUnicode_Check
(
value
))
{
}
else
if
(
!
PyUnicode_Check
(
value
))
{
...
@@ -1275,9 +1275,9 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp)
...
@@ -1275,9 +1275,9 @@ add_getset(PyTypeObject *type, PyGetSetDef *gsp)
}
}
static
PyCArgObject
*
static
PyCArgObject
*
ArrayType_paramfunc
(
CDataObject
*
self
)
PyC
ArrayType_paramfunc
(
CDataObject
*
self
)
{
{
PyCArgObject
*
p
=
new_CArgObject
();
PyCArgObject
*
p
=
PyCArgObject_new
();
if
(
p
==
NULL
)
if
(
p
==
NULL
)
return
NULL
;
return
NULL
;
p
->
tag
=
'P'
;
p
->
tag
=
'P'
;
...
@@ -1289,7 +1289,7 @@ ArrayType_paramfunc(CDataObject *self)
...
@@ -1289,7 +1289,7 @@ ArrayType_paramfunc(CDataObject *self)
}
}
static
PyObject
*
static
PyObject
*
ArrayType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
PyC
ArrayType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
PyTypeObject
*
result
;
PyTypeObject
*
result
;
StgDictObject
*
stgdict
;
StgDictObject
*
stgdict
;
...
@@ -1322,7 +1322,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1322,7 +1322,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
(
PyObject
*
)
&
StgDict_Type
,
NULL
);
(
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
stgdict
)
if
(
!
stgdict
)
return
NULL
;
return
NULL
;
...
@@ -1337,10 +1337,10 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1337,10 +1337,10 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
assert
(
itemdict
->
format
);
assert
(
itemdict
->
format
);
if
(
itemdict
->
format
[
0
]
==
'('
)
{
if
(
itemdict
->
format
[
0
]
==
'('
)
{
sprintf
(
buf
,
"(%ld,"
,
length
);
sprintf
(
buf
,
"(%ld,"
,
length
);
stgdict
->
format
=
alloc_format_string
(
buf
,
itemdict
->
format
+
1
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
buf
,
itemdict
->
format
+
1
);
}
else
{
}
else
{
sprintf
(
buf
,
"(%ld)"
,
length
);
sprintf
(
buf
,
"(%ld)"
,
length
);
stgdict
->
format
=
alloc_format_string
(
buf
,
itemdict
->
format
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
buf
,
itemdict
->
format
);
}
}
if
(
stgdict
->
format
==
NULL
)
{
if
(
stgdict
->
format
==
NULL
)
{
Py_DECREF
((
PyObject
*
)
stgdict
);
Py_DECREF
((
PyObject
*
)
stgdict
);
...
@@ -1374,7 +1374,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1374,7 +1374,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
Py_INCREF
(
proto
);
Py_INCREF
(
proto
);
stgdict
->
proto
=
proto
;
stgdict
->
proto
=
proto
;
stgdict
->
paramfunc
=
&
ArrayType_paramfunc
;
stgdict
->
paramfunc
=
&
PyC
ArrayType_paramfunc
;
/* Arrays are passed as pointers to function calls. */
/* Arrays are passed as pointers to function calls. */
stgdict
->
ffi_type_pointer
=
ffi_type_pointer
;
stgdict
->
ffi_type_pointer
=
ffi_type_pointer
;
...
@@ -1397,11 +1397,11 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1397,11 +1397,11 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
/* Special case for character arrays.
/* Special case for character arrays.
A permanent annoyance: char arrays are also strings!
A permanent annoyance: char arrays are also strings!
*/
*/
if
(
itemdict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
if
(
-
1
==
add_getset
(
result
,
CharArray_getsets
))
if
(
-
1
==
add_getset
(
result
,
CharArray_getsets
))
return
NULL
;
return
NULL
;
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
}
else
if
(
itemdict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
}
else
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
if
(
-
1
==
add_getset
(
result
,
WCharArray_getsets
))
if
(
-
1
==
add_getset
(
result
,
WCharArray_getsets
))
return
NULL
;
return
NULL
;
#endif
#endif
...
@@ -1410,9 +1410,9 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1410,9 +1410,9 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
(
PyObject
*
)
result
;
return
(
PyObject
*
)
result
;
}
}
PyTypeObject
ArrayType_Type
=
{
PyTypeObject
PyC
ArrayType_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.ArrayType"
,
/* tp_name */
"_ctypes.
PyC
ArrayType"
,
/* tp_name */
0
,
/* tp_basicsize */
0
,
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_dealloc */
...
@@ -1448,18 +1448,18 @@ PyTypeObject ArrayType_Type = {
...
@@ -1448,18 +1448,18 @@ PyTypeObject ArrayType_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
ArrayType_new
,
/* tp_new */
PyC
ArrayType_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
/******************************************************************/
/******************************************************************/
/*
/*
SimpleType_Type
PyC
SimpleType_Type
*/
*/
/*
/*
SimpleType_new ensures that the new Simple_Type subclass created has a valid
PyC
SimpleType_new ensures that the new Simple_Type subclass created has a valid
_type_ attribute.
_type_ attribute.
*/
*/
...
@@ -1479,9 +1479,9 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
...
@@ -1479,9 +1479,9 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
}
}
if
(
PyUnicode_Check
(
value
)
||
PyString_Check
(
value
))
{
if
(
PyUnicode_Check
(
value
)
||
PyString_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
=
getentry
(
"Z"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"Z"
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1503,7 +1503,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
...
@@ -1503,7 +1503,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
StgDictObject
*
dict
;
StgDictObject
*
dict
;
assert
(
dt
);
/* Cannot be NULL for pointer or array objects */
assert
(
dt
);
/* Cannot be NULL for pointer or array objects */
dict
=
dt
&&
dt
->
proto
?
PyType_stgdict
(
dt
->
proto
)
:
NULL
;
dict
=
dt
&&
dt
->
proto
?
PyType_stgdict
(
dt
->
proto
)
:
NULL
;
if
(
dict
&&
(
dict
->
setfunc
==
getentry
(
"u"
)
->
setfunc
))
{
if
(
dict
&&
(
dict
->
setfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
setfunc
))
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1512,7 +1512,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
...
@@ -1512,7 +1512,7 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
/* byref(c_char(...)) */
/* byref(c_char(...)) */
PyCArgObject
*
a
=
(
PyCArgObject
*
)
value
;
PyCArgObject
*
a
=
(
PyCArgObject
*
)
value
;
StgDictObject
*
dict
=
PyObject_stgdict
(
a
->
obj
);
StgDictObject
*
dict
=
PyObject_stgdict
(
a
->
obj
);
if
(
dict
&&
(
dict
->
setfunc
==
getentry
(
"u"
)
->
setfunc
))
{
if
(
dict
&&
(
dict
->
setfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
setfunc
))
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1543,9 +1543,9 @@ c_char_p_from_param(PyObject *type, PyObject *value)
...
@@ -1543,9 +1543,9 @@ c_char_p_from_param(PyObject *type, PyObject *value)
}
}
if
(
PyString_Check
(
value
)
||
PyUnicode_Check
(
value
))
{
if
(
PyString_Check
(
value
)
||
PyUnicode_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
=
getentry
(
"z"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"z"
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1567,7 +1567,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
...
@@ -1567,7 +1567,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
StgDictObject
*
dict
;
StgDictObject
*
dict
;
assert
(
dt
);
/* Cannot be NULL for pointer or array objects */
assert
(
dt
);
/* Cannot be NULL for pointer or array objects */
dict
=
dt
&&
dt
->
proto
?
PyType_stgdict
(
dt
->
proto
)
:
NULL
;
dict
=
dt
&&
dt
->
proto
?
PyType_stgdict
(
dt
->
proto
)
:
NULL
;
if
(
dict
&&
(
dict
->
setfunc
==
getentry
(
"c"
)
->
setfunc
))
{
if
(
dict
&&
(
dict
->
setfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
setfunc
))
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1576,7 +1576,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
...
@@ -1576,7 +1576,7 @@ c_char_p_from_param(PyObject *type, PyObject *value)
/* byref(c_char(...)) */
/* byref(c_char(...)) */
PyCArgObject
*
a
=
(
PyCArgObject
*
)
value
;
PyCArgObject
*
a
=
(
PyCArgObject
*
)
value
;
StgDictObject
*
dict
=
PyObject_stgdict
(
a
->
obj
);
StgDictObject
*
dict
=
PyObject_stgdict
(
a
->
obj
);
if
(
dict
&&
(
dict
->
setfunc
==
getentry
(
"c"
)
->
setfunc
))
{
if
(
dict
&&
(
dict
->
setfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
setfunc
))
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1612,9 +1612,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1612,9 +1612,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
/* int, long */
/* int, long */
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
=
getentry
(
"P"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"P"
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1629,9 +1629,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1629,9 +1629,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
/* string */
/* string */
if
(
PyString_Check
(
value
))
{
if
(
PyString_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
=
getentry
(
"z"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"z"
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1646,9 +1646,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1646,9 +1646,9 @@ c_void_p_from_param(PyObject *type, PyObject *value)
/* unicode */
/* unicode */
if
(
PyUnicode_Check
(
value
))
{
if
(
PyUnicode_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
=
getentry
(
"Z"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"Z"
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1682,11 +1682,11 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1682,11 +1682,11 @@ c_void_p_from_param(PyObject *type, PyObject *value)
}
}
}
}
/* function pointer */
/* function pointer */
if
(
CFuncPtrObject_Check
(
value
))
{
if
(
Py
CFuncPtrObject_Check
(
value
))
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
CFuncPtrObject
*
func
;
Py
CFuncPtrObject
*
func
;
func
=
(
CFuncPtrObject
*
)
value
;
func
=
(
Py
CFuncPtrObject
*
)
value
;
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1704,7 +1704,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1704,7 +1704,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
switch
(
PyString_AS_STRING
(
stgd
->
proto
)[
0
])
{
switch
(
PyString_AS_STRING
(
stgd
->
proto
)[
0
])
{
case
'z'
:
/* c_char_p */
case
'z'
:
/* c_char_p */
case
'Z'
:
/* c_wchar_p */
case
'Z'
:
/* c_wchar_p */
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
parg
->
pffi_type
=
&
ffi_type_pointer
;
...
@@ -1783,7 +1783,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
...
@@ -1783,7 +1783,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
return
NULL
;
return
NULL
;
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
(
PyObject
*
)
&
StgDict_Type
,
NULL
);
(
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
stgdict
)
/* XXX leaks result! */
if
(
!
stgdict
)
/* XXX leaks result! */
return
NULL
;
return
NULL
;
...
@@ -1810,7 +1810,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
...
@@ -1810,7 +1810,7 @@ static PyObject *CreateSwappedType(PyTypeObject *type, PyObject *args, PyObject
}
}
static
PyCArgObject
*
static
PyCArgObject
*
SimpleType_paramfunc
(
CDataObject
*
self
)
PyC
SimpleType_paramfunc
(
CDataObject
*
self
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
char
*
fmt
;
char
*
fmt
;
...
@@ -1822,10 +1822,10 @@ SimpleType_paramfunc(CDataObject *self)
...
@@ -1822,10 +1822,10 @@ SimpleType_paramfunc(CDataObject *self)
fmt
=
PyString_AsString
(
dict
->
proto
);
fmt
=
PyString_AsString
(
dict
->
proto
);
assert
(
fmt
);
assert
(
fmt
);
fd
=
getentry
(
fmt
);
fd
=
_ctypes_get_fielddesc
(
fmt
);
assert
(
fd
);
assert
(
fd
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -1838,7 +1838,7 @@ SimpleType_paramfunc(CDataObject *self)
...
@@ -1838,7 +1838,7 @@ SimpleType_paramfunc(CDataObject *self)
}
}
static
PyObject
*
static
PyObject
*
SimpleType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
PyC
SimpleType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
PyTypeObject
*
result
;
PyTypeObject
*
result
;
StgDictObject
*
stgdict
;
StgDictObject
*
stgdict
;
...
@@ -1884,7 +1884,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1884,7 +1884,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
SIMPLE_TYPE_CHARS
);
SIMPLE_TYPE_CHARS
);
goto
error
;
goto
error
;
}
}
fmt
=
getentry
(
PyString_AS_STRING
(
proto
));
fmt
=
_ctypes_get_fielddesc
(
PyString_AS_STRING
(
proto
));
if
(
fmt
==
NULL
)
{
if
(
fmt
==
NULL
)
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
PyErr_Format
(
PyExc_ValueError
,
PyErr_Format
(
PyExc_ValueError
,
...
@@ -1894,7 +1894,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1894,7 +1894,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
(
PyObject
*
)
&
StgDict_Type
,
NULL
);
(
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
stgdict
)
if
(
!
stgdict
)
return
NULL
;
return
NULL
;
...
@@ -1905,9 +1905,9 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1905,9 +1905,9 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
stgdict
->
setfunc
=
fmt
->
setfunc
;
stgdict
->
setfunc
=
fmt
->
setfunc
;
stgdict
->
getfunc
=
fmt
->
getfunc
;
stgdict
->
getfunc
=
fmt
->
getfunc
;
#ifdef WORDS_BIGENDIAN
#ifdef WORDS_BIGENDIAN
stgdict
->
format
=
alloc_format_string
(
">"
,
proto_str
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
">"
,
proto_str
);
#else
#else
stgdict
->
format
=
alloc_format_string
(
"<"
,
proto_str
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
"<"
,
proto_str
);
#endif
#endif
if
(
stgdict
->
format
==
NULL
)
{
if
(
stgdict
->
format
==
NULL
)
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
...
@@ -1915,7 +1915,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1915,7 +1915,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
return
NULL
;
}
}
stgdict
->
paramfunc
=
SimpleType_paramfunc
;
stgdict
->
paramfunc
=
PyC
SimpleType_paramfunc
;
/*
/*
if (result->tp_base != &Simple_Type) {
if (result->tp_base != &Simple_Type) {
stgdict->setfunc = NULL;
stgdict->setfunc = NULL;
...
@@ -1936,7 +1936,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1936,7 +1936,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
result
->
tp_dict
=
(
PyObject
*
)
stgdict
;
result
->
tp_dict
=
(
PyObject
*
)
stgdict
;
/* Install from_param class methods in ctypes base classes.
/* Install from_param class methods in ctypes base classes.
Overrides the SimpleType_from_param generic method.
Overrides the
PyC
SimpleType_from_param generic method.
*/
*/
if
(
result
->
tp_base
==
&
Simple_Type
)
{
if
(
result
->
tp_base
==
&
Simple_Type
)
{
switch
(
PyString_AS_STRING
(
proto
)[
0
])
{
switch
(
PyString_AS_STRING
(
proto
)[
0
])
{
...
@@ -1996,7 +1996,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -1996,7 +1996,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
}
}
if
(
type
==
&
SimpleType_Type
&&
fmt
->
setfunc_swapped
&&
fmt
->
getfunc_swapped
)
{
if
(
type
==
&
PyC
SimpleType_Type
&&
fmt
->
setfunc_swapped
&&
fmt
->
getfunc_swapped
)
{
PyObject
*
swapped
=
CreateSwappedType
(
type
,
args
,
kwds
,
PyObject
*
swapped
=
CreateSwappedType
(
type
,
args
,
kwds
,
proto
,
fmt
);
proto
,
fmt
);
StgDictObject
*
sw_dict
;
StgDictObject
*
sw_dict
;
...
@@ -2011,14 +2011,14 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2011,14 +2011,14 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject_SetAttrString
(
swapped
,
"__ctype_be__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
(
swapped
,
"__ctype_be__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
(
swapped
,
"__ctype_le__"
,
swapped
);
PyObject_SetAttrString
(
swapped
,
"__ctype_le__"
,
swapped
);
/* We are creating the type for the OTHER endian */
/* We are creating the type for the OTHER endian */
sw_dict
->
format
=
alloc_format_string
(
"<"
,
stgdict
->
format
+
1
);
sw_dict
->
format
=
_ctypes_
alloc_format_string
(
"<"
,
stgdict
->
format
+
1
);
#else
#else
PyObject_SetAttrString
((
PyObject
*
)
result
,
"__ctype_be__"
,
swapped
);
PyObject_SetAttrString
((
PyObject
*
)
result
,
"__ctype_be__"
,
swapped
);
PyObject_SetAttrString
((
PyObject
*
)
result
,
"__ctype_le__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
((
PyObject
*
)
result
,
"__ctype_le__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
(
swapped
,
"__ctype_le__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
(
swapped
,
"__ctype_le__"
,
(
PyObject
*
)
result
);
PyObject_SetAttrString
(
swapped
,
"__ctype_be__"
,
swapped
);
PyObject_SetAttrString
(
swapped
,
"__ctype_be__"
,
swapped
);
/* We are creating the type for the OTHER endian */
/* We are creating the type for the OTHER endian */
sw_dict
->
format
=
alloc_format_string
(
">"
,
stgdict
->
format
+
1
);
sw_dict
->
format
=
_ctypes_
alloc_format_string
(
">"
,
stgdict
->
format
+
1
);
#endif
#endif
Py_DECREF
(
swapped
);
Py_DECREF
(
swapped
);
if
(
PyErr_Occurred
())
{
if
(
PyErr_Occurred
())
{
...
@@ -2035,7 +2035,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2035,7 +2035,7 @@ SimpleType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
* Convert a parameter into something that ConvParam can handle.
* Convert a parameter into something that ConvParam can handle.
*/
*/
static
PyObject
*
static
PyObject
*
SimpleType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
PyC
SimpleType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
char
*
fmt
;
char
*
fmt
;
...
@@ -2057,10 +2057,10 @@ SimpleType_from_param(PyObject *type, PyObject *value)
...
@@ -2057,10 +2057,10 @@ SimpleType_from_param(PyObject *type, PyObject *value)
fmt
=
PyString_AsString
(
dict
->
proto
);
fmt
=
PyString_AsString
(
dict
->
proto
);
assert
(
fmt
);
assert
(
fmt
);
fd
=
getentry
(
fmt
);
fd
=
_ctypes_get_fielddesc
(
fmt
);
assert
(
fd
);
assert
(
fd
);
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -2074,7 +2074,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
...
@@ -2074,7 +2074,7 @@ SimpleType_from_param(PyObject *type, PyObject *value)
as_parameter
=
PyObject_GetAttrString
(
value
,
"_as_parameter_"
);
as_parameter
=
PyObject_GetAttrString
(
value
,
"_as_parameter_"
);
if
(
as_parameter
)
{
if
(
as_parameter
)
{
value
=
SimpleType_from_param
(
type
,
as_parameter
);
value
=
PyC
SimpleType_from_param
(
type
,
as_parameter
);
Py_DECREF
(
as_parameter
);
Py_DECREF
(
as_parameter
);
return
value
;
return
value
;
}
}
...
@@ -2083,8 +2083,8 @@ SimpleType_from_param(PyObject *type, PyObject *value)
...
@@ -2083,8 +2083,8 @@ SimpleType_from_param(PyObject *type, PyObject *value)
return
NULL
;
return
NULL
;
}
}
static
PyMethodDef
SimpleType_methods
[]
=
{
static
PyMethodDef
PyC
SimpleType_methods
[]
=
{
{
"from_param"
,
SimpleType_from_param
,
METH_O
,
from_param_doc
},
{
"from_param"
,
PyC
SimpleType_from_param
,
METH_O
,
from_param_doc
},
{
"from_address"
,
CDataType_from_address
,
METH_O
,
from_address_doc
},
{
"from_address"
,
CDataType_from_address
,
METH_O
,
from_address_doc
},
{
"from_buffer"
,
CDataType_from_buffer
,
METH_VARARGS
,
from_buffer_doc
,
},
{
"from_buffer"
,
CDataType_from_buffer
,
METH_VARARGS
,
from_buffer_doc
,
},
{
"from_buffer_copy"
,
CDataType_from_buffer_copy
,
METH_VARARGS
,
from_buffer_copy_doc
,
},
{
"from_buffer_copy"
,
CDataType_from_buffer_copy
,
METH_VARARGS
,
from_buffer_copy_doc
,
},
...
@@ -2092,9 +2092,9 @@ static PyMethodDef SimpleType_methods[] = {
...
@@ -2092,9 +2092,9 @@ static PyMethodDef SimpleType_methods[] = {
{
NULL
,
NULL
},
{
NULL
,
NULL
},
};
};
PyTypeObject
SimpleType_Type
=
{
PyTypeObject
PyC
SimpleType_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.SimpleType"
,
/* tp_name */
"_ctypes.
PyC
SimpleType"
,
/* tp_name */
0
,
/* tp_basicsize */
0
,
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_dealloc */
...
@@ -2113,14 +2113,14 @@ PyTypeObject SimpleType_Type = {
...
@@ -2113,14 +2113,14 @@ PyTypeObject SimpleType_Type = {
0
,
/* tp_setattro */
0
,
/* tp_setattro */
0
,
/* tp_as_buffer */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"metatype for the SimpleType Objects"
,
/* tp_doc */
"metatype for the
PyC
SimpleType Objects"
,
/* tp_doc */
0
,
/* tp_traverse */
0
,
/* tp_traverse */
0
,
/* tp_clear */
0
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
SimpleType_methods
,
/* tp_methods */
PyC
SimpleType_methods
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
...
@@ -2130,13 +2130,13 @@ PyTypeObject SimpleType_Type = {
...
@@ -2130,13 +2130,13 @@ PyTypeObject SimpleType_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
SimpleType_new
,
/* tp_new */
PyC
SimpleType_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
/******************************************************************/
/******************************************************************/
/*
/*
CFuncPtrType_Type
Py
CFuncPtrType_Type
*/
*/
static
PyObject
*
static
PyObject
*
...
@@ -2192,7 +2192,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
...
@@ -2192,7 +2192,7 @@ make_funcptrtype_dict(StgDictObject *stgdict)
PyObject
*
ob
;
PyObject
*
ob
;
PyObject
*
converters
=
NULL
;
PyObject
*
converters
=
NULL
;
stgdict
->
align
=
getentry
(
"P"
)
->
pffi_type
->
alignment
;
stgdict
->
align
=
_ctypes_get_fielddesc
(
"P"
)
->
pffi_type
->
alignment
;
stgdict
->
length
=
1
;
stgdict
->
length
=
1
;
stgdict
->
size
=
sizeof
(
void
*
);
stgdict
->
size
=
sizeof
(
void
*
);
stgdict
->
setfunc
=
NULL
;
stgdict
->
setfunc
=
NULL
;
...
@@ -2252,11 +2252,11 @@ make_funcptrtype_dict(StgDictObject *stgdict)
...
@@ -2252,11 +2252,11 @@ make_funcptrtype_dict(StgDictObject *stgdict)
}
}
static
PyCArgObject
*
static
PyCArgObject
*
CFuncPtrType_paramfunc
(
CDataObject
*
self
)
Py
CFuncPtrType_paramfunc
(
CDataObject
*
self
)
{
{
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -2269,24 +2269,24 @@ CFuncPtrType_paramfunc(CDataObject *self)
...
@@ -2269,24 +2269,24 @@ CFuncPtrType_paramfunc(CDataObject *self)
}
}
static
PyObject
*
static
PyObject
*
CFuncPtrType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Py
CFuncPtrType_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
PyTypeObject
*
result
;
PyTypeObject
*
result
;
StgDictObject
*
stgdict
;
StgDictObject
*
stgdict
;
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
stgdict
=
(
StgDictObject
*
)
PyObject_CallObject
(
(
PyObject
*
)
&
StgDict_Type
,
NULL
);
(
PyObject
*
)
&
PyC
StgDict_Type
,
NULL
);
if
(
!
stgdict
)
if
(
!
stgdict
)
return
NULL
;
return
NULL
;
stgdict
->
paramfunc
=
CFuncPtrType_paramfunc
;
stgdict
->
paramfunc
=
Py
CFuncPtrType_paramfunc
;
/* We do NOT expose the function signature in the format string. It
/* We do NOT expose the function signature in the format string. It
is impossible, generally, because the only requirement for the
is impossible, generally, because the only requirement for the
argtypes items is that they have a .from_param method - we do not
argtypes items is that they have a .from_param method - we do not
know the types of the arguments (although, in practice, most
know the types of the arguments (although, in practice, most
argtypes would be a ctypes type).
argtypes would be a ctypes type).
*/
*/
stgdict
->
format
=
alloc_format_string
(
NULL
,
"X{}"
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
NULL
,
"X{}"
);
stgdict
->
flags
|=
TYPEFLAG_ISPOINTER
;
stgdict
->
flags
|=
TYPEFLAG_ISPOINTER
;
/* create the new instance (which is a class,
/* create the new instance (which is a class,
...
@@ -2314,9 +2314,9 @@ CFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2314,9 +2314,9 @@ CFuncPtrType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
(
PyObject
*
)
result
;
return
(
PyObject
*
)
result
;
}
}
PyTypeObject
CFuncPtrType_Type
=
{
PyTypeObject
Py
CFuncPtrType_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.CFuncPtrType"
,
/* tp_name */
"_ctypes.
Py
CFuncPtrType"
,
/* tp_name */
0
,
/* tp_basicsize */
0
,
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
0
,
/* tp_dealloc */
0
,
/* tp_dealloc */
...
@@ -2352,7 +2352,7 @@ PyTypeObject CFuncPtrType_Type = {
...
@@ -2352,7 +2352,7 @@ PyTypeObject CFuncPtrType_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
CFuncPtrType_new
,
/* tp_new */
Py
CFuncPtrType_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
...
@@ -2362,7 +2362,7 @@ PyTypeObject CFuncPtrType_Type = {
...
@@ -2362,7 +2362,7 @@ PyTypeObject CFuncPtrType_Type = {
*/
*/
static
CDataObject
*
static
CDataObject
*
CData_GetContainer
(
CDataObject
*
self
)
Py
CData_GetContainer
(
CDataObject
*
self
)
{
{
while
(
self
->
b_base
)
while
(
self
->
b_base
)
self
=
self
->
b_base
;
self
=
self
->
b_base
;
...
@@ -2380,7 +2380,7 @@ CData_GetContainer(CDataObject *self)
...
@@ -2380,7 +2380,7 @@ CData_GetContainer(CDataObject *self)
static
PyObject
*
static
PyObject
*
GetKeepedObjects
(
CDataObject
*
target
)
GetKeepedObjects
(
CDataObject
*
target
)
{
{
return
CData_GetContainer
(
target
)
->
b_objects
;
return
Py
CData_GetContainer
(
target
)
->
b_objects
;
}
}
static
PyObject
*
static
PyObject
*
...
@@ -2444,7 +2444,7 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
...
@@ -2444,7 +2444,7 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
Py_DECREF
(
Py_None
);
Py_DECREF
(
Py_None
);
return
0
;
return
0
;
}
}
ob
=
CData_GetContainer
(
target
);
ob
=
Py
CData_GetContainer
(
target
);
if
(
ob
->
b_objects
==
NULL
||
!
PyDict_CheckExact
(
ob
->
b_objects
))
{
if
(
ob
->
b_objects
==
NULL
||
!
PyDict_CheckExact
(
ob
->
b_objects
))
{
Py_XDECREF
(
ob
->
b_objects
);
Py_XDECREF
(
ob
->
b_objects
);
ob
->
b_objects
=
keep
;
/* refcount consumed */
ob
->
b_objects
=
keep
;
/* refcount consumed */
...
@@ -2463,10 +2463,10 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
...
@@ -2463,10 +2463,10 @@ KeepRef(CDataObject *target, Py_ssize_t index, PyObject *keep)
/******************************************************************/
/******************************************************************/
/*
/*
CData_Type
Py
CData_Type
*/
*/
static
int
static
int
CData_traverse
(
CDataObject
*
self
,
visitproc
visit
,
void
*
arg
)
Py
CData_traverse
(
CDataObject
*
self
,
visitproc
visit
,
void
*
arg
)
{
{
Py_VISIT
(
self
->
b_objects
);
Py_VISIT
(
self
->
b_objects
);
Py_VISIT
((
PyObject
*
)
self
->
b_base
);
Py_VISIT
((
PyObject
*
)
self
->
b_base
);
...
@@ -2474,7 +2474,7 @@ CData_traverse(CDataObject *self, visitproc visit, void *arg)
...
@@ -2474,7 +2474,7 @@ CData_traverse(CDataObject *self, visitproc visit, void *arg)
}
}
static
int
static
int
CData_clear
(
CDataObject
*
self
)
Py
CData_clear
(
CDataObject
*
self
)
{
{
StgDictObject
*
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
StgDictObject
*
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
dict
);
/* Cannot be NULL for CDataObject instances */
assert
(
dict
);
/* Cannot be NULL for CDataObject instances */
...
@@ -2488,13 +2488,13 @@ CData_clear(CDataObject *self)
...
@@ -2488,13 +2488,13 @@ CData_clear(CDataObject *self)
}
}
static
void
static
void
CData_dealloc
(
PyObject
*
self
)
Py
CData_dealloc
(
PyObject
*
self
)
{
{
CData_clear
((
CDataObject
*
)
self
);
Py
CData_clear
((
CDataObject
*
)
self
);
Py_TYPE
(
self
)
->
tp_free
(
self
);
Py_TYPE
(
self
)
->
tp_free
(
self
);
}
}
static
PyMemberDef
CData_members
[]
=
{
static
PyMemberDef
Py
CData_members
[]
=
{
{
"_b_base_"
,
T_OBJECT
,
{
"_b_base_"
,
T_OBJECT
,
offsetof
(
CDataObject
,
b_base
),
READONLY
,
offsetof
(
CDataObject
,
b_base
),
READONLY
,
"the base object"
},
"the base object"
},
...
@@ -2508,7 +2508,7 @@ static PyMemberDef CData_members[] = {
...
@@ -2508,7 +2508,7 @@ static PyMemberDef CData_members[] = {
};
};
#if (PY_VERSION_HEX >= 0x02060000)
#if (PY_VERSION_HEX >= 0x02060000)
static
int
CData_NewGetBuffer
(
PyObject
*
_self
,
Py_buffer
*
view
,
int
flags
)
static
int
Py
CData_NewGetBuffer
(
PyObject
*
_self
,
Py_buffer
*
view
,
int
flags
)
{
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
StgDictObject
*
dict
=
PyObject_stgdict
(
_self
);
StgDictObject
*
dict
=
PyObject_stgdict
(
_self
);
...
@@ -2536,14 +2536,14 @@ static int CData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
...
@@ -2536,14 +2536,14 @@ static int CData_NewGetBuffer(PyObject *_self, Py_buffer *view, int flags)
}
}
#endif
#endif
static
Py_ssize_t
CData_GetSegcount
(
PyObject
*
_self
,
Py_ssize_t
*
lenp
)
static
Py_ssize_t
Py
CData_GetSegcount
(
PyObject
*
_self
,
Py_ssize_t
*
lenp
)
{
{
if
(
lenp
)
if
(
lenp
)
*
lenp
=
1
;
*
lenp
=
1
;
return
1
;
return
1
;
}
}
static
Py_ssize_t
CData_GetBuffer
(
PyObject
*
_self
,
Py_ssize_t
seg
,
void
**
pptr
)
static
Py_ssize_t
Py
CData_GetBuffer
(
PyObject
*
_self
,
Py_ssize_t
seg
,
void
**
pptr
)
{
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
if
(
seg
!=
0
)
{
if
(
seg
!=
0
)
{
...
@@ -2554,13 +2554,13 @@ static Py_ssize_t CData_GetBuffer(PyObject *_self, Py_ssize_t seg, void **pptr)
...
@@ -2554,13 +2554,13 @@ static Py_ssize_t CData_GetBuffer(PyObject *_self, Py_ssize_t seg, void **pptr)
return
self
->
b_size
;
return
self
->
b_size
;
}
}
static
PyBufferProcs
CData_as_buffer
=
{
static
PyBufferProcs
Py
CData_as_buffer
=
{
(
readbufferproc
)
CData_GetBuffer
,
(
readbufferproc
)
Py
CData_GetBuffer
,
(
writebufferproc
)
CData_GetBuffer
,
(
writebufferproc
)
Py
CData_GetBuffer
,
(
segcountproc
)
CData_GetSegcount
,
(
segcountproc
)
Py
CData_GetSegcount
,
(
charbufferproc
)
NULL
,
(
charbufferproc
)
NULL
,
#if (PY_VERSION_HEX >= 0x02060000)
#if (PY_VERSION_HEX >= 0x02060000)
(
getbufferproc
)
CData_NewGetBuffer
,
(
getbufferproc
)
Py
CData_NewGetBuffer
,
(
releasebufferproc
)
NULL
,
(
releasebufferproc
)
NULL
,
#endif
#endif
};
};
...
@@ -2569,14 +2569,14 @@ static PyBufferProcs CData_as_buffer = {
...
@@ -2569,14 +2569,14 @@ static PyBufferProcs CData_as_buffer = {
* CData objects are mutable, so they cannot be hashable!
* CData objects are mutable, so they cannot be hashable!
*/
*/
static
long
static
long
CData_nohash
(
PyObject
*
self
)
Py
CData_nohash
(
PyObject
*
self
)
{
{
PyErr_SetString
(
PyExc_TypeError
,
"unhashable type"
);
PyErr_SetString
(
PyExc_TypeError
,
"unhashable type"
);
return
-
1
;
return
-
1
;
}
}
static
PyObject
*
static
PyObject
*
CData_reduce
(
PyObject
*
_self
,
PyObject
*
args
)
Py
CData_reduce
(
PyObject
*
_self
,
PyObject
*
args
)
{
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
...
@@ -2593,7 +2593,7 @@ CData_reduce(PyObject *_self, PyObject *args)
...
@@ -2593,7 +2593,7 @@ CData_reduce(PyObject *_self, PyObject *args)
}
}
static
PyObject
*
static
PyObject
*
CData_setstate
(
PyObject
*
_self
,
PyObject
*
args
)
Py
CData_setstate
(
PyObject
*
_self
,
PyObject
*
args
)
{
{
void
*
data
;
void
*
data
;
Py_ssize_t
len
;
Py_ssize_t
len
;
...
@@ -2618,25 +2618,25 @@ CData_setstate(PyObject *_self, PyObject *args)
...
@@ -2618,25 +2618,25 @@ CData_setstate(PyObject *_self, PyObject *args)
* default __ctypes_from_outparam__ method returns self.
* default __ctypes_from_outparam__ method returns self.
*/
*/
static
PyObject
*
static
PyObject
*
CData_from_outparam
(
PyObject
*
self
,
PyObject
*
args
)
Py
CData_from_outparam
(
PyObject
*
self
,
PyObject
*
args
)
{
{
Py_INCREF
(
self
);
Py_INCREF
(
self
);
return
self
;
return
self
;
}
}
static
PyMethodDef
CData_methods
[]
=
{
static
PyMethodDef
Py
CData_methods
[]
=
{
{
"__ctypes_from_outparam__"
,
CData_from_outparam
,
METH_NOARGS
,
},
{
"__ctypes_from_outparam__"
,
Py
CData_from_outparam
,
METH_NOARGS
,
},
{
"__reduce__"
,
CData_reduce
,
METH_NOARGS
,
},
{
"__reduce__"
,
Py
CData_reduce
,
METH_NOARGS
,
},
{
"__setstate__"
,
CData_setstate
,
METH_VARARGS
,
},
{
"__setstate__"
,
Py
CData_setstate
,
METH_VARARGS
,
},
{
NULL
,
NULL
},
{
NULL
,
NULL
},
};
};
PyTypeObject
CData_Type
=
{
PyTypeObject
Py
CData_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes._CData"
,
"_ctypes._CData"
,
sizeof
(
CDataObject
),
/* tp_basicsize */
sizeof
(
CDataObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
CData_dealloc
,
/* tp_dealloc */
Py
CData_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
...
@@ -2645,22 +2645,22 @@ PyTypeObject CData_Type = {
...
@@ -2645,22 +2645,22 @@ PyTypeObject CData_Type = {
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_as_mapping */
CData_nohash
,
/* tp_hash */
Py
CData_nohash
,
/* tp_hash */
0
,
/* tp_call */
0
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"XXX to be provided"
,
/* tp_doc */
"XXX to be provided"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
CData_methods
,
/* tp_methods */
Py
CData_methods
,
/* tp_methods */
CData_members
,
/* tp_members */
Py
CData_members
,
/* tp_members */
0
,
/* tp_getset */
0
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_dict */
...
@@ -2673,7 +2673,7 @@ PyTypeObject CData_Type = {
...
@@ -2673,7 +2673,7 @@ PyTypeObject CData_Type = {
0
,
/* tp_free */
0
,
/* tp_free */
};
};
static
int
CData_MallocBuffer
(
CDataObject
*
obj
,
StgDictObject
*
dict
)
static
int
Py
CData_MallocBuffer
(
CDataObject
*
obj
,
StgDictObject
*
dict
)
{
{
if
((
size_t
)
dict
->
size
<=
sizeof
(
obj
->
b_value
))
{
if
((
size_t
)
dict
->
size
<=
sizeof
(
obj
->
b_value
))
{
/* No need to call malloc, can use the default buffer */
/* No need to call malloc, can use the default buffer */
...
@@ -2702,7 +2702,7 @@ static int CData_MallocBuffer(CDataObject *obj, StgDictObject *dict)
...
@@ -2702,7 +2702,7 @@ static int CData_MallocBuffer(CDataObject *obj, StgDictObject *dict)
}
}
PyObject
*
PyObject
*
CData_FromBaseObj
(
PyObject
*
type
,
PyObject
*
base
,
Py_ssize_t
index
,
char
*
adr
)
Py
CData_FromBaseObj
(
PyObject
*
type
,
PyObject
*
base
,
Py_ssize_t
index
,
char
*
adr
)
{
{
CDataObject
*
cmem
;
CDataObject
*
cmem
;
StgDictObject
*
dict
;
StgDictObject
*
dict
;
...
@@ -2730,7 +2730,7 @@ CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr)
...
@@ -2730,7 +2730,7 @@ CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr)
cmem
->
b_base
=
(
CDataObject
*
)
base
;
cmem
->
b_base
=
(
CDataObject
*
)
base
;
cmem
->
b_index
=
index
;
cmem
->
b_index
=
index
;
}
else
{
/* copy contents of adr */
}
else
{
/* copy contents of adr */
if
(
-
1
==
CData_MallocBuffer
(
cmem
,
dict
))
{
if
(
-
1
==
Py
CData_MallocBuffer
(
cmem
,
dict
))
{
return
NULL
;
return
NULL
;
Py_DECREF
(
cmem
);
Py_DECREF
(
cmem
);
}
}
...
@@ -2744,7 +2744,7 @@ CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr)
...
@@ -2744,7 +2744,7 @@ CData_FromBaseObj(PyObject *type, PyObject *base, Py_ssize_t index, char *adr)
Box a memory block into a CData instance.
Box a memory block into a CData instance.
*/
*/
PyObject
*
PyObject
*
CData_AtAddress
(
PyObject
*
type
,
void
*
buf
)
Py
CData_AtAddress
(
PyObject
*
type
,
void
*
buf
)
{
{
CDataObject
*
pd
;
CDataObject
*
pd
;
StgDictObject
*
dict
;
StgDictObject
*
dict
;
...
@@ -2773,17 +2773,17 @@ CData_AtAddress(PyObject *type, void *buf)
...
@@ -2773,17 +2773,17 @@ CData_AtAddress(PyObject *type, void *buf)
classes. FALSE otherwise FALSE also for subclasses of c_int and
classes. FALSE otherwise FALSE also for subclasses of c_int and
such.
such.
*/
*/
int
IsSimpleSubTyp
e
(
PyObject
*
obj
)
int
_ctypes_simple_instanc
e
(
PyObject
*
obj
)
{
{
PyTypeObject
*
type
=
(
PyTypeObject
*
)
obj
;
PyTypeObject
*
type
=
(
PyTypeObject
*
)
obj
;
if
(
SimpleTypeObject_Check
(
type
))
if
(
PyC
SimpleTypeObject_Check
(
type
))
return
type
->
tp_base
!=
&
Simple_Type
;
return
type
->
tp_base
!=
&
Simple_Type
;
return
0
;
return
0
;
}
}
PyObject
*
PyObject
*
CData_get
(
PyObject
*
type
,
GETFUNC
getfunc
,
PyObject
*
src
,
Py
CData_get
(
PyObject
*
type
,
GETFUNC
getfunc
,
PyObject
*
src
,
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
adr
)
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
adr
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
...
@@ -2791,16 +2791,16 @@ CData_get(PyObject *type, GETFUNC getfunc, PyObject *src,
...
@@ -2791,16 +2791,16 @@ CData_get(PyObject *type, GETFUNC getfunc, PyObject *src,
return
getfunc
(
adr
,
size
);
return
getfunc
(
adr
,
size
);
assert
(
type
);
assert
(
type
);
dict
=
PyType_stgdict
(
type
);
dict
=
PyType_stgdict
(
type
);
if
(
dict
&&
dict
->
getfunc
&&
!
IsSimpleSubTyp
e
(
type
))
if
(
dict
&&
dict
->
getfunc
&&
!
_ctypes_simple_instanc
e
(
type
))
return
dict
->
getfunc
(
adr
,
size
);
return
dict
->
getfunc
(
adr
,
size
);
return
CData_FromBaseObj
(
type
,
src
,
index
,
adr
);
return
Py
CData_FromBaseObj
(
type
,
src
,
index
,
adr
);
}
}
/*
/*
Helper function for CData_set below.
Helper function for
Py
CData_set below.
*/
*/
static
PyObject
*
static
PyObject
*
_CData_set
(
CDataObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
_
Py
CData_set
(
CDataObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
Py_ssize_t
size
,
char
*
ptr
)
Py_ssize_t
size
,
char
*
ptr
)
{
{
CDataObject
*
src
;
CDataObject
*
src
;
...
@@ -2822,15 +2822,15 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2822,15 +2822,15 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
PyObject
*
result
;
PyObject
*
result
;
ob
=
PyObject_CallObject
(
type
,
value
);
ob
=
PyObject_CallObject
(
type
,
value
);
if
(
ob
==
NULL
)
{
if
(
ob
==
NULL
)
{
Extend_Error_Info
(
PyExc_RuntimeError
,
"(%s) "
,
_ctypes_extend_error
(
PyExc_RuntimeError
,
"(%s) "
,
((
PyTypeObject
*
)
type
)
->
tp_name
);
((
PyTypeObject
*
)
type
)
->
tp_name
);
return
NULL
;
return
NULL
;
}
}
result
=
_CData_set
(
dst
,
type
,
setfunc
,
ob
,
result
=
_
Py
CData_set
(
dst
,
type
,
setfunc
,
ob
,
size
,
ptr
);
size
,
ptr
);
Py_DECREF
(
ob
);
Py_DECREF
(
ob
);
return
result
;
return
result
;
}
else
if
(
value
==
Py_None
&&
PointerTypeObject_Check
(
type
))
{
}
else
if
(
value
==
Py_None
&&
P
yCP
ointerTypeObject_Check
(
type
))
{
*
(
void
**
)
ptr
=
NULL
;
*
(
void
**
)
ptr
=
NULL
;
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
...
@@ -2849,7 +2849,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2849,7 +2849,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
src
->
b_ptr
,
src
->
b_ptr
,
size
);
size
);
if
(
PointerTypeObject_Check
(
type
))
if
(
P
yCP
ointerTypeObject_Check
(
type
))
/* XXX */
;
/* XXX */
;
value
=
GetKeepedObjects
(
src
);
value
=
GetKeepedObjects
(
src
);
...
@@ -2857,7 +2857,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2857,7 +2857,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
return
value
;
return
value
;
}
}
if
(
PointerTypeObject_Check
(
type
)
if
(
P
yCP
ointerTypeObject_Check
(
type
)
&&
ArrayObject_Check
(
value
))
{
&&
ArrayObject_Check
(
value
))
{
StgDictObject
*
p1
,
*
p2
;
StgDictObject
*
p1
,
*
p2
;
PyObject
*
keep
;
PyObject
*
keep
;
...
@@ -2898,7 +2898,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2898,7 +2898,7 @@ _CData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
* to the value 'value'.
* to the value 'value'.
*/
*/
int
int
CData_set
(
PyObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
Py
CData_set
(
PyObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
)
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
)
{
{
CDataObject
*
mem
=
(
CDataObject
*
)
dst
;
CDataObject
*
mem
=
(
CDataObject
*
)
dst
;
...
@@ -2910,7 +2910,7 @@ CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2910,7 +2910,7 @@ CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
return
-
1
;
return
-
1
;
}
}
result
=
_CData_set
(
mem
,
type
,
setfunc
,
value
,
result
=
_
Py
CData_set
(
mem
,
type
,
setfunc
,
value
,
size
,
ptr
);
size
,
ptr
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
-
1
;
return
-
1
;
...
@@ -2924,7 +2924,7 @@ CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2924,7 +2924,7 @@ CData_set(PyObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
/******************************************************************/
/******************************************************************/
static
PyObject
*
static
PyObject
*
GenericCData_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Generic
Py
CData_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
CDataObject
*
obj
;
CDataObject
*
obj
;
StgDictObject
*
dict
;
StgDictObject
*
dict
;
...
@@ -2946,7 +2946,7 @@ GenericCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2946,7 +2946,7 @@ GenericCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
obj
->
b_objects
=
NULL
;
obj
->
b_objects
=
NULL
;
obj
->
b_length
=
dict
->
length
;
obj
->
b_length
=
dict
->
length
;
if
(
-
1
==
CData_MallocBuffer
(
obj
,
dict
))
{
if
(
-
1
==
Py
CData_MallocBuffer
(
obj
,
dict
))
{
Py_DECREF
(
obj
);
Py_DECREF
(
obj
);
return
NULL
;
return
NULL
;
}
}
...
@@ -2954,11 +2954,11 @@ GenericCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2954,11 +2954,11 @@ GenericCData_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
/*****************************************************************/
/*****************************************************************/
/*
/*
CFuncPtr_Type
Py
CFuncPtr_Type
*/
*/
static
int
static
int
CFuncPtr_set_errcheck
(
CFuncPtrObject
*
self
,
PyObject
*
ob
)
PyCFuncPtr_set_errcheck
(
Py
CFuncPtrObject
*
self
,
PyObject
*
ob
)
{
{
if
(
ob
&&
!
PyCallable_Check
(
ob
))
{
if
(
ob
&&
!
PyCallable_Check
(
ob
))
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
...
@@ -2972,7 +2972,7 @@ CFuncPtr_set_errcheck(CFuncPtrObject *self, PyObject *ob)
...
@@ -2972,7 +2972,7 @@ CFuncPtr_set_errcheck(CFuncPtrObject *self, PyObject *ob)
}
}
static
PyObject
*
static
PyObject
*
CFuncPtr_get_errcheck
(
CFuncPtrObject
*
self
)
PyCFuncPtr_get_errcheck
(
Py
CFuncPtrObject
*
self
)
{
{
if
(
self
->
errcheck
)
{
if
(
self
->
errcheck
)
{
Py_INCREF
(
self
->
errcheck
);
Py_INCREF
(
self
->
errcheck
);
...
@@ -2983,7 +2983,7 @@ CFuncPtr_get_errcheck(CFuncPtrObject *self)
...
@@ -2983,7 +2983,7 @@ CFuncPtr_get_errcheck(CFuncPtrObject *self)
}
}
static
int
static
int
CFuncPtr_set_restype
(
CFuncPtrObject
*
self
,
PyObject
*
ob
)
PyCFuncPtr_set_restype
(
Py
CFuncPtrObject
*
self
,
PyObject
*
ob
)
{
{
if
(
ob
==
NULL
)
{
if
(
ob
==
NULL
)
{
Py_XDECREF
(
self
->
restype
);
Py_XDECREF
(
self
->
restype
);
...
@@ -3008,7 +3008,7 @@ CFuncPtr_set_restype(CFuncPtrObject *self, PyObject *ob)
...
@@ -3008,7 +3008,7 @@ CFuncPtr_set_restype(CFuncPtrObject *self, PyObject *ob)
}
}
static
PyObject
*
static
PyObject
*
CFuncPtr_get_restype
(
CFuncPtrObject
*
self
)
PyCFuncPtr_get_restype
(
Py
CFuncPtrObject
*
self
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
if
(
self
->
restype
)
{
if
(
self
->
restype
)
{
...
@@ -3016,7 +3016,7 @@ CFuncPtr_get_restype(CFuncPtrObject *self)
...
@@ -3016,7 +3016,7 @@ CFuncPtr_get_restype(CFuncPtrObject *self)
return
self
->
restype
;
return
self
->
restype
;
}
}
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
dict
);
/* Cannot be NULL for CFuncPtrObject instances */
assert
(
dict
);
/* Cannot be NULL for
Py
CFuncPtrObject instances */
if
(
dict
->
restype
)
{
if
(
dict
->
restype
)
{
Py_INCREF
(
dict
->
restype
);
Py_INCREF
(
dict
->
restype
);
return
dict
->
restype
;
return
dict
->
restype
;
...
@@ -3027,7 +3027,7 @@ CFuncPtr_get_restype(CFuncPtrObject *self)
...
@@ -3027,7 +3027,7 @@ CFuncPtr_get_restype(CFuncPtrObject *self)
}
}
static
int
static
int
CFuncPtr_set_argtypes
(
CFuncPtrObject
*
self
,
PyObject
*
ob
)
PyCFuncPtr_set_argtypes
(
Py
CFuncPtrObject
*
self
,
PyObject
*
ob
)
{
{
PyObject
*
converters
;
PyObject
*
converters
;
...
@@ -3050,7 +3050,7 @@ CFuncPtr_set_argtypes(CFuncPtrObject *self, PyObject *ob)
...
@@ -3050,7 +3050,7 @@ CFuncPtr_set_argtypes(CFuncPtrObject *self, PyObject *ob)
}
}
static
PyObject
*
static
PyObject
*
CFuncPtr_get_argtypes
(
CFuncPtrObject
*
self
)
PyCFuncPtr_get_argtypes
(
Py
CFuncPtrObject
*
self
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
if
(
self
->
argtypes
)
{
if
(
self
->
argtypes
)
{
...
@@ -3058,7 +3058,7 @@ CFuncPtr_get_argtypes(CFuncPtrObject *self)
...
@@ -3058,7 +3058,7 @@ CFuncPtr_get_argtypes(CFuncPtrObject *self)
return
self
->
argtypes
;
return
self
->
argtypes
;
}
}
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
dict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
dict
);
/* Cannot be NULL for CFuncPtrObject instances */
assert
(
dict
);
/* Cannot be NULL for
Py
CFuncPtrObject instances */
if
(
dict
->
argtypes
)
{
if
(
dict
->
argtypes
)
{
Py_INCREF
(
dict
->
argtypes
);
Py_INCREF
(
dict
->
argtypes
);
return
dict
->
argtypes
;
return
dict
->
argtypes
;
...
@@ -3068,13 +3068,13 @@ CFuncPtr_get_argtypes(CFuncPtrObject *self)
...
@@ -3068,13 +3068,13 @@ CFuncPtr_get_argtypes(CFuncPtrObject *self)
}
}
}
}
static
PyGetSetDef
CFuncPtr_getsets
[]
=
{
static
PyGetSetDef
Py
CFuncPtr_getsets
[]
=
{
{
"errcheck"
,
(
getter
)
CFuncPtr_get_errcheck
,
(
setter
)
CFuncPtr_set_errcheck
,
{
"errcheck"
,
(
getter
)
PyCFuncPtr_get_errcheck
,
(
setter
)
Py
CFuncPtr_set_errcheck
,
"a function to check for errors"
,
NULL
},
"a function to check for errors"
,
NULL
},
{
"restype"
,
(
getter
)
CFuncPtr_get_restype
,
(
setter
)
CFuncPtr_set_restype
,
{
"restype"
,
(
getter
)
PyCFuncPtr_get_restype
,
(
setter
)
Py
CFuncPtr_set_restype
,
"specify the result type"
,
NULL
},
"specify the result type"
,
NULL
},
{
"argtypes"
,
(
getter
)
CFuncPtr_get_argtypes
,
{
"argtypes"
,
(
getter
)
Py
CFuncPtr_get_argtypes
,
(
setter
)
CFuncPtr_set_argtypes
,
(
setter
)
Py
CFuncPtr_set_argtypes
,
"specify the argument types"
,
NULL
},
"specify the argument types"
,
NULL
},
{
NULL
,
NULL
}
{
NULL
,
NULL
}
};
};
...
@@ -3129,10 +3129,10 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
...
@@ -3129,10 +3129,10 @@ _check_outarg_type(PyObject *arg, Py_ssize_t index)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
if
(
PointerTypeObject_Check
(
arg
))
if
(
P
yCP
ointerTypeObject_Check
(
arg
))
return
1
;
return
1
;
if
(
ArrayTypeObject_Check
(
arg
))
if
(
PyC
ArrayTypeObject_Check
(
arg
))
return
1
;
return
1
;
dict
=
PyType_stgdict
(
arg
);
dict
=
PyType_stgdict
(
arg
);
...
@@ -3162,7 +3162,7 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags)
...
@@ -3162,7 +3162,7 @@ _validate_paramflags(PyTypeObject *type, PyObject *paramflags)
PyObject
*
argtypes
;
PyObject
*
argtypes
;
dict
=
PyType_stgdict
((
PyObject
*
)
type
);
dict
=
PyType_stgdict
((
PyObject
*
)
type
);
assert
(
dict
);
/* Cannot be NULL. 'type' is a CFuncPtr type. */
assert
(
dict
);
/* Cannot be NULL. 'type' is a
Py
CFuncPtr type. */
argtypes
=
dict
->
argtypes
;
argtypes
=
dict
->
argtypes
;
if
(
paramflags
==
NULL
||
dict
->
argtypes
==
NULL
)
if
(
paramflags
==
NULL
||
dict
->
argtypes
==
NULL
)
...
@@ -3236,13 +3236,13 @@ _get_name(PyObject *obj, char **pname)
...
@@ -3236,13 +3236,13 @@ _get_name(PyObject *obj, char **pname)
static
PyObject
*
static
PyObject
*
CFuncPtr_FromDll
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Py
CFuncPtr_FromDll
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
char
*
name
;
char
*
name
;
int
(
*
address
)(
void
);
int
(
*
address
)(
void
);
PyObject
*
dll
;
PyObject
*
dll
;
PyObject
*
obj
;
PyObject
*
obj
;
CFuncPtrObject
*
self
;
Py
CFuncPtrObject
*
self
;
void
*
handle
;
void
*
handle
;
PyObject
*
paramflags
=
NULL
;
PyObject
*
paramflags
=
NULL
;
...
@@ -3298,7 +3298,7 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3298,7 +3298,7 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
_validate_paramflags
(
type
,
paramflags
))
if
(
!
_validate_paramflags
(
type
,
paramflags
))
return
NULL
;
return
NULL
;
self
=
(
CFuncPtrObject
*
)
Generic
CData_new
(
type
,
args
,
kwds
);
self
=
(
PyCFuncPtrObject
*
)
GenericPy
CData_new
(
type
,
args
,
kwds
);
if
(
!
self
)
if
(
!
self
)
return
NULL
;
return
NULL
;
...
@@ -3320,9 +3320,9 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3320,9 +3320,9 @@ CFuncPtr_FromDll(PyTypeObject *type, PyObject *args, PyObject *kwds)
#ifdef MS_WIN32
#ifdef MS_WIN32
static
PyObject
*
static
PyObject
*
CFuncPtr_FromVtblIndex
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Py
CFuncPtr_FromVtblIndex
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
CFuncPtrObject
*
self
;
Py
CFuncPtrObject
*
self
;
int
index
;
int
index
;
char
*
name
=
NULL
;
char
*
name
=
NULL
;
PyObject
*
paramflags
=
NULL
;
PyObject
*
paramflags
=
NULL
;
...
@@ -3337,7 +3337,7 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3337,7 +3337,7 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
if
(
!
_validate_paramflags
(
type
,
paramflags
))
if
(
!
_validate_paramflags
(
type
,
paramflags
))
return
NULL
;
return
NULL
;
self
=
(
CFuncPtrObject
*
)
Generic
CData_new
(
type
,
args
,
kwds
);
self
=
(
PyCFuncPtrObject
*
)
GenericPy
CData_new
(
type
,
args
,
kwds
);
self
->
index
=
index
+
0x1000
;
self
->
index
=
index
+
0x1000
;
Py_XINCREF
(
paramflags
);
Py_XINCREF
(
paramflags
);
self
->
paramflags
=
paramflags
;
self
->
paramflags
=
paramflags
;
...
@@ -3348,7 +3348,7 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3348,7 +3348,7 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
#endif
#endif
/*
/*
CFuncPtr_new accepts different argument lists in addition to the standard
Py
CFuncPtr_new accepts different argument lists in addition to the standard
_basespec_ keyword arg:
_basespec_ keyword arg:
one argument form
one argument form
...
@@ -3361,22 +3361,22 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3361,22 +3361,22 @@ CFuncPtr_FromVtblIndex(PyTypeObject *type, PyObject *args, PyObject *kwds)
"is|..." - vtable index, method name, creates callable calling COM vtbl
"is|..." - vtable index, method name, creates callable calling COM vtbl
*/
*/
static
PyObject
*
static
PyObject
*
CFuncPtr_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Py
CFuncPtr_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
CFuncPtrObject
*
self
;
Py
CFuncPtrObject
*
self
;
PyObject
*
callable
;
PyObject
*
callable
;
StgDictObject
*
dict
;
StgDictObject
*
dict
;
CThunkObject
*
thunk
;
CThunkObject
*
thunk
;
if
(
PyTuple_GET_SIZE
(
args
)
==
0
)
if
(
PyTuple_GET_SIZE
(
args
)
==
0
)
return
GenericCData_new
(
type
,
args
,
kwds
);
return
Generic
Py
CData_new
(
type
,
args
,
kwds
);
if
(
1
<=
PyTuple_GET_SIZE
(
args
)
&&
PyTuple_Check
(
PyTuple_GET_ITEM
(
args
,
0
)))
if
(
1
<=
PyTuple_GET_SIZE
(
args
)
&&
PyTuple_Check
(
PyTuple_GET_ITEM
(
args
,
0
)))
return
CFuncPtr_FromDll
(
type
,
args
,
kwds
);
return
Py
CFuncPtr_FromDll
(
type
,
args
,
kwds
);
#ifdef MS_WIN32
#ifdef MS_WIN32
if
(
2
<=
PyTuple_GET_SIZE
(
args
)
&&
PyInt_Check
(
PyTuple_GET_ITEM
(
args
,
0
)))
if
(
2
<=
PyTuple_GET_SIZE
(
args
)
&&
PyInt_Check
(
PyTuple_GET_ITEM
(
args
,
0
)))
return
CFuncPtr_FromVtblIndex
(
type
,
args
,
kwds
);
return
Py
CFuncPtr_FromVtblIndex
(
type
,
args
,
kwds
);
#endif
#endif
if
(
1
==
PyTuple_GET_SIZE
(
args
)
if
(
1
==
PyTuple_GET_SIZE
(
args
)
...
@@ -3386,7 +3386,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3386,7 +3386,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
void
*
ptr
=
PyLong_AsVoidPtr
(
PyTuple_GET_ITEM
(
args
,
0
));
void
*
ptr
=
PyLong_AsVoidPtr
(
PyTuple_GET_ITEM
(
args
,
0
));
if
(
ptr
==
NULL
&&
PyErr_Occurred
())
if
(
ptr
==
NULL
&&
PyErr_Occurred
())
return
NULL
;
return
NULL
;
ob
=
(
CDataObject
*
)
GenericCData_new
(
type
,
args
,
kwds
);
ob
=
(
CDataObject
*
)
Generic
Py
CData_new
(
type
,
args
,
kwds
);
if
(
ob
==
NULL
)
if
(
ob
==
NULL
)
return
NULL
;
return
NULL
;
*
(
void
**
)
ob
->
b_ptr
=
ptr
;
*
(
void
**
)
ob
->
b_ptr
=
ptr
;
...
@@ -3415,7 +3415,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3415,7 +3415,7 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
*/
*/
dict
=
PyType_stgdict
((
PyObject
*
)
type
);
dict
=
PyType_stgdict
((
PyObject
*
)
type
);
/* XXXX Fails if we do: 'CFuncPtr(lambda x: x)' */
/* XXXX Fails if we do: '
Py
CFuncPtr(lambda x: x)' */
if
(
!
dict
||
!
dict
->
argtypes
)
{
if
(
!
dict
||
!
dict
->
argtypes
)
{
PyErr_SetString
(
PyExc_TypeError
,
PyErr_SetString
(
PyExc_TypeError
,
"cannot construct instance of this class:"
"cannot construct instance of this class:"
...
@@ -3423,14 +3423,14 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3423,14 +3423,14 @@ CFuncPtr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
NULL
;
return
NULL
;
}
}
thunk
=
AllocFunctionC
allback
(
callable
,
thunk
=
_ctypes_alloc_c
allback
(
callable
,
dict
->
argtypes
,
dict
->
argtypes
,
dict
->
restype
,
dict
->
restype
,
dict
->
flags
);
dict
->
flags
);
if
(
!
thunk
)
if
(
!
thunk
)
return
NULL
;
return
NULL
;
self
=
(
CFuncPtrObject
*
)
Generic
CData_new
(
type
,
args
,
kwds
);
self
=
(
PyCFuncPtrObject
*
)
GenericPy
CData_new
(
type
,
args
,
kwds
);
if
(
self
==
NULL
)
{
if
(
self
==
NULL
)
{
Py_DECREF
(
thunk
);
Py_DECREF
(
thunk
);
return
NULL
;
return
NULL
;
...
@@ -3464,7 +3464,7 @@ _byref(PyObject *obj)
...
@@ -3464,7 +3464,7 @@ _byref(PyObject *obj)
return
NULL
;
return
NULL
;
}
}
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
{
if
(
parg
==
NULL
)
{
Py_DECREF
(
obj
);
Py_DECREF
(
obj
);
return
NULL
;
return
NULL
;
...
@@ -3526,7 +3526,7 @@ _get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject *
...
@@ -3526,7 +3526,7 @@ _get_arg(int *pindex, char *name, PyObject *defval, PyObject *inargs, PyObject *
function.
function.
*/
*/
static
PyObject
*
static
PyObject
*
_build_callargs
(
CFuncPtrObject
*
self
,
PyObject
*
argtypes
,
_build_callargs
(
Py
CFuncPtrObject
*
self
,
PyObject
*
argtypes
,
PyObject
*
inargs
,
PyObject
*
kwds
,
PyObject
*
inargs
,
PyObject
*
kwds
,
int
*
poutmask
,
int
*
pinoutmask
,
unsigned
int
*
pnumretvals
)
int
*
poutmask
,
int
*
pinoutmask
,
unsigned
int
*
pnumretvals
)
{
{
...
@@ -3638,7 +3638,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
...
@@ -3638,7 +3638,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
((
PyTypeObject
*
)
ob
)
->
tp_name
);
((
PyTypeObject
*
)
ob
)
->
tp_name
);
goto
error
;
goto
error
;
}
}
if
(
ArrayTypeObject_Check
(
ob
))
if
(
PyC
ArrayTypeObject_Check
(
ob
))
ob
=
PyObject_CallObject
(
ob
,
NULL
);
ob
=
PyObject_CallObject
(
ob
,
NULL
);
else
else
/* Create an instance of the pointed-to type */
/* Create an instance of the pointed-to type */
...
@@ -3758,7 +3758,7 @@ _build_result(PyObject *result, PyObject *callargs,
...
@@ -3758,7 +3758,7 @@ _build_result(PyObject *result, PyObject *callargs,
}
}
static
PyObject
*
static
PyObject
*
CFuncPtr_call
(
CFuncPtrObject
*
self
,
PyObject
*
inargs
,
PyObject
*
kwds
)
PyCFuncPtr_call
(
Py
CFuncPtrObject
*
self
,
PyObject
*
inargs
,
PyObject
*
kwds
)
{
{
PyObject
*
restype
;
PyObject
*
restype
;
PyObject
*
converters
;
PyObject
*
converters
;
...
@@ -3777,7 +3777,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
...
@@ -3777,7 +3777,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
int
outmask
;
int
outmask
;
unsigned
int
numretvals
;
unsigned
int
numretvals
;
assert
(
dict
);
/* Cannot be NULL for CFuncPtrObject instances */
assert
(
dict
);
/* Cannot be NULL for
Py
CFuncPtrObject instances */
restype
=
self
->
restype
?
self
->
restype
:
dict
->
restype
;
restype
=
self
->
restype
?
self
->
restype
:
dict
->
restype
;
converters
=
self
->
converters
?
self
->
converters
:
dict
->
converters
;
converters
=
self
->
converters
?
self
->
converters
:
dict
->
converters
;
checker
=
self
->
checker
?
self
->
checker
:
dict
->
checker
;
checker
=
self
->
checker
?
self
->
checker
:
dict
->
checker
;
...
@@ -3854,7 +3854,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
...
@@ -3854,7 +3854,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
}
}
}
}
result
=
_
CallP
roc
(
pProc
,
result
=
_
ctypes_callp
roc
(
pProc
,
callargs
,
callargs
,
#ifdef MS_WIN32
#ifdef MS_WIN32
piunk
,
piunk
,
...
@@ -3890,7 +3890,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
...
@@ -3890,7 +3890,7 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
}
}
static
int
static
int
CFuncPtr_traverse
(
CFuncPtrObject
*
self
,
visitproc
visit
,
void
*
arg
)
PyCFuncPtr_traverse
(
Py
CFuncPtrObject
*
self
,
visitproc
visit
,
void
*
arg
)
{
{
Py_VISIT
(
self
->
callable
);
Py_VISIT
(
self
->
callable
);
Py_VISIT
(
self
->
restype
);
Py_VISIT
(
self
->
restype
);
...
@@ -3900,11 +3900,11 @@ CFuncPtr_traverse(CFuncPtrObject *self, visitproc visit, void *arg)
...
@@ -3900,11 +3900,11 @@ CFuncPtr_traverse(CFuncPtrObject *self, visitproc visit, void *arg)
Py_VISIT
(
self
->
converters
);
Py_VISIT
(
self
->
converters
);
Py_VISIT
(
self
->
paramflags
);
Py_VISIT
(
self
->
paramflags
);
Py_VISIT
(
self
->
thunk
);
Py_VISIT
(
self
->
thunk
);
return
CData_traverse
((
CDataObject
*
)
self
,
visit
,
arg
);
return
Py
CData_traverse
((
CDataObject
*
)
self
,
visit
,
arg
);
}
}
static
int
static
int
CFuncPtr_clear
(
CFuncPtrObject
*
self
)
PyCFuncPtr_clear
(
Py
CFuncPtrObject
*
self
)
{
{
Py_CLEAR
(
self
->
callable
);
Py_CLEAR
(
self
->
callable
);
Py_CLEAR
(
self
->
restype
);
Py_CLEAR
(
self
->
restype
);
...
@@ -3914,18 +3914,18 @@ CFuncPtr_clear(CFuncPtrObject *self)
...
@@ -3914,18 +3914,18 @@ CFuncPtr_clear(CFuncPtrObject *self)
Py_CLEAR
(
self
->
converters
);
Py_CLEAR
(
self
->
converters
);
Py_CLEAR
(
self
->
paramflags
);
Py_CLEAR
(
self
->
paramflags
);
Py_CLEAR
(
self
->
thunk
);
Py_CLEAR
(
self
->
thunk
);
return
CData_clear
((
CDataObject
*
)
self
);
return
Py
CData_clear
((
CDataObject
*
)
self
);
}
}
static
void
static
void
CFuncPtr_dealloc
(
CFuncPtrObject
*
self
)
PyCFuncPtr_dealloc
(
Py
CFuncPtrObject
*
self
)
{
{
CFuncPtr_clear
(
self
);
Py
CFuncPtr_clear
(
self
);
Py_TYPE
(
self
)
->
tp_free
((
PyObject
*
)
self
);
Py_TYPE
(
self
)
->
tp_free
((
PyObject
*
)
self
);
}
}
static
PyObject
*
static
PyObject
*
CFuncPtr_repr
(
CFuncPtrObject
*
self
)
PyCFuncPtr_repr
(
Py
CFuncPtrObject
*
self
)
{
{
#ifdef MS_WIN32
#ifdef MS_WIN32
if
(
self
->
index
)
if
(
self
->
index
)
...
@@ -3940,7 +3940,7 @@ CFuncPtr_repr(CFuncPtrObject *self)
...
@@ -3940,7 +3940,7 @@ CFuncPtr_repr(CFuncPtrObject *self)
}
}
static
int
static
int
CFuncPtr_nonzero
(
CFuncPtrObject
*
self
)
PyCFuncPtr_nonzero
(
Py
CFuncPtrObject
*
self
)
{
{
return
((
*
(
void
**
)
self
->
b_ptr
!=
NULL
)
return
((
*
(
void
**
)
self
->
b_ptr
!=
NULL
)
#ifdef MS_WIN32
#ifdef MS_WIN32
...
@@ -3949,7 +3949,7 @@ CFuncPtr_nonzero(CFuncPtrObject *self)
...
@@ -3949,7 +3949,7 @@ CFuncPtr_nonzero(CFuncPtrObject *self)
);
);
}
}
static
PyNumberMethods
CFuncPtr_as_number
=
{
static
PyNumberMethods
Py
CFuncPtr_as_number
=
{
0
,
/* nb_add */
0
,
/* nb_add */
0
,
/* nb_subtract */
0
,
/* nb_subtract */
0
,
/* nb_multiply */
0
,
/* nb_multiply */
...
@@ -3960,40 +3960,40 @@ static PyNumberMethods CFuncPtr_as_number = {
...
@@ -3960,40 +3960,40 @@ static PyNumberMethods CFuncPtr_as_number = {
0
,
/* nb_negative */
0
,
/* nb_negative */
0
,
/* nb_positive */
0
,
/* nb_positive */
0
,
/* nb_absolute */
0
,
/* nb_absolute */
(
inquiry
)
CFuncPtr_nonzero
,
/* nb_nonzero */
(
inquiry
)
Py
CFuncPtr_nonzero
,
/* nb_nonzero */
};
};
PyTypeObject
CFuncPtr_Type
=
{
PyTypeObject
Py
CFuncPtr_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.CFuncPtr"
,
"_ctypes.
Py
CFuncPtr"
,
sizeof
(
CFuncPtrObject
),
/* tp_basicsize */
sizeof
(
Py
CFuncPtrObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
(
destructor
)
CFuncPtr_dealloc
,
/* tp_dealloc */
(
destructor
)
Py
CFuncPtr_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
CFuncPtr_repr
,
/* tp_repr */
(
reprfunc
)
Py
CFuncPtr_repr
,
/* tp_repr */
&
CFuncPtr_as_number
,
/* tp_as_number */
&
Py
CFuncPtr_as_number
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_as_mapping */
0
,
/* tp_hash */
0
,
/* tp_hash */
(
ternaryfunc
)
CFuncPtr_call
,
/* tp_call */
(
ternaryfunc
)
Py
CFuncPtr_call
,
/* tp_call */
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"Function Pointer"
,
/* tp_doc */
"Function Pointer"
,
/* tp_doc */
(
traverseproc
)
CFuncPtr_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CFuncPtr_traverse
,
/* tp_traverse */
(
inquiry
)
CFuncPtr_clear
,
/* tp_clear */
(
inquiry
)
Py
CFuncPtr_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
CFuncPtr_getsets
,
/* tp_getset */
Py
CFuncPtr_getsets
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_dict */
0
,
/* tp_descr_get */
0
,
/* tp_descr_get */
...
@@ -4001,7 +4001,7 @@ PyTypeObject CFuncPtr_Type = {
...
@@ -4001,7 +4001,7 @@ PyTypeObject CFuncPtr_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
CFuncPtr_new
,
/* tp_new */
Py
CFuncPtr_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
...
@@ -4125,11 +4125,11 @@ static PyTypeObject Struct_Type = {
...
@@ -4125,11 +4125,11 @@ static PyTypeObject Struct_Type = {
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"Structure base class"
,
/* tp_doc */
"Structure base class"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
...
@@ -4144,7 +4144,7 @@ static PyTypeObject Struct_Type = {
...
@@ -4144,7 +4144,7 @@ static PyTypeObject Struct_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
Struct_init
,
/* tp_init */
Struct_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
GenericCData_new
,
/* tp_new */
Generic
Py
CData_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
...
@@ -4167,11 +4167,11 @@ static PyTypeObject Union_Type = {
...
@@ -4167,11 +4167,11 @@ static PyTypeObject Union_Type = {
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"Union base class"
,
/* tp_doc */
"Union base class"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
...
@@ -4186,14 +4186,14 @@ static PyTypeObject Union_Type = {
...
@@ -4186,14 +4186,14 @@ static PyTypeObject Union_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
Struct_init
,
/* tp_init */
Struct_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
GenericCData_new
,
/* tp_new */
Generic
Py
CData_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
/******************************************************************/
/******************************************************************/
/*
/*
Array_Type
PyC
Array_Type
*/
*/
static
int
static
int
Array_init
(
CDataObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
Array_init
(
CDataObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
...
@@ -4238,7 +4238,7 @@ Array_item(PyObject *_self, Py_ssize_t index)
...
@@ -4238,7 +4238,7 @@ Array_item(PyObject *_self, Py_ssize_t index)
size
=
stgdict
->
size
/
stgdict
->
length
;
size
=
stgdict
->
size
/
stgdict
->
length
;
offset
=
index
*
size
;
offset
=
index
*
size
;
return
CData_get
(
stgdict
->
proto
,
stgdict
->
getfunc
,
(
PyObject
*
)
self
,
return
Py
CData_get
(
stgdict
->
proto
,
stgdict
->
getfunc
,
(
PyObject
*
)
self
,
index
,
size
,
self
->
b_ptr
+
offset
);
index
,
size
,
self
->
b_ptr
+
offset
);
}
}
...
@@ -4267,11 +4267,11 @@ Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
...
@@ -4267,11 +4267,11 @@ Array_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
itemdict
=
PyType_stgdict
(
proto
);
itemdict
=
PyType_stgdict
(
proto
);
assert
(
itemdict
);
/* proto is the item type of the array, a ctypes
assert
(
itemdict
);
/* proto is the item type of the array, a ctypes
type, so this cannot be NULL */
type, so this cannot be NULL */
if
(
itemdict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
char
*
ptr
=
(
char
*
)
self
->
b_ptr
;
char
*
ptr
=
(
char
*
)
self
->
b_ptr
;
return
PyString_FromStringAndSize
(
ptr
+
ilow
,
len
);
return
PyString_FromStringAndSize
(
ptr
+
ilow
,
len
);
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
}
else
if
(
itemdict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
}
else
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
wchar_t
*
ptr
=
(
wchar_t
*
)
self
->
b_ptr
;
wchar_t
*
ptr
=
(
wchar_t
*
)
self
->
b_ptr
;
return
PyUnicode_FromWideChar
(
ptr
+
ilow
,
len
);
return
PyUnicode_FromWideChar
(
ptr
+
ilow
,
len
);
#endif
#endif
...
@@ -4321,7 +4321,7 @@ Array_subscript(PyObject *_self, PyObject *item)
...
@@ -4321,7 +4321,7 @@ Array_subscript(PyObject *_self, PyObject *item)
assert
(
itemdict
);
/* proto is the item type of the array, a
assert
(
itemdict
);
/* proto is the item type of the array, a
ctypes type, so this cannot be NULL */
ctypes type, so this cannot be NULL */
if
(
itemdict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
char
*
ptr
=
(
char
*
)
self
->
b_ptr
;
char
*
ptr
=
(
char
*
)
self
->
b_ptr
;
char
*
dest
;
char
*
dest
;
...
@@ -4346,7 +4346,7 @@ Array_subscript(PyObject *_self, PyObject *item)
...
@@ -4346,7 +4346,7 @@ Array_subscript(PyObject *_self, PyObject *item)
return
np
;
return
np
;
}
}
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
if
(
itemdict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
wchar_t
*
ptr
=
(
wchar_t
*
)
self
->
b_ptr
;
wchar_t
*
ptr
=
(
wchar_t
*
)
self
->
b_ptr
;
wchar_t
*
dest
;
wchar_t
*
dest
;
...
@@ -4415,7 +4415,7 @@ Array_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
...
@@ -4415,7 +4415,7 @@ Array_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
offset
=
index
*
size
;
offset
=
index
*
size
;
ptr
=
self
->
b_ptr
+
offset
;
ptr
=
self
->
b_ptr
+
offset
;
return
CData_set
((
PyObject
*
)
self
,
stgdict
->
proto
,
stgdict
->
setfunc
,
value
,
return
Py
CData_set
((
PyObject
*
)
self
,
stgdict
->
proto
,
stgdict
->
setfunc
,
value
,
index
,
size
,
ptr
);
index
,
size
,
ptr
);
}
}
...
@@ -4545,7 +4545,7 @@ static PyMappingMethods Array_as_mapping = {
...
@@ -4545,7 +4545,7 @@ static PyMappingMethods Array_as_mapping = {
Array_ass_subscript
,
Array_ass_subscript
,
};
};
PyTypeObject
Array_Type
=
{
PyTypeObject
PyC
Array_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.Array"
,
"_ctypes.Array"
,
sizeof
(
CDataObject
),
/* tp_basicsize */
sizeof
(
CDataObject
),
/* tp_basicsize */
...
@@ -4564,11 +4564,11 @@ PyTypeObject Array_Type = {
...
@@ -4564,11 +4564,11 @@ PyTypeObject Array_Type = {
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"XXX to be provided"
,
/* tp_doc */
"XXX to be provided"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
...
@@ -4583,12 +4583,12 @@ PyTypeObject Array_Type = {
...
@@ -4583,12 +4583,12 @@ PyTypeObject Array_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
(
initproc
)
Array_init
,
/* tp_init */
(
initproc
)
Array_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
GenericCData_new
,
/* tp_new */
Generic
Py
CData_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
PyObject
*
PyObject
*
CreateArrayT
ype
(
PyObject
*
itemtype
,
Py_ssize_t
length
)
PyCArrayType_from_ct
ype
(
PyObject
*
itemtype
,
Py_ssize_t
length
)
{
{
static
PyObject
*
cache
;
static
PyObject
*
cache
;
PyObject
*
key
;
PyObject
*
key
;
...
@@ -4628,14 +4628,14 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
...
@@ -4628,14 +4628,14 @@ CreateArrayType(PyObject *itemtype, Py_ssize_t length)
((
PyTypeObject
*
)
itemtype
)
->
tp_name
,
(
long
)
length
);
((
PyTypeObject
*
)
itemtype
)
->
tp_name
,
(
long
)
length
);
#endif
#endif
result
=
PyObject_CallFunction
((
PyObject
*
)
&
ArrayType_Type
,
result
=
PyObject_CallFunction
((
PyObject
*
)
&
PyC
ArrayType_Type
,
#if (PY_VERSION_HEX < 0x02050000)
#if (PY_VERSION_HEX < 0x02050000)
"s(O){s:i,s:O}"
,
"s(O){s:i,s:O}"
,
#else
#else
"s(O){s:n,s:O}"
,
"s(O){s:n,s:O}"
,
#endif
#endif
name
,
name
,
&
Array_Type
,
&
PyC
Array_Type
,
"_length_"
,
"_length_"
,
length
,
length
,
"_type_"
,
"_type_"
,
...
@@ -4711,7 +4711,7 @@ static PyGetSetDef Simple_getsets[] = {
...
@@ -4711,7 +4711,7 @@ static PyGetSetDef Simple_getsets[] = {
static
PyObject
*
static
PyObject
*
Simple_from_outparm
(
PyObject
*
self
,
PyObject
*
args
)
Simple_from_outparm
(
PyObject
*
self
,
PyObject
*
args
)
{
{
if
(
IsSimpleSubTyp
e
((
PyObject
*
)
Py_TYPE
(
self
)))
{
if
(
_ctypes_simple_instanc
e
((
PyObject
*
)
Py_TYPE
(
self
)))
{
Py_INCREF
(
self
);
Py_INCREF
(
self
);
return
self
;
return
self
;
}
}
...
@@ -4801,11 +4801,11 @@ static PyTypeObject Simple_Type = {
...
@@ -4801,11 +4801,11 @@ static PyTypeObject Simple_Type = {
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"XXX to be provided"
,
/* tp_doc */
"XXX to be provided"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
...
@@ -4820,13 +4820,13 @@ static PyTypeObject Simple_Type = {
...
@@ -4820,13 +4820,13 @@ static PyTypeObject Simple_Type = {
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
(
initproc
)
Simple_init
,
/* tp_init */
(
initproc
)
Simple_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
GenericCData_new
,
/* tp_new */
Generic
Py
CData_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
/******************************************************************/
/******************************************************************/
/*
/*
Pointer_Type
P
yCP
ointer_Type
*/
*/
static
PyObject
*
static
PyObject
*
Pointer_item
(
PyObject
*
_self
,
Py_ssize_t
index
)
Pointer_item
(
PyObject
*
_self
,
Py_ssize_t
index
)
...
@@ -4855,7 +4855,7 @@ Pointer_item(PyObject *_self, Py_ssize_t index)
...
@@ -4855,7 +4855,7 @@ Pointer_item(PyObject *_self, Py_ssize_t index)
size
=
itemdict
->
size
;
size
=
itemdict
->
size
;
offset
=
index
*
itemdict
->
size
;
offset
=
index
*
itemdict
->
size
;
return
CData_get
(
proto
,
stgdict
->
getfunc
,
(
PyObject
*
)
self
,
return
Py
CData_get
(
proto
,
stgdict
->
getfunc
,
(
PyObject
*
)
self
,
index
,
size
,
(
*
(
char
**
)
self
->
b_ptr
)
+
offset
);
index
,
size
,
(
*
(
char
**
)
self
->
b_ptr
)
+
offset
);
}
}
...
@@ -4893,7 +4893,7 @@ Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
...
@@ -4893,7 +4893,7 @@ Pointer_ass_item(PyObject *_self, Py_ssize_t index, PyObject *value)
size
=
itemdict
->
size
;
size
=
itemdict
->
size
;
offset
=
index
*
itemdict
->
size
;
offset
=
index
*
itemdict
->
size
;
return
CData_set
((
PyObject
*
)
self
,
proto
,
stgdict
->
setfunc
,
value
,
return
Py
CData_set
((
PyObject
*
)
self
,
proto
,
stgdict
->
setfunc
,
value
,
index
,
size
,
(
*
(
char
**
)
self
->
b_ptr
)
+
offset
);
index
,
size
,
(
*
(
char
**
)
self
->
b_ptr
)
+
offset
);
}
}
...
@@ -4910,7 +4910,7 @@ Pointer_get_contents(CDataObject *self, void *closure)
...
@@ -4910,7 +4910,7 @@ Pointer_get_contents(CDataObject *self, void *closure)
stgdict
=
PyObject_stgdict
((
PyObject
*
)
self
);
stgdict
=
PyObject_stgdict
((
PyObject
*
)
self
);
assert
(
stgdict
);
/* Cannot be NULL fr pointer instances */
assert
(
stgdict
);
/* Cannot be NULL fr pointer instances */
return
CData_FromBaseObj
(
stgdict
->
proto
,
return
Py
CData_FromBaseObj
(
stgdict
->
proto
,
(
PyObject
*
)
self
,
0
,
(
PyObject
*
)
self
,
0
,
*
(
void
**
)
self
->
b_ptr
);
*
(
void
**
)
self
->
b_ptr
);
}
}
...
@@ -4985,7 +4985,7 @@ Pointer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
...
@@ -4985,7 +4985,7 @@ Pointer_new(PyTypeObject *type, PyObject *args, PyObject *kw)
"Cannot create instance: has no _type_"
);
"Cannot create instance: has no _type_"
);
return
NULL
;
return
NULL
;
}
}
return
GenericCData_new
(
type
,
args
,
kw
);
return
Generic
Py
CData_new
(
type
,
args
,
kw
);
}
}
static
PyObject
*
static
PyObject
*
...
@@ -5009,11 +5009,11 @@ Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
...
@@ -5009,11 +5009,11 @@ Pointer_slice(PyObject *_self, Py_ssize_t ilow, Py_ssize_t ihigh)
assert
(
proto
);
assert
(
proto
);
itemdict
=
PyType_stgdict
(
proto
);
itemdict
=
PyType_stgdict
(
proto
);
assert
(
itemdict
);
assert
(
itemdict
);
if
(
itemdict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
char
*
ptr
=
*
(
char
**
)
self
->
b_ptr
;
char
*
ptr
=
*
(
char
**
)
self
->
b_ptr
;
return
PyString_FromStringAndSize
(
ptr
+
ilow
,
len
);
return
PyString_FromStringAndSize
(
ptr
+
ilow
,
len
);
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
}
else
if
(
itemdict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
}
else
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
wchar_t
*
ptr
=
*
(
wchar_t
**
)
self
->
b_ptr
;
wchar_t
*
ptr
=
*
(
wchar_t
**
)
self
->
b_ptr
;
return
PyUnicode_FromWideChar
(
ptr
+
ilow
,
len
);
return
PyUnicode_FromWideChar
(
ptr
+
ilow
,
len
);
#endif
#endif
...
@@ -5103,7 +5103,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
...
@@ -5103,7 +5103,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
assert
(
proto
);
assert
(
proto
);
itemdict
=
PyType_stgdict
(
proto
);
itemdict
=
PyType_stgdict
(
proto
);
assert
(
itemdict
);
assert
(
itemdict
);
if
(
itemdict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
char
*
ptr
=
*
(
char
**
)
self
->
b_ptr
;
char
*
ptr
=
*
(
char
**
)
self
->
b_ptr
;
char
*
dest
;
char
*
dest
;
...
@@ -5124,7 +5124,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
...
@@ -5124,7 +5124,7 @@ Pointer_subscript(PyObject *_self, PyObject *item)
return
np
;
return
np
;
}
}
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
if
(
itemdict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
if
(
itemdict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
wchar_t
*
ptr
=
*
(
wchar_t
**
)
self
->
b_ptr
;
wchar_t
*
ptr
=
*
(
wchar_t
**
)
self
->
b_ptr
;
wchar_t
*
dest
;
wchar_t
*
dest
;
...
@@ -5202,7 +5202,7 @@ static PyNumberMethods Pointer_as_number = {
...
@@ -5202,7 +5202,7 @@ static PyNumberMethods Pointer_as_number = {
(
inquiry
)
Pointer_nonzero
,
/* nb_nonzero */
(
inquiry
)
Pointer_nonzero
,
/* nb_nonzero */
};
};
PyTypeObject
Pointer_Type
=
{
PyTypeObject
P
yCP
ointer_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes._Pointer"
,
"_ctypes._Pointer"
,
sizeof
(
CDataObject
),
/* tp_basicsize */
sizeof
(
CDataObject
),
/* tp_basicsize */
...
@@ -5221,11 +5221,11 @@ PyTypeObject Pointer_Type = {
...
@@ -5221,11 +5221,11 @@ PyTypeObject Pointer_Type = {
0
,
/* tp_str */
0
,
/* tp_str */
0
,
/* tp_getattro */
0
,
/* tp_getattro */
0
,
/* tp_setattro */
0
,
/* tp_setattro */
&
CData_as_buffer
,
/* tp_as_buffer */
&
Py
CData_as_buffer
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_NEWBUFFER
|
Py_TPFLAGS_BASETYPE
,
/* tp_flags */
"XXX to be provided"
,
/* tp_doc */
"XXX to be provided"
,
/* tp_doc */
(
traverseproc
)
CData_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CData_traverse
,
/* tp_traverse */
(
inquiry
)
CData_clear
,
/* tp_clear */
(
inquiry
)
Py
CData_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
...
@@ -5354,9 +5354,9 @@ cast_check_pointertype(PyObject *arg)
...
@@ -5354,9 +5354,9 @@ cast_check_pointertype(PyObject *arg)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
if
(
PointerTypeObject_Check
(
arg
))
if
(
P
yCP
ointerTypeObject_Check
(
arg
))
return
1
;
return
1
;
if
(
CFuncPtrTypeObject_Check
(
arg
))
if
(
Py
CFuncPtrTypeObject_Check
(
arg
))
return
1
;
return
1
;
dict
=
PyType_stgdict
(
arg
);
dict
=
PyType_stgdict
(
arg
);
if
(
dict
)
{
if
(
dict
)
{
...
@@ -5392,9 +5392,9 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
...
@@ -5392,9 +5392,9 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
*/
*/
if
(
CDataObject_Check
(
src
))
{
if
(
CDataObject_Check
(
src
))
{
CDataObject
*
obj
=
(
CDataObject
*
)
src
;
CDataObject
*
obj
=
(
CDataObject
*
)
src
;
/* CData_GetContainer will initialize src.b_objects, we need
/*
Py
CData_GetContainer will initialize src.b_objects, we need
this so it can be shared */
this so it can be shared */
CData_GetContainer
(
obj
);
Py
CData_GetContainer
(
obj
);
/* But we need a dictionary! */
/* But we need a dictionary! */
if
(
obj
->
b_objects
==
Py_None
)
{
if
(
obj
->
b_objects
==
Py_None
)
{
Py_DECREF
(
Py_None
);
Py_DECREF
(
Py_None
);
...
@@ -5448,15 +5448,15 @@ init_ctypes(void)
...
@@ -5448,15 +5448,15 @@ init_ctypes(void)
#ifdef WITH_THREAD
#ifdef WITH_THREAD
PyEval_InitThreads
();
PyEval_InitThreads
();
#endif
#endif
m
=
Py_InitModule3
(
"_ctypes"
,
module_methods
,
module_docs
);
m
=
Py_InitModule3
(
"_ctypes"
,
_ctypes_
module_methods
,
module_docs
);
if
(
!
m
)
if
(
!
m
)
return
;
return
;
_
pointer_
type_cache
=
PyDict_New
();
_
ctypes_ptr
type_cache
=
PyDict_New
();
if
(
_
pointer_
type_cache
==
NULL
)
if
(
_
ctypes_ptr
type_cache
==
NULL
)
return
;
return
;
PyModule_AddObject
(
m
,
"_pointer_type_cache"
,
(
PyObject
*
)
_
pointer_
type_cache
);
PyModule_AddObject
(
m
,
"_pointer_type_cache"
,
(
PyObject
*
)
_
ctypes_ptr
type_cache
);
_unpickle
=
PyObject_GetAttrString
(
m
,
"_unpickle"
);
_unpickle
=
PyObject_GetAttrString
(
m
,
"_unpickle"
);
if
(
_unpickle
==
NULL
)
if
(
_unpickle
==
NULL
)
...
@@ -5465,12 +5465,12 @@ init_ctypes(void)
...
@@ -5465,12 +5465,12 @@ init_ctypes(void)
if
(
PyType_Ready
(
&
PyCArg_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyCArg_Type
)
<
0
)
return
;
return
;
if
(
PyType_Ready
(
&
CThunk_Type
)
<
0
)
if
(
PyType_Ready
(
&
Py
CThunk_Type
)
<
0
)
return
;
return
;
/* StgDict is derived from PyDict_Type */
/* StgDict is derived from PyDict_Type */
StgDict_Type
.
tp_base
=
&
PyDict_Type
;
PyC
StgDict_Type
.
tp_base
=
&
PyDict_Type
;
if
(
PyType_Ready
(
&
StgDict_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyC
StgDict_Type
)
<
0
)
return
;
return
;
/*************************************************
/*************************************************
...
@@ -5478,28 +5478,28 @@ init_ctypes(void)
...
@@ -5478,28 +5478,28 @@ init_ctypes(void)
* Metaclasses
* Metaclasses
*/
*/
StructType_Type
.
tp_base
=
&
PyType_Type
;
PyC
StructType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
StructType_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyC
StructType_Type
)
<
0
)
return
;
return
;
UnionType_Type
.
tp_base
=
&
PyType_Type
;
UnionType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
UnionType_Type
)
<
0
)
if
(
PyType_Ready
(
&
UnionType_Type
)
<
0
)
return
;
return
;
PointerType_Type
.
tp_base
=
&
PyType_Type
;
P
yCP
ointerType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
PointerType_Type
)
<
0
)
if
(
PyType_Ready
(
&
P
yCP
ointerType_Type
)
<
0
)
return
;
return
;
ArrayType_Type
.
tp_base
=
&
PyType_Type
;
PyC
ArrayType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
ArrayType_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyC
ArrayType_Type
)
<
0
)
return
;
return
;
SimpleType_Type
.
tp_base
=
&
PyType_Type
;
PyC
SimpleType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
SimpleType_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyC
SimpleType_Type
)
<
0
)
return
;
return
;
CFuncPtrType_Type
.
tp_base
=
&
PyType_Type
;
Py
CFuncPtrType_Type
.
tp_base
=
&
PyType_Type
;
if
(
PyType_Ready
(
&
CFuncPtrType_Type
)
<
0
)
if
(
PyType_Ready
(
&
Py
CFuncPtrType_Type
)
<
0
)
return
;
return
;
/*************************************************
/*************************************************
...
@@ -5507,52 +5507,52 @@ init_ctypes(void)
...
@@ -5507,52 +5507,52 @@ init_ctypes(void)
* Classes using a custom metaclass
* Classes using a custom metaclass
*/
*/
if
(
PyType_Ready
(
&
CData_Type
)
<
0
)
if
(
PyType_Ready
(
&
Py
CData_Type
)
<
0
)
return
;
return
;
Py_TYPE
(
&
Struct_Type
)
=
&
StructType_Type
;
Py_TYPE
(
&
Struct_Type
)
=
&
PyC
StructType_Type
;
Struct_Type
.
tp_base
=
&
CData_Type
;
Struct_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
Struct_Type
)
<
0
)
if
(
PyType_Ready
(
&
Struct_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"Structure"
,
(
PyObject
*
)
&
Struct_Type
);
PyModule_AddObject
(
m
,
"Structure"
,
(
PyObject
*
)
&
Struct_Type
);
Py_TYPE
(
&
Union_Type
)
=
&
UnionType_Type
;
Py_TYPE
(
&
Union_Type
)
=
&
UnionType_Type
;
Union_Type
.
tp_base
=
&
CData_Type
;
Union_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
Union_Type
)
<
0
)
if
(
PyType_Ready
(
&
Union_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"Union"
,
(
PyObject
*
)
&
Union_Type
);
PyModule_AddObject
(
m
,
"Union"
,
(
PyObject
*
)
&
Union_Type
);
Py_TYPE
(
&
P
ointer_Type
)
=
&
PointerType_Type
;
Py_TYPE
(
&
P
yCPointer_Type
)
=
&
PyC
PointerType_Type
;
P
ointer_Type
.
tp_base
=
&
CData_Type
;
P
yCPointer_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
Pointer_Type
)
<
0
)
if
(
PyType_Ready
(
&
P
yCP
ointer_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"_Pointer"
,
(
PyObject
*
)
&
Pointer_Type
);
PyModule_AddObject
(
m
,
"_Pointer"
,
(
PyObject
*
)
&
P
yCP
ointer_Type
);
Py_TYPE
(
&
Array_Type
)
=
&
ArrayType_Type
;
Py_TYPE
(
&
PyCArray_Type
)
=
&
PyC
ArrayType_Type
;
Array_Type
.
tp_base
=
&
CData_Type
;
PyCArray_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
Array_Type
)
<
0
)
if
(
PyType_Ready
(
&
PyC
Array_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"Array"
,
(
PyObject
*
)
&
Array_Type
);
PyModule_AddObject
(
m
,
"Array"
,
(
PyObject
*
)
&
PyC
Array_Type
);
Py_TYPE
(
&
Simple_Type
)
=
&
SimpleType_Type
;
Py_TYPE
(
&
Simple_Type
)
=
&
PyC
SimpleType_Type
;
Simple_Type
.
tp_base
=
&
CData_Type
;
Simple_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
Simple_Type
)
<
0
)
if
(
PyType_Ready
(
&
Simple_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"_SimpleCData"
,
(
PyObject
*
)
&
Simple_Type
);
PyModule_AddObject
(
m
,
"_SimpleCData"
,
(
PyObject
*
)
&
Simple_Type
);
Py_TYPE
(
&
CFuncPtr_Type
)
=
&
CFuncPtrType_Type
;
Py_TYPE
(
&
PyCFuncPtr_Type
)
=
&
Py
CFuncPtrType_Type
;
CFuncPtr_Type
.
tp_base
=
&
CData_Type
;
PyCFuncPtr_Type
.
tp_base
=
&
Py
CData_Type
;
if
(
PyType_Ready
(
&
CFuncPtr_Type
)
<
0
)
if
(
PyType_Ready
(
&
Py
CFuncPtr_Type
)
<
0
)
return
;
return
;
PyModule_AddObject
(
m
,
"CFuncPtr"
,
(
PyObject
*
)
&
CFuncPtr_Type
);
PyModule_AddObject
(
m
,
"CFuncPtr"
,
(
PyObject
*
)
&
Py
CFuncPtr_Type
);
/*************************************************
/*************************************************
*
*
* Simple classes
* Simple classes
*/
*/
/* CField_Type is derived from PyBaseObject_Type */
/*
Py
CField_Type is derived from PyBaseObject_Type */
if
(
PyType_Ready
(
&
CField_Type
)
<
0
)
if
(
PyType_Ready
(
&
Py
CField_Type
)
<
0
)
return
;
return
;
/*************************************************
/*************************************************
...
@@ -5613,6 +5613,7 @@ init_ctypes(void)
...
@@ -5613,6 +5613,7 @@ init_ctypes(void)
* See #1047269 Buffer overwrite in PyUnicode_AsWideChar
* See #1047269 Buffer overwrite in PyUnicode_AsWideChar
*/
*/
#if (PY_VERSION_HEX < 0x02040000)
#ifdef HAVE_WCHAR_H
#ifdef HAVE_WCHAR_H
PyObject
*
My_PyUnicode_FromWideChar
(
register
const
wchar_t
*
w
,
PyObject
*
My_PyUnicode_FromWideChar
(
register
const
wchar_t
*
w
,
...
@@ -5671,7 +5672,7 @@ Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
...
@@ -5671,7 +5672,7 @@ Py_ssize_t My_PyUnicode_AsWideChar(PyUnicodeObject *unicode,
return
size
;
return
size
;
}
}
#endif
#endif
#endif
/*
/*
...
...
Modules/_ctypes/callbacks.c
View file @
5c6af808
...
@@ -22,7 +22,7 @@ CThunkObject_dealloc(PyObject *_self)
...
@@ -22,7 +22,7 @@ CThunkObject_dealloc(PyObject *_self)
Py_XDECREF
(
self
->
callable
);
Py_XDECREF
(
self
->
callable
);
Py_XDECREF
(
self
->
restype
);
Py_XDECREF
(
self
->
restype
);
if
(
self
->
pcl
)
if
(
self
->
pcl
)
FreeC
losure
(
self
->
pcl
);
_ctypes_free_c
losure
(
self
->
pcl
);
PyObject_Del
(
self
);
PyObject_Del
(
self
);
}
}
...
@@ -46,7 +46,7 @@ CThunkObject_clear(PyObject *_self)
...
@@ -46,7 +46,7 @@ CThunkObject_clear(PyObject *_self)
return
0
;
return
0
;
}
}
PyTypeObject
CThunk_Type
=
{
PyTypeObject
Py
CThunk_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.CThunkObject"
,
"_ctypes.CThunkObject"
,
sizeof
(
CThunkObject
),
/* tp_basicsize */
sizeof
(
CThunkObject
),
/* tp_basicsize */
...
@@ -97,7 +97,7 @@ PrintError(char *msg, ...)
...
@@ -97,7 +97,7 @@ PrintError(char *msg, ...)
/* after code that pyrex generates */
/* after code that pyrex generates */
void
_
AddT
raceback
(
char
*
funcname
,
char
*
filename
,
int
lineno
)
void
_
ctypes_add_t
raceback
(
char
*
funcname
,
char
*
filename
,
int
lineno
)
{
{
PyObject
*
py_srcfile
=
0
;
PyObject
*
py_srcfile
=
0
;
PyObject
*
py_funcname
=
0
;
PyObject
*
py_funcname
=
0
;
...
@@ -227,7 +227,7 @@ static void _CallPythonObject(void *mem,
...
@@ -227,7 +227,7 @@ static void _CallPythonObject(void *mem,
goto
Done
;
goto
Done
;
}
}
if
(
dict
&&
dict
->
getfunc
&&
!
IsSimpleSubTyp
e
(
cnv
))
{
if
(
dict
&&
dict
->
getfunc
&&
!
_ctypes_simple_instanc
e
(
cnv
))
{
PyObject
*
v
=
dict
->
getfunc
(
*
pArgs
,
dict
->
size
);
PyObject
*
v
=
dict
->
getfunc
(
*
pArgs
,
dict
->
size
);
if
(
!
v
)
{
if
(
!
v
)
{
PrintError
(
"create argument %d:
\n
"
,
i
);
PrintError
(
"create argument %d:
\n
"
,
i
);
...
@@ -241,7 +241,7 @@ static void _CallPythonObject(void *mem,
...
@@ -241,7 +241,7 @@ static void _CallPythonObject(void *mem,
BTW, the same problem occurrs when they are pushed as parameters
BTW, the same problem occurrs when they are pushed as parameters
*/
*/
}
else
if
(
dict
)
{
}
else
if
(
dict
)
{
/* Hm, shouldn't we use CData_AtAddress() or something like that instead? */
/* Hm, shouldn't we use
Py
CData_AtAddress() or something like that instead? */
CDataObject
*
obj
=
(
CDataObject
*
)
PyObject_CallFunctionObjArgs
(
cnv
,
NULL
);
CDataObject
*
obj
=
(
CDataObject
*
)
PyObject_CallFunctionObjArgs
(
cnv
,
NULL
);
if
(
!
obj
)
{
if
(
!
obj
)
{
PrintError
(
"create argument %d:
\n
"
,
i
);
PrintError
(
"create argument %d:
\n
"
,
i
);
...
@@ -272,10 +272,10 @@ static void _CallPythonObject(void *mem,
...
@@ -272,10 +272,10 @@ static void _CallPythonObject(void *mem,
}
}
#define CHECK(what, x) \
#define CHECK(what, x) \
if (x == NULL) _
AddT
raceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
if (x == NULL) _
ctypes_add_t
raceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_Print()
if
(
flags
&
(
FUNCFLAG_USE_ERRNO
|
FUNCFLAG_USE_LASTERROR
))
{
if
(
flags
&
(
FUNCFLAG_USE_ERRNO
|
FUNCFLAG_USE_LASTERROR
))
{
error_object
=
get_error_object
(
&
space
);
error_object
=
_ctypes_get_errobj
(
&
space
);
if
(
error_object
==
NULL
)
if
(
error_object
==
NULL
)
goto
Done
;
goto
Done
;
if
(
flags
&
FUNCFLAG_USE_ERRNO
)
{
if
(
flags
&
FUNCFLAG_USE_ERRNO
)
{
...
@@ -332,7 +332,7 @@ if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_P
...
@@ -332,7 +332,7 @@ if (x == NULL) _AddTraceback(what, "_ctypes/callbacks.c", __LINE__ - 1), PyErr_P
PyErr_WriteUnraisable
(
callable
);
PyErr_WriteUnraisable
(
callable
);
else
if
(
keep
==
Py_None
)
/* Nothing to keep */
else
if
(
keep
==
Py_None
)
/* Nothing to keep */
Py_DECREF
(
keep
);
Py_DECREF
(
keep
);
else
if
(
setfunc
!=
getentry
(
"O"
)
->
setfunc
)
{
else
if
(
setfunc
!=
_ctypes_get_fielddesc
(
"O"
)
->
setfunc
)
{
if
(
-
1
==
PyErr_Warn
(
PyExc_RuntimeWarning
,
if
(
-
1
==
PyErr_Warn
(
PyExc_RuntimeWarning
,
"memory leak in callback function."
))
"memory leak in callback function."
))
PyErr_WriteUnraisable
(
callable
);
PyErr_WriteUnraisable
(
callable
);
...
@@ -367,7 +367,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
...
@@ -367,7 +367,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
CThunkObject
*
p
;
CThunkObject
*
p
;
int
i
;
int
i
;
p
=
PyObject_NewVar
(
CThunkObject
,
&
CThunk_Type
,
nArgs
);
p
=
PyObject_NewVar
(
CThunkObject
,
&
Py
CThunk_Type
,
nArgs
);
if
(
p
==
NULL
)
{
if
(
p
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
return
NULL
;
return
NULL
;
...
@@ -385,7 +385,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
...
@@ -385,7 +385,7 @@ static CThunkObject* CThunkObject_new(Py_ssize_t nArgs)
return
p
;
return
p
;
}
}
CThunkObject
*
AllocFunctionC
allback
(
PyObject
*
callable
,
CThunkObject
*
_ctypes_alloc_c
allback
(
PyObject
*
callable
,
PyObject
*
converters
,
PyObject
*
converters
,
PyObject
*
restype
,
PyObject
*
restype
,
int
flags
)
int
flags
)
...
@@ -402,7 +402,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
...
@@ -402,7 +402,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
assert
(
CThunk_CheckExact
(
p
));
assert
(
CThunk_CheckExact
(
p
));
p
->
pcl
=
MallocC
losure
();
p
->
pcl
=
_ctypes_alloc_c
losure
();
if
(
p
->
pcl
==
NULL
)
{
if
(
p
->
pcl
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
goto
error
;
goto
error
;
...
@@ -413,7 +413,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
...
@@ -413,7 +413,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
PyObject
*
cnv
=
PySequence_GetItem
(
converters
,
i
);
PyObject
*
cnv
=
PySequence_GetItem
(
converters
,
i
);
if
(
cnv
==
NULL
)
if
(
cnv
==
NULL
)
goto
error
;
goto
error
;
p
->
atypes
[
i
]
=
GetT
ype
(
cnv
);
p
->
atypes
[
i
]
=
_ctypes_get_ffi_t
ype
(
cnv
);
Py_DECREF
(
cnv
);
Py_DECREF
(
cnv
);
}
}
p
->
atypes
[
i
]
=
NULL
;
p
->
atypes
[
i
]
=
NULL
;
...
@@ -441,7 +441,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
...
@@ -441,7 +441,7 @@ CThunkObject *AllocFunctionCallback(PyObject *callable,
#endif
#endif
result
=
ffi_prep_cif
(
&
p
->
cif
,
cc
,
result
=
ffi_prep_cif
(
&
p
->
cif
,
cc
,
Py_SAFE_DOWNCAST
(
nArgs
,
Py_ssize_t
,
int
),
Py_SAFE_DOWNCAST
(
nArgs
,
Py_ssize_t
,
int
),
GetT
ype
(
restype
),
_ctypes_get_ffi_t
ype
(
restype
),
&
p
->
atypes
[
0
]);
&
p
->
atypes
[
0
]);
if
(
result
!=
FFI_OK
)
{
if
(
result
!=
FFI_OK
)
{
PyErr_Format
(
PyExc_RuntimeError
,
PyErr_Format
(
PyExc_RuntimeError
,
...
...
Modules/_ctypes/callproc.c
View file @
5c6af808
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
/*
/*
How are functions called, and how are parameters converted to C ?
How are functions called, and how are parameters converted to C ?
1. _ctypes.c::CFuncPtr_call receives an argument tuple 'inargs' and a
1. _ctypes.c::
Py
CFuncPtr_call receives an argument tuple 'inargs' and a
keyword dictionary 'kwds'.
keyword dictionary 'kwds'.
2. After several checks, _build_callargs() is called which returns another
2. After several checks, _build_callargs() is called which returns another
...
@@ -32,7 +32,7 @@
...
@@ -32,7 +32,7 @@
the callargs tuple, specifying how to build the return value(s) of
the callargs tuple, specifying how to build the return value(s) of
the function.
the function.
4. _
CallProc is then called with the 'callargs' tuple. _CallP
roc first
4. _
ctypes_callproc is then called with the 'callargs' tuple. _ctypes_callp
roc first
allocates two arrays. The first is an array of 'struct argument' items, the
allocates two arrays. The first is an array of 'struct argument' items, the
second array has 'void *' entried.
second array has 'void *' entried.
...
@@ -52,8 +52,8 @@
...
@@ -52,8 +52,8 @@
libffi specific stuff, then it calls ffi_call.
libffi specific stuff, then it calls ffi_call.
So, there are 4 data structures holding processed arguments:
So, there are 4 data structures holding processed arguments:
- the inargs tuple (in CFuncPtr_call)
- the inargs tuple (in
Py
CFuncPtr_call)
- the callargs tuple (in CFuncPtr_call)
- the callargs tuple (in
Py
CFuncPtr_call)
- the 'struct argguments' array
- the 'struct argguments' array
- the 'void *' array
- the 'void *' array
...
@@ -118,7 +118,7 @@
...
@@ -118,7 +118,7 @@
kept alive in the thread state dictionary as long as the thread itself.
kept alive in the thread state dictionary as long as the thread itself.
*/
*/
PyObject
*
PyObject
*
get_error_object
(
int
**
pspace
)
_ctypes_get_errobj
(
int
**
pspace
)
{
{
PyObject
*
dict
=
PyThreadState_GetDict
();
PyObject
*
dict
=
PyThreadState_GetDict
();
PyObject
*
errobj
;
PyObject
*
errobj
;
...
@@ -158,7 +158,7 @@ static PyObject *
...
@@ -158,7 +158,7 @@ static PyObject *
get_error_internal
(
PyObject
*
self
,
PyObject
*
args
,
int
index
)
get_error_internal
(
PyObject
*
self
,
PyObject
*
args
,
int
index
)
{
{
int
*
space
;
int
*
space
;
PyObject
*
errobj
=
get_error_object
(
&
space
);
PyObject
*
errobj
=
_ctypes_get_errobj
(
&
space
);
PyObject
*
result
;
PyObject
*
result
;
if
(
errobj
==
NULL
)
if
(
errobj
==
NULL
)
...
@@ -177,7 +177,7 @@ set_error_internal(PyObject *self, PyObject *args, int index)
...
@@ -177,7 +177,7 @@ set_error_internal(PyObject *self, PyObject *args, int index)
if
(
!
PyArg_ParseTuple
(
args
,
"i"
,
&
new_errno
))
if
(
!
PyArg_ParseTuple
(
args
,
"i"
,
&
new_errno
))
return
NULL
;
return
NULL
;
errobj
=
get_error_object
(
&
space
);
errobj
=
_ctypes_get_errobj
(
&
space
);
if
(
errobj
==
NULL
)
if
(
errobj
==
NULL
)
return
NULL
;
return
NULL
;
old_errno
=
space
[
index
];
old_errno
=
space
[
index
];
...
@@ -410,7 +410,7 @@ check_hresult(PyObject *self, PyObject *args)
...
@@ -410,7 +410,7 @@ check_hresult(PyObject *self, PyObject *args)
/**************************************************************/
/**************************************************************/
PyCArgObject
*
PyCArgObject
*
new_CArgObject
(
void
)
PyCArgObject_new
(
void
)
{
{
PyCArgObject
*
p
;
PyCArgObject
*
p
;
p
=
PyObject_New
(
PyCArgObject
,
&
PyCArg_Type
);
p
=
PyObject_New
(
PyCArgObject
,
&
PyCArg_Type
);
...
@@ -708,7 +708,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
...
@@ -708,7 +708,7 @@ static int ConvParam(PyObject *obj, Py_ssize_t index, struct argument *pa)
}
}
ffi_type
*
GetT
ype
(
PyObject
*
obj
)
ffi_type
*
_ctypes_get_ffi_t
ype
(
PyObject
*
obj
)
{
{
StgDictObject
*
dict
;
StgDictObject
*
dict
;
if
(
obj
==
NULL
)
if
(
obj
==
NULL
)
...
@@ -788,7 +788,7 @@ static int _call_function_pointer(int flags,
...
@@ -788,7 +788,7 @@ static int _call_function_pointer(int flags,
}
}
if
(
flags
&
(
FUNCFLAG_USE_ERRNO
|
FUNCFLAG_USE_LASTERROR
))
{
if
(
flags
&
(
FUNCFLAG_USE_ERRNO
|
FUNCFLAG_USE_LASTERROR
))
{
error_object
=
get_error_object
(
&
space
);
error_object
=
_ctypes_get_errobj
(
&
space
);
if
(
error_object
==
NULL
)
if
(
error_object
==
NULL
)
return
-
1
;
return
-
1
;
}
}
...
@@ -906,24 +906,24 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
...
@@ -906,24 +906,24 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
if
(
dict
==
NULL
)
if
(
dict
==
NULL
)
return
PyObject_CallFunction
(
restype
,
"i"
,
*
(
int
*
)
result
);
return
PyObject_CallFunction
(
restype
,
"i"
,
*
(
int
*
)
result
);
if
(
dict
->
getfunc
&&
!
IsSimpleSubTyp
e
(
restype
))
{
if
(
dict
->
getfunc
&&
!
_ctypes_simple_instanc
e
(
restype
))
{
retval
=
dict
->
getfunc
(
result
,
dict
->
size
);
retval
=
dict
->
getfunc
(
result
,
dict
->
size
);
/* If restype is py_object (detected by comparing getfunc with
/* If restype is py_object (detected by comparing getfunc with
O_get), we have to call Py_DECREF because O_get has already
O_get), we have to call Py_DECREF because O_get has already
called Py_INCREF.
called Py_INCREF.
*/
*/
if
(
dict
->
getfunc
==
getentry
(
"O"
)
->
getfunc
)
{
if
(
dict
->
getfunc
==
_ctypes_get_fielddesc
(
"O"
)
->
getfunc
)
{
Py_DECREF
(
retval
);
Py_DECREF
(
retval
);
}
}
}
else
}
else
retval
=
CData_FromBaseObj
(
restype
,
NULL
,
0
,
result
);
retval
=
Py
CData_FromBaseObj
(
restype
,
NULL
,
0
,
result
);
if
(
!
checker
||
!
retval
)
if
(
!
checker
||
!
retval
)
return
retval
;
return
retval
;
v
=
PyObject_CallFunctionObjArgs
(
checker
,
retval
,
NULL
);
v
=
PyObject_CallFunctionObjArgs
(
checker
,
retval
,
NULL
);
if
(
v
==
NULL
)
if
(
v
==
NULL
)
_
AddT
raceback
(
"GetResult"
,
"_ctypes/callproc.c"
,
__LINE__
-
2
);
_
ctypes_add_t
raceback
(
"GetResult"
,
"_ctypes/callproc.c"
,
__LINE__
-
2
);
Py_DECREF
(
retval
);
Py_DECREF
(
retval
);
return
v
;
return
v
;
}
}
...
@@ -932,7 +932,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
...
@@ -932,7 +932,7 @@ static PyObject *GetResult(PyObject *restype, void *result, PyObject *checker)
* Raise a new exception 'exc_class', adding additional text to the original
* Raise a new exception 'exc_class', adding additional text to the original
* exception string.
* exception string.
*/
*/
void
Extend_Error_Info
(
PyObject
*
exc_class
,
char
*
fmt
,
...)
void
_ctypes_extend_error
(
PyObject
*
exc_class
,
char
*
fmt
,
...)
{
{
va_list
vargs
;
va_list
vargs
;
PyObject
*
tp
,
*
v
,
*
tb
,
*
s
,
*
cls_str
,
*
msg_str
;
PyObject
*
tp
,
*
v
,
*
tb
,
*
s
,
*
cls_str
,
*
msg_str
;
...
@@ -1057,7 +1057,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
...
@@ -1057,7 +1057,7 @@ GetComError(HRESULT errcode, GUID *riid, IUnknown *pIunk)
*
*
* - XXX various requirements for restype, not yet collected
* - XXX various requirements for restype, not yet collected
*/
*/
PyObject
*
_
CallP
roc
(
PPROC
pProc
,
PyObject
*
_
ctypes_callp
roc
(
PPROC
pProc
,
PyObject
*
argtuple
,
PyObject
*
argtuple
,
#ifdef MS_WIN32
#ifdef MS_WIN32
IUnknown
*
pIunk
,
IUnknown
*
pIunk
,
...
@@ -1110,7 +1110,7 @@ PyObject *_CallProc(PPROC pProc,
...
@@ -1110,7 +1110,7 @@ PyObject *_CallProc(PPROC pProc,
arg
=
PyTuple_GET_ITEM
(
argtuple
,
i
);
/* borrowed ref */
arg
=
PyTuple_GET_ITEM
(
argtuple
,
i
);
/* borrowed ref */
/* For cdecl functions, we allow more actual arguments
/* For cdecl functions, we allow more actual arguments
than the length of the argtypes tuple.
than the length of the argtypes tuple.
This is checked in _ctypes::CFuncPtr_Call
This is checked in _ctypes::
Py
CFuncPtr_Call
*/
*/
if
(
argtypes
&&
argtype_count
>
i
)
{
if
(
argtypes
&&
argtype_count
>
i
)
{
PyObject
*
v
;
PyObject
*
v
;
...
@@ -1119,26 +1119,26 @@ PyObject *_CallProc(PPROC pProc,
...
@@ -1119,26 +1119,26 @@ PyObject *_CallProc(PPROC pProc,
arg
,
arg
,
NULL
);
NULL
);
if
(
v
==
NULL
)
{
if
(
v
==
NULL
)
{
Extend_Error_Info
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
_ctypes_extend_error
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
goto
cleanup
;
goto
cleanup
;
}
}
err
=
ConvParam
(
v
,
i
+
1
,
pa
);
err
=
ConvParam
(
v
,
i
+
1
,
pa
);
Py_DECREF
(
v
);
Py_DECREF
(
v
);
if
(
-
1
==
err
)
{
if
(
-
1
==
err
)
{
Extend_Error_Info
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
_ctypes_extend_error
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
goto
cleanup
;
goto
cleanup
;
}
}
}
else
{
}
else
{
err
=
ConvParam
(
arg
,
i
+
1
,
pa
);
err
=
ConvParam
(
arg
,
i
+
1
,
pa
);
if
(
-
1
==
err
)
{
if
(
-
1
==
err
)
{
Extend_Error_Info
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
_ctypes_extend_error
(
PyExc_ArgError
,
"argument %d: "
,
i
+
1
);
goto
cleanup
;
/* leaking ? */
goto
cleanup
;
/* leaking ? */
}
}
}
}
}
}
rtype
=
GetT
ype
(
restype
);
rtype
=
_ctypes_get_ffi_t
ype
(
restype
);
resbuf
=
alloca
(
max
(
rtype
->
size
,
sizeof
(
ffi_arg
)));
resbuf
=
alloca
(
max
(
rtype
->
size
,
sizeof
(
ffi_arg
)));
avalues
=
(
void
**
)
alloca
(
sizeof
(
void
*
)
*
argcount
);
avalues
=
(
void
**
)
alloca
(
sizeof
(
void
*
)
*
argcount
);
...
@@ -1350,7 +1350,7 @@ call_commethod(PyObject *self, PyObject *args)
...
@@ -1350,7 +1350,7 @@ call_commethod(PyObject *self, PyObject *args)
pIunk
=
(
IUnknown
*
)(
*
(
void
**
)(
pcom
->
b_ptr
));
pIunk
=
(
IUnknown
*
)(
*
(
void
**
)(
pcom
->
b_ptr
));
lpVtbl
=
(
PPROC
*
)(
pIunk
->
lpVtbl
);
lpVtbl
=
(
PPROC
*
)(
pIunk
->
lpVtbl
);
result
=
_
CallP
roc
(
lpVtbl
[
index
],
result
=
_
ctypes_callp
roc
(
lpVtbl
[
index
],
arguments
,
arguments
,
#ifdef MS_WIN32
#ifdef MS_WIN32
pIunk
,
pIunk
,
...
@@ -1473,7 +1473,7 @@ call_function(PyObject *self, PyObject *args)
...
@@ -1473,7 +1473,7 @@ call_function(PyObject *self, PyObject *args)
&
PyTuple_Type
,
&
arguments
))
&
PyTuple_Type
,
&
arguments
))
return
NULL
;
return
NULL
;
result
=
_
CallP
roc
((
PPROC
)
func
,
result
=
_
ctypes_callp
roc
((
PPROC
)
func
,
arguments
,
arguments
,
#ifdef MS_WIN32
#ifdef MS_WIN32
NULL
,
NULL
,
...
@@ -1504,7 +1504,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
...
@@ -1504,7 +1504,7 @@ call_cdeclfunction(PyObject *self, PyObject *args)
&
PyTuple_Type
,
&
arguments
))
&
PyTuple_Type
,
&
arguments
))
return
NULL
;
return
NULL
;
result
=
_
CallP
roc
((
PPROC
)
func
,
result
=
_
ctypes_callp
roc
((
PPROC
)
func
,
arguments
,
arguments
,
#ifdef MS_WIN32
#ifdef MS_WIN32
NULL
,
NULL
,
...
@@ -1596,7 +1596,7 @@ byref(PyObject *self, PyObject *args)
...
@@ -1596,7 +1596,7 @@ byref(PyObject *self, PyObject *args)
return
NULL
;
return
NULL
;
}
}
parg
=
new_CArgObject
();
parg
=
PyCArgObject_new
();
if
(
parg
==
NULL
)
if
(
parg
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -1671,17 +1671,17 @@ set_conversion_mode(PyObject *self, PyObject *args)
...
@@ -1671,17 +1671,17 @@ set_conversion_mode(PyObject *self, PyObject *args)
if
(
!
PyArg_ParseTuple
(
args
,
"zs:set_conversion_mode"
,
&
coding
,
&
mode
))
if
(
!
PyArg_ParseTuple
(
args
,
"zs:set_conversion_mode"
,
&
coding
,
&
mode
))
return
NULL
;
return
NULL
;
result
=
Py_BuildValue
(
"(zz)"
,
conversion_mode_encoding
,
conversion_mode
_errors
);
result
=
Py_BuildValue
(
"(zz)"
,
_ctypes_conversion_encoding
,
_ctypes_conversion
_errors
);
if
(
coding
)
{
if
(
coding
)
{
PyMem_Free
(
conversion_mode
_encoding
);
PyMem_Free
(
_ctypes_conversion
_encoding
);
conversion_mode
_encoding
=
PyMem_Malloc
(
strlen
(
coding
)
+
1
);
_ctypes_conversion
_encoding
=
PyMem_Malloc
(
strlen
(
coding
)
+
1
);
strcpy
(
conversion_mode
_encoding
,
coding
);
strcpy
(
_ctypes_conversion
_encoding
,
coding
);
}
else
{
}
else
{
conversion_mode
_encoding
=
NULL
;
_ctypes_conversion
_encoding
=
NULL
;
}
}
PyMem_Free
(
conversion_mode
_errors
);
PyMem_Free
(
_ctypes_conversion
_errors
);
conversion_mode
_errors
=
PyMem_Malloc
(
strlen
(
mode
)
+
1
);
_ctypes_conversion
_errors
=
PyMem_Malloc
(
strlen
(
mode
)
+
1
);
strcpy
(
conversion_mode
_errors
,
mode
);
strcpy
(
_ctypes_conversion
_errors
,
mode
);
return
result
;
return
result
;
}
}
#endif
#endif
...
@@ -1780,7 +1780,7 @@ POINTER(PyObject *self, PyObject *cls)
...
@@ -1780,7 +1780,7 @@ POINTER(PyObject *self, PyObject *cls)
PyObject
*
key
;
PyObject
*
key
;
char
*
buf
;
char
*
buf
;
result
=
PyDict_GetItem
(
_
pointer_
type_cache
,
cls
);
result
=
PyDict_GetItem
(
_
ctypes_ptr
type_cache
,
cls
);
if
(
result
)
{
if
(
result
)
{
Py_INCREF
(
result
);
Py_INCREF
(
result
);
return
result
;
return
result
;
...
@@ -1788,10 +1788,10 @@ POINTER(PyObject *self, PyObject *cls)
...
@@ -1788,10 +1788,10 @@ POINTER(PyObject *self, PyObject *cls)
if
(
PyString_CheckExact
(
cls
))
{
if
(
PyString_CheckExact
(
cls
))
{
buf
=
alloca
(
strlen
(
PyString_AS_STRING
(
cls
))
+
3
+
1
);
buf
=
alloca
(
strlen
(
PyString_AS_STRING
(
cls
))
+
3
+
1
);
sprintf
(
buf
,
"LP_%s"
,
PyString_AS_STRING
(
cls
));
sprintf
(
buf
,
"LP_%s"
,
PyString_AS_STRING
(
cls
));
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
Pointer_Type
),
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
P
yCP
ointer_Type
),
"s(O){}"
,
"s(O){}"
,
buf
,
buf
,
&
Pointer_Type
);
&
P
yCP
ointer_Type
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
result
;
return
result
;
key
=
PyLong_FromVoidPtr
(
result
);
key
=
PyLong_FromVoidPtr
(
result
);
...
@@ -1799,10 +1799,10 @@ POINTER(PyObject *self, PyObject *cls)
...
@@ -1799,10 +1799,10 @@ POINTER(PyObject *self, PyObject *cls)
typ
=
(
PyTypeObject
*
)
cls
;
typ
=
(
PyTypeObject
*
)
cls
;
buf
=
alloca
(
strlen
(
typ
->
tp_name
)
+
3
+
1
);
buf
=
alloca
(
strlen
(
typ
->
tp_name
)
+
3
+
1
);
sprintf
(
buf
,
"LP_%s"
,
typ
->
tp_name
);
sprintf
(
buf
,
"LP_%s"
,
typ
->
tp_name
);
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
Pointer_Type
),
result
=
PyObject_CallFunction
((
PyObject
*
)
Py_TYPE
(
&
P
yCP
ointer_Type
),
"s(O){sO}"
,
"s(O){sO}"
,
buf
,
buf
,
&
Pointer_Type
,
&
P
yCP
ointer_Type
,
"_type_"
,
cls
);
"_type_"
,
cls
);
if
(
result
==
NULL
)
if
(
result
==
NULL
)
return
result
;
return
result
;
...
@@ -1812,7 +1812,7 @@ POINTER(PyObject *self, PyObject *cls)
...
@@ -1812,7 +1812,7 @@ POINTER(PyObject *self, PyObject *cls)
PyErr_SetString
(
PyExc_TypeError
,
"must be a ctypes type"
);
PyErr_SetString
(
PyExc_TypeError
,
"must be a ctypes type"
);
return
NULL
;
return
NULL
;
}
}
if
(
-
1
==
PyDict_SetItem
(
_
pointer_
type_cache
,
key
,
result
))
{
if
(
-
1
==
PyDict_SetItem
(
_
ctypes_ptr
type_cache
,
key
,
result
))
{
Py_DECREF
(
result
);
Py_DECREF
(
result
);
Py_DECREF
(
key
);
Py_DECREF
(
key
);
return
NULL
;
return
NULL
;
...
@@ -1827,7 +1827,7 @@ pointer(PyObject *self, PyObject *arg)
...
@@ -1827,7 +1827,7 @@ pointer(PyObject *self, PyObject *arg)
PyObject
*
result
;
PyObject
*
result
;
PyObject
*
typ
;
PyObject
*
typ
;
typ
=
PyDict_GetItem
(
_
pointer_
type_cache
,
(
PyObject
*
)
Py_TYPE
(
arg
));
typ
=
PyDict_GetItem
(
_
ctypes_ptr
type_cache
,
(
PyObject
*
)
Py_TYPE
(
arg
));
if
(
typ
)
if
(
typ
)
return
PyObject_CallFunctionObjArgs
(
typ
,
arg
,
NULL
);
return
PyObject_CallFunctionObjArgs
(
typ
,
arg
,
NULL
);
typ
=
POINTER
(
NULL
,
(
PyObject
*
)
Py_TYPE
(
arg
));
typ
=
POINTER
(
NULL
,
(
PyObject
*
)
Py_TYPE
(
arg
));
...
@@ -1865,7 +1865,7 @@ buffer_info(PyObject *self, PyObject *arg)
...
@@ -1865,7 +1865,7 @@ buffer_info(PyObject *self, PyObject *arg)
return
Py_BuildValue
(
"siN"
,
dict
->
format
,
dict
->
ndim
,
shape
);
return
Py_BuildValue
(
"siN"
,
dict
->
format
,
dict
->
ndim
,
shape
);
}
}
PyMethodDef
module_methods
[]
=
{
PyMethodDef
_ctypes_
module_methods
[]
=
{
{
"get_errno"
,
get_errno
,
METH_NOARGS
},
{
"get_errno"
,
get_errno
,
METH_NOARGS
},
{
"set_errno"
,
set_errno
,
METH_VARARGS
},
{
"set_errno"
,
set_errno
,
METH_VARARGS
},
{
"POINTER"
,
POINTER
,
METH_O
},
{
"POINTER"
,
POINTER
,
METH_O
},
...
...
Modules/_ctypes/cfield.c
View file @
5c6af808
...
@@ -12,10 +12,10 @@
...
@@ -12,10 +12,10 @@
/******************************************************************/
/******************************************************************/
/*
/*
CField_Type
Py
CField_Type
*/
*/
static
PyObject
*
static
PyObject
*
CField_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
Py
CField_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
CFieldObject
*
obj
;
CFieldObject
*
obj
;
obj
=
(
CFieldObject
*
)
type
->
tp_alloc
(
type
,
0
);
obj
=
(
CFieldObject
*
)
type
->
tp_alloc
(
type
,
0
);
...
@@ -35,7 +35,7 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -35,7 +35,7 @@ CField_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
* prev_desc points to the type of the previous bitfield, if any.
* prev_desc points to the type of the previous bitfield, if any.
*/
*/
PyObject
*
PyObject
*
CField_FromDesc
(
PyObject
*
desc
,
Py_ssize_t
index
,
Py
CField_FromDesc
(
PyObject
*
desc
,
Py_ssize_t
index
,
Py_ssize_t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
Py_ssize_t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
poffset
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
poffset
,
Py_ssize_t
*
palign
,
int
pack
,
int
big_endian
)
int
pack
,
int
big_endian
)
...
@@ -52,7 +52,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
...
@@ -52,7 +52,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
#define CONT_BITFIELD 2
#define CONT_BITFIELD 2
#define EXPAND_BITFIELD 3
#define EXPAND_BITFIELD 3
self
=
(
CFieldObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
CField_Type
,
self
=
(
CFieldObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
Py
CField_Type
,
NULL
);
NULL
);
if
(
self
==
NULL
)
if
(
self
==
NULL
)
return
NULL
;
return
NULL
;
...
@@ -102,7 +102,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
...
@@ -102,7 +102,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
/* Field descriptors for 'c_char * n' are be scpecial cased to
/* Field descriptors for 'c_char * n' are be scpecial cased to
return a Python string instead of an Array object instance...
return a Python string instead of an Array object instance...
*/
*/
if
(
ArrayTypeObject_Check
(
proto
))
{
if
(
PyC
ArrayTypeObject_Check
(
proto
))
{
StgDictObject
*
adict
=
PyType_stgdict
(
proto
);
StgDictObject
*
adict
=
PyType_stgdict
(
proto
);
StgDictObject
*
idict
;
StgDictObject
*
idict
;
if
(
adict
&&
adict
->
proto
)
{
if
(
adict
&&
adict
->
proto
)
{
...
@@ -113,14 +113,14 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
...
@@ -113,14 +113,14 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
Py_DECREF
(
self
);
Py_DECREF
(
self
);
return
NULL
;
return
NULL
;
}
}
if
(
idict
->
getfunc
==
getentry
(
"c"
)
->
getfunc
)
{
if
(
idict
->
getfunc
==
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
)
{
struct
fielddesc
*
fd
=
getentry
(
"s"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"s"
);
getfunc
=
fd
->
getfunc
;
getfunc
=
fd
->
getfunc
;
setfunc
=
fd
->
setfunc
;
setfunc
=
fd
->
setfunc
;
}
}
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
if
(
idict
->
getfunc
==
getentry
(
"u"
)
->
getfunc
)
{
if
(
idict
->
getfunc
==
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
)
{
struct
fielddesc
*
fd
=
getentry
(
"U"
);
struct
fielddesc
*
fd
=
_ctypes_get_fielddesc
(
"U"
);
getfunc
=
fd
->
getfunc
;
getfunc
=
fd
->
getfunc
;
setfunc
=
fd
->
setfunc
;
setfunc
=
fd
->
setfunc
;
}
}
...
@@ -194,7 +194,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
...
@@ -194,7 +194,7 @@ CField_FromDesc(PyObject *desc, Py_ssize_t index,
}
}
static
int
static
int
CField_set
(
CFieldObject
*
self
,
PyObject
*
inst
,
PyObject
*
value
)
Py
CField_set
(
CFieldObject
*
self
,
PyObject
*
inst
,
PyObject
*
value
)
{
{
CDataObject
*
dst
;
CDataObject
*
dst
;
char
*
ptr
;
char
*
ptr
;
...
@@ -206,12 +206,12 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value)
...
@@ -206,12 +206,12 @@ CField_set(CFieldObject *self, PyObject *inst, PyObject *value)
"can't delete attribute"
);
"can't delete attribute"
);
return
-
1
;
return
-
1
;
}
}
return
CData_set
(
inst
,
self
->
proto
,
self
->
setfunc
,
value
,
return
Py
CData_set
(
inst
,
self
->
proto
,
self
->
setfunc
,
value
,
self
->
index
,
self
->
size
,
ptr
);
self
->
index
,
self
->
size
,
ptr
);
}
}
static
PyObject
*
static
PyObject
*
CField_get
(
CFieldObject
*
self
,
PyObject
*
inst
,
PyTypeObject
*
type
)
Py
CField_get
(
CFieldObject
*
self
,
PyObject
*
inst
,
PyTypeObject
*
type
)
{
{
CDataObject
*
src
;
CDataObject
*
src
;
if
(
inst
==
NULL
)
{
if
(
inst
==
NULL
)
{
...
@@ -220,51 +220,51 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
...
@@ -220,51 +220,51 @@ CField_get(CFieldObject *self, PyObject *inst, PyTypeObject *type)
}
}
assert
(
CDataObject_Check
(
inst
));
assert
(
CDataObject_Check
(
inst
));
src
=
(
CDataObject
*
)
inst
;
src
=
(
CDataObject
*
)
inst
;
return
CData_get
(
self
->
proto
,
self
->
getfunc
,
inst
,
return
Py
CData_get
(
self
->
proto
,
self
->
getfunc
,
inst
,
self
->
index
,
self
->
size
,
src
->
b_ptr
+
self
->
offset
);
self
->
index
,
self
->
size
,
src
->
b_ptr
+
self
->
offset
);
}
}
static
PyObject
*
static
PyObject
*
CField_get_offset
(
PyObject
*
self
,
void
*
data
)
Py
CField_get_offset
(
PyObject
*
self
,
void
*
data
)
{
{
return
PyInt_FromSsize_t
(((
CFieldObject
*
)
self
)
->
offset
);
return
PyInt_FromSsize_t
(((
CFieldObject
*
)
self
)
->
offset
);
}
}
static
PyObject
*
static
PyObject
*
CField_get_size
(
PyObject
*
self
,
void
*
data
)
Py
CField_get_size
(
PyObject
*
self
,
void
*
data
)
{
{
return
PyInt_FromSsize_t
(((
CFieldObject
*
)
self
)
->
size
);
return
PyInt_FromSsize_t
(((
CFieldObject
*
)
self
)
->
size
);
}
}
static
PyGetSetDef
CField_getset
[]
=
{
static
PyGetSetDef
Py
CField_getset
[]
=
{
{
"offset"
,
CField_get_offset
,
NULL
,
"offset in bytes of this field"
},
{
"offset"
,
Py
CField_get_offset
,
NULL
,
"offset in bytes of this field"
},
{
"size"
,
CField_get_size
,
NULL
,
"size in bytes of this field"
},
{
"size"
,
Py
CField_get_size
,
NULL
,
"size in bytes of this field"
},
{
NULL
,
NULL
,
NULL
,
NULL
},
{
NULL
,
NULL
,
NULL
,
NULL
},
};
};
static
int
static
int
CField_traverse
(
CFieldObject
*
self
,
visitproc
visit
,
void
*
arg
)
Py
CField_traverse
(
CFieldObject
*
self
,
visitproc
visit
,
void
*
arg
)
{
{
Py_VISIT
(
self
->
proto
);
Py_VISIT
(
self
->
proto
);
return
0
;
return
0
;
}
}
static
int
static
int
CField_clear
(
CFieldObject
*
self
)
Py
CField_clear
(
CFieldObject
*
self
)
{
{
Py_CLEAR
(
self
->
proto
);
Py_CLEAR
(
self
->
proto
);
return
0
;
return
0
;
}
}
static
void
static
void
CField_dealloc
(
PyObject
*
self
)
Py
CField_dealloc
(
PyObject
*
self
)
{
{
CField_clear
((
CFieldObject
*
)
self
);
Py
CField_clear
((
CFieldObject
*
)
self
);
self
->
ob_type
->
tp_free
((
PyObject
*
)
self
);
self
->
ob_type
->
tp_free
((
PyObject
*
)
self
);
}
}
static
PyObject
*
static
PyObject
*
CField_repr
(
CFieldObject
*
self
)
Py
CField_repr
(
CFieldObject
*
self
)
{
{
PyObject
*
result
;
PyObject
*
result
;
Py_ssize_t
bits
=
self
->
size
>>
16
;
Py_ssize_t
bits
=
self
->
size
>>
16
;
...
@@ -292,17 +292,17 @@ CField_repr(CFieldObject *self)
...
@@ -292,17 +292,17 @@ CField_repr(CFieldObject *self)
return
result
;
return
result
;
}
}
PyTypeObject
CField_Type
=
{
PyTypeObject
Py
CField_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"_ctypes.CField"
,
/* tp_name */
"_ctypes.CField"
,
/* tp_name */
sizeof
(
CFieldObject
),
/* tp_basicsize */
sizeof
(
CFieldObject
),
/* tp_basicsize */
0
,
/* tp_itemsize */
0
,
/* tp_itemsize */
CField_dealloc
,
/* tp_dealloc */
Py
CField_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
0
,
/* tp_compare */
0
,
/* tp_compare */
(
reprfunc
)
CField_repr
,
/* tp_repr */
(
reprfunc
)
Py
CField_repr
,
/* tp_repr */
0
,
/* tp_as_number */
0
,
/* tp_as_number */
0
,
/* tp_as_sequence */
0
,
/* tp_as_sequence */
0
,
/* tp_as_mapping */
0
,
/* tp_as_mapping */
...
@@ -314,23 +314,23 @@ PyTypeObject CField_Type = {
...
@@ -314,23 +314,23 @@ PyTypeObject CField_Type = {
0
,
/* tp_as_buffer */
0
,
/* tp_as_buffer */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
Py_TPFLAGS_DEFAULT
|
Py_TPFLAGS_HAVE_GC
,
/* tp_flags */
"Structure/Union member"
,
/* tp_doc */
"Structure/Union member"
,
/* tp_doc */
(
traverseproc
)
CField_traverse
,
/* tp_traverse */
(
traverseproc
)
Py
CField_traverse
,
/* tp_traverse */
(
inquiry
)
CField_clear
,
/* tp_clear */
(
inquiry
)
Py
CField_clear
,
/* tp_clear */
0
,
/* tp_richcompare */
0
,
/* tp_richcompare */
0
,
/* tp_weaklistoffset */
0
,
/* tp_weaklistoffset */
0
,
/* tp_iter */
0
,
/* tp_iter */
0
,
/* tp_iternext */
0
,
/* tp_iternext */
0
,
/* tp_methods */
0
,
/* tp_methods */
0
,
/* tp_members */
0
,
/* tp_members */
CField_getset
,
/* tp_getset */
Py
CField_getset
,
/* tp_getset */
0
,
/* tp_base */
0
,
/* tp_base */
0
,
/* tp_dict */
0
,
/* tp_dict */
(
descrgetfunc
)
CField_get
,
/* tp_descr_get */
(
descrgetfunc
)
Py
CField_get
,
/* tp_descr_get */
(
descrsetfunc
)
CField_set
,
/* tp_descr_set */
(
descrsetfunc
)
Py
CField_set
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
0
,
/* tp_init */
0
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
CField_new
,
/* tp_new */
Py
CField_new
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
};
};
...
@@ -1191,8 +1191,8 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
...
@@ -1191,8 +1191,8 @@ u_set(void *ptr, PyObject *value, Py_ssize_t size)
if
(
PyString_Check
(
value
))
{
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
NULL
;
return
NULL
;
}
else
if
(
!
PyUnicode_Check
(
value
))
{
}
else
if
(
!
PyUnicode_Check
(
value
))
{
...
@@ -1266,8 +1266,8 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
...
@@ -1266,8 +1266,8 @@ U_set(void *ptr, PyObject *value, Py_ssize_t length)
if
(
PyString_Check
(
value
))
{
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
NULL
;
return
NULL
;
}
else
if
(
!
PyUnicode_Check
(
value
))
{
}
else
if
(
!
PyUnicode_Check
(
value
))
{
...
@@ -1364,8 +1364,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
...
@@ -1364,8 +1364,8 @@ z_set(void *ptr, PyObject *value, Py_ssize_t size)
return
value
;
return
value
;
}
else
if
(
PyUnicode_Check
(
value
))
{
}
else
if
(
PyUnicode_Check
(
value
))
{
PyObject
*
str
=
PyUnicode_AsEncodedString
(
value
,
PyObject
*
str
=
PyUnicode_AsEncodedString
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
str
==
NULL
)
if
(
str
==
NULL
)
return
NULL
;
return
NULL
;
*
(
char
**
)
ptr
=
PyString_AS_STRING
(
str
);
*
(
char
**
)
ptr
=
PyString_AS_STRING
(
str
);
...
@@ -1415,8 +1415,8 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
...
@@ -1415,8 +1415,8 @@ Z_set(void *ptr, PyObject *value, Py_ssize_t size)
}
}
if
(
PyString_Check
(
value
))
{
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
NULL
;
return
NULL
;
}
else
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
}
else
if
(
PyInt_Check
(
value
)
||
PyLong_Check
(
value
))
{
...
@@ -1509,8 +1509,8 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
...
@@ -1509,8 +1509,8 @@ BSTR_set(void *ptr, PyObject *value, Py_ssize_t size)
value
=
NULL
;
value
=
NULL
;
}
else
if
(
PyString_Check
(
value
))
{
}
else
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
value
=
PyUnicode_FromEncodedObject
(
value
,
conversion_mode
_encoding
,
_ctypes_conversion
_encoding
,
conversion_mode
_errors
);
_ctypes_conversion
_errors
);
if
(
!
value
)
if
(
!
value
)
return
NULL
;
return
NULL
;
}
else
if
(
PyUnicode_Check
(
value
))
{
}
else
if
(
PyUnicode_Check
(
value
))
{
...
@@ -1670,7 +1670,7 @@ static struct fielddesc formattable[] = {
...
@@ -1670,7 +1670,7 @@ static struct fielddesc formattable[] = {
*/
*/
struct
fielddesc
*
struct
fielddesc
*
getentry
(
char
*
fmt
)
_ctypes_get_fielddesc
(
char
*
fmt
)
{
{
static
int
initialized
=
0
;
static
int
initialized
=
0
;
struct
fielddesc
*
table
=
formattable
;
struct
fielddesc
*
table
=
formattable
;
...
@@ -1679,11 +1679,11 @@ getentry(char *fmt)
...
@@ -1679,11 +1679,11 @@ getentry(char *fmt)
initialized
=
1
;
initialized
=
1
;
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
if
(
sizeof
(
wchar_t
)
==
sizeof
(
short
))
if
(
sizeof
(
wchar_t
)
==
sizeof
(
short
))
getentry
(
"u"
)
->
pffi_type
=
&
ffi_type_sshort
;
_ctypes_get_fielddesc
(
"u"
)
->
pffi_type
=
&
ffi_type_sshort
;
else
if
(
sizeof
(
wchar_t
)
==
sizeof
(
int
))
else
if
(
sizeof
(
wchar_t
)
==
sizeof
(
int
))
getentry
(
"u"
)
->
pffi_type
=
&
ffi_type_sint
;
_ctypes_get_fielddesc
(
"u"
)
->
pffi_type
=
&
ffi_type_sint
;
else
if
(
sizeof
(
wchar_t
)
==
sizeof
(
long
))
else
if
(
sizeof
(
wchar_t
)
==
sizeof
(
long
))
getentry
(
"u"
)
->
pffi_type
=
&
ffi_type_slong
;
_ctypes_get_fielddesc
(
"u"
)
->
pffi_type
=
&
ffi_type_slong
;
#endif
#endif
}
}
...
...
Modules/_ctypes/ctypes.h
View file @
5c6af808
...
@@ -59,7 +59,7 @@ this buffer is too small, PyMem_Malloc will be called to create a larger one,
...
@@ -59,7 +59,7 @@ this buffer is too small, PyMem_Malloc will be called to create a larger one,
and this one is not used.
and this one is not used.
Making CDataObject a variable size object would be a better solution, but more
Making CDataObject a variable size object would be a better solution, but more
difficult in the presence of CFuncPtrObject. Maybe later.
difficult in the presence of
Py
CFuncPtrObject. Maybe later.
*/
*/
union
value
{
union
value
{
char
c
[
16
];
char
c
[
16
];
...
@@ -105,8 +105,8 @@ typedef struct {
...
@@ -105,8 +105,8 @@ typedef struct {
ffi_type
*
ffi_restype
;
ffi_type
*
ffi_restype
;
ffi_type
*
atypes
[
1
];
ffi_type
*
atypes
[
1
];
}
CThunkObject
;
}
CThunkObject
;
extern
PyTypeObject
CThunk_Type
;
extern
PyTypeObject
Py
CThunk_Type
;
#define CThunk_CheckExact(v) ((v)->ob_type == &CThunk_Type)
#define CThunk_CheckExact(v) ((v)->ob_type == &
Py
CThunk_Type)
typedef
struct
{
typedef
struct
{
/* First part identical to tagCDataObject */
/* First part identical to tagCDataObject */
...
@@ -137,61 +137,61 @@ typedef struct {
...
@@ -137,61 +137,61 @@ typedef struct {
GUID
*
iid
;
GUID
*
iid
;
#endif
#endif
PyObject
*
paramflags
;
PyObject
*
paramflags
;
}
CFuncPtrObject
;
}
Py
CFuncPtrObject
;
extern
PyTypeObject
StgDict_Type
;
extern
PyTypeObject
PyC
StgDict_Type
;
#define
StgDict_CheckExact(v) ((v)->ob_type == &
StgDict_Type)
#define
PyCStgDict_CheckExact(v) ((v)->ob_type == &PyC
StgDict_Type)
#define
StgDict_Check(v) PyObject_TypeCheck(v, &
StgDict_Type)
#define
PyCStgDict_Check(v) PyObject_TypeCheck(v, &PyC
StgDict_Type)
extern
int
StructUnionType_update_stgdict
(
PyObject
*
fields
,
PyObject
*
type
,
int
isStruct
);
extern
int
PyC
StructUnionType_update_stgdict
(
PyObject
*
fields
,
PyObject
*
type
,
int
isStruct
);
extern
int
PyType_stginfo
(
PyTypeObject
*
self
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
plength
);
extern
int
PyType_stginfo
(
PyTypeObject
*
self
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
plength
);
extern
int
PyObject_stginfo
(
PyObject
*
self
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
plength
);
extern
int
PyObject_stginfo
(
PyObject
*
self
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
plength
);
extern
PyTypeObject
CData_Type
;
extern
PyTypeObject
Py
CData_Type
;
#define CDataObject_CheckExact(v) ((v)->ob_type == &CData_Type)
#define CDataObject_CheckExact(v) ((v)->ob_type == &
Py
CData_Type)
#define CDataObject_Check(v) PyObject_TypeCheck(v, &CData_Type)
#define CDataObject_Check(v) PyObject_TypeCheck(v, &
Py
CData_Type)
extern
PyTypeObject
SimpleType_Type
;
extern
PyTypeObject
PyC
SimpleType_Type
;
#define
SimpleTypeObject_CheckExact(v) ((v)->ob_type == &
SimpleType_Type)
#define
PyCSimpleTypeObject_CheckExact(v) ((v)->ob_type == &PyC
SimpleType_Type)
#define
SimpleTypeObject_Check(v) PyObject_TypeCheck(v, &
SimpleType_Type)
#define
PyCSimpleTypeObject_Check(v) PyObject_TypeCheck(v, &PyC
SimpleType_Type)
extern
PyTypeObject
CField_Type
;
extern
PyTypeObject
Py
CField_Type
;
extern
struct
fielddesc
*
getentry
(
char
*
fmt
);
extern
struct
fielddesc
*
_ctypes_get_fielddesc
(
char
*
fmt
);
extern
PyObject
*
extern
PyObject
*
CField_FromDesc
(
PyObject
*
desc
,
Py_ssize_t
index
,
Py
CField_FromDesc
(
PyObject
*
desc
,
Py_ssize_t
index
,
Py_ssize_t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
Py_ssize_t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
poffset
,
Py_ssize_t
*
palign
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
poffset
,
Py_ssize_t
*
palign
,
int
pack
,
int
is_big_endian
);
int
pack
,
int
is_big_endian
);
extern
PyObject
*
CData_AtAddress
(
PyObject
*
type
,
void
*
buf
);
extern
PyObject
*
Py
CData_AtAddress
(
PyObject
*
type
,
void
*
buf
);
extern
PyObject
*
CData_FromBytes
(
PyObject
*
type
,
char
*
data
,
Py_ssize_t
length
);
extern
PyObject
*
Py
CData_FromBytes
(
PyObject
*
type
,
char
*
data
,
Py_ssize_t
length
);
extern
PyTypeObject
ArrayType_Type
;
extern
PyTypeObject
PyC
ArrayType_Type
;
extern
PyTypeObject
Array_Type
;
extern
PyTypeObject
PyC
Array_Type
;
extern
PyTypeObject
PointerType_Type
;
extern
PyTypeObject
P
yCP
ointerType_Type
;
extern
PyTypeObject
Pointer_Type
;
extern
PyTypeObject
P
yCP
ointer_Type
;
extern
PyTypeObject
CFuncPtr_Type
;
extern
PyTypeObject
Py
CFuncPtr_Type
;
extern
PyTypeObject
CFuncPtrType_Type
;
extern
PyTypeObject
Py
CFuncPtrType_Type
;
extern
PyTypeObject
StructType_Type
;
extern
PyTypeObject
PyC
StructType_Type
;
#define
ArrayTypeObject_Check(v) PyObject_TypeCheck(v, &
ArrayType_Type)
#define
PyCArrayTypeObject_Check(v) PyObject_TypeCheck(v, &PyC
ArrayType_Type)
#define ArrayObject_Check(v) PyObject_TypeCheck(v, &Array_Type)
#define ArrayObject_Check(v) PyObject_TypeCheck(v, &
PyC
Array_Type)
#define PointerObject_Check(v) PyObject_TypeCheck(v, &Pointer_Type)
#define PointerObject_Check(v) PyObject_TypeCheck(v, &P
yCP
ointer_Type)
#define P
ointerTypeObject_Check(v) PyObject_TypeCheck(v, &
PointerType_Type)
#define P
yCPointerTypeObject_Check(v) PyObject_TypeCheck(v, &PyC
PointerType_Type)
#define
CFuncPtrObject_Check(v) PyObject_TypeCheck(v, &
CFuncPtr_Type)
#define
PyCFuncPtrObject_Check(v) PyObject_TypeCheck(v, &Py
CFuncPtr_Type)
#define
CFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &
CFuncPtrType_Type)
#define
PyCFuncPtrTypeObject_Check(v) PyObject_TypeCheck(v, &Py
CFuncPtrType_Type)
#define
StructTypeObject_Check(v) PyObject_TypeCheck(v, &
StructType_Type)
#define
PyCStructTypeObject_Check(v) PyObject_TypeCheck(v, &PyC
StructType_Type)
extern
PyObject
*
extern
PyObject
*
CreateArrayT
ype
(
PyObject
*
itemtype
,
Py_ssize_t
length
);
PyCArrayType_from_ct
ype
(
PyObject
*
itemtype
,
Py_ssize_t
length
);
extern
PyMethodDef
module_methods
[];
extern
PyMethodDef
_ctypes_
module_methods
[];
extern
CThunkObject
*
AllocFunctionC
allback
(
PyObject
*
callable
,
extern
CThunkObject
*
_ctypes_alloc_c
allback
(
PyObject
*
callable
,
PyObject
*
converters
,
PyObject
*
converters
,
PyObject
*
restype
,
PyObject
*
restype
,
int
flags
);
int
flags
);
...
@@ -223,7 +223,7 @@ typedef struct {
...
@@ -223,7 +223,7 @@ typedef struct {
PyDictObject
dict
;
/* first part identical to PyDictObject */
PyDictObject
dict
;
/* first part identical to PyDictObject */
/* The size and align fields are unneeded, they are in ffi_type as well. As
/* The size and align fields are unneeded, they are in ffi_type as well. As
an experiment shows, it's trivial to get rid of them, the only thing to
an experiment shows, it's trivial to get rid of them, the only thing to
remember is that in ArrayType_new the ffi_type fields must be filled in -
remember is that in
PyC
ArrayType_new the ffi_type fields must be filled in -
so far it was unneeded because libffi doesn't support arrays at all
so far it was unneeded because libffi doesn't support arrays at all
(because they are passed as pointers to function calls anyway). But it's
(because they are passed as pointers to function calls anyway). But it's
too much risk to change that now, and there are other fields which doen't
too much risk to change that now, and there are other fields which doen't
...
@@ -238,7 +238,7 @@ typedef struct {
...
@@ -238,7 +238,7 @@ typedef struct {
GETFUNC
getfunc
;
/* Only for simple objects */
GETFUNC
getfunc
;
/* Only for simple objects */
PARAMFUNC
paramfunc
;
PARAMFUNC
paramfunc
;
/* Following fields only used by CFuncPtrType_Type instances */
/* Following fields only used by
Py
CFuncPtrType_Type instances */
PyObject
*
argtypes
;
/* tuple of CDataObjects */
PyObject
*
argtypes
;
/* tuple of CDataObjects */
PyObject
*
converters
;
/* tuple([t.from_param for t in argtypes]) */
PyObject
*
converters
;
/* tuple([t.from_param for t in argtypes]) */
PyObject
*
restype
;
/* CDataObject or NULL */
PyObject
*
restype
;
/* CDataObject or NULL */
...
@@ -272,7 +272,7 @@ typedef struct {
...
@@ -272,7 +272,7 @@ typedef struct {
construction time, or assigns to it later, tp_setattro should update the
construction time, or assigns to it later, tp_setattro should update the
StgDictObject function to a generic one.
StgDictObject function to a generic one.
Currently, CFuncPtr types have 'converters' and 'checker' entries in their
Currently,
Py
CFuncPtr types have 'converters' and 'checker' entries in their
type dict. They are only used to cache attributes from other entries, whihc
type dict. They are only used to cache attributes from other entries, whihc
is wrong.
is wrong.
...
@@ -300,11 +300,11 @@ extern StgDictObject *PyType_stgdict(PyObject *obj);
...
@@ -300,11 +300,11 @@ extern StgDictObject *PyType_stgdict(PyObject *obj);
/* May return NULL, but does not set an exception! */
/* May return NULL, but does not set an exception! */
extern
StgDictObject
*
PyObject_stgdict
(
PyObject
*
self
);
extern
StgDictObject
*
PyObject_stgdict
(
PyObject
*
self
);
extern
int
StgDict_clone
(
StgDictObject
*
src
,
StgDictObject
*
dst
);
extern
int
PyC
StgDict_clone
(
StgDictObject
*
src
,
StgDictObject
*
dst
);
typedef
int
(
*
PPROC
)(
void
);
typedef
int
(
*
PPROC
)(
void
);
PyObject
*
_
CallP
roc
(
PPROC
pProc
,
PyObject
*
_
ctypes_callp
roc
(
PPROC
pProc
,
PyObject
*
arguments
,
PyObject
*
arguments
,
#ifdef MS_WIN32
#ifdef MS_WIN32
IUnknown
*
pIUnk
,
IUnknown
*
pIUnk
,
...
@@ -352,17 +352,17 @@ struct tagPyCArgObject {
...
@@ -352,17 +352,17 @@ struct tagPyCArgObject {
extern
PyTypeObject
PyCArg_Type
;
extern
PyTypeObject
PyCArg_Type
;
#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type)
#define PyCArg_CheckExact(v) ((v)->ob_type == &PyCArg_Type)
extern
PyCArgObject
*
new_CArgObject
(
void
);
extern
PyCArgObject
*
PyCArgObject_new
(
void
);
extern
PyObject
*
extern
PyObject
*
CData_get
(
PyObject
*
type
,
GETFUNC
getfunc
,
PyObject
*
src
,
Py
CData_get
(
PyObject
*
type
,
GETFUNC
getfunc
,
PyObject
*
src
,
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
);
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
);
extern
int
extern
int
CData_set
(
PyObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
Py
CData_set
(
PyObject
*
dst
,
PyObject
*
type
,
SETFUNC
setfunc
,
PyObject
*
value
,
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
);
Py_ssize_t
index
,
Py_ssize_t
size
,
char
*
ptr
);
extern
void
Extend_Error_Info
(
PyObject
*
exc_class
,
char
*
fmt
,
...);
extern
void
_ctypes_extend_error
(
PyObject
*
exc_class
,
char
*
fmt
,
...);
struct
basespec
{
struct
basespec
{
CDataObject
*
base
;
CDataObject
*
base
;
...
@@ -372,13 +372,13 @@ struct basespec {
...
@@ -372,13 +372,13 @@ struct basespec {
extern
char
basespec_string
[];
extern
char
basespec_string
[];
extern
ffi_type
*
GetT
ype
(
PyObject
*
obj
);
extern
ffi_type
*
_ctypes_get_ffi_t
ype
(
PyObject
*
obj
);
/* exception classes */
/* exception classes */
extern
PyObject
*
PyExc_ArgError
;
extern
PyObject
*
PyExc_ArgError
;
extern
char
*
conversion_mode
_encoding
;
extern
char
*
_ctypes_conversion
_encoding
;
extern
char
*
conversion_mode
_errors
;
extern
char
*
_ctypes_conversion
_errors
;
/* Python 2.4 macros, which are not available in Python 2.3 */
/* Python 2.4 macros, which are not available in Python 2.3 */
...
@@ -415,31 +415,31 @@ extern char *conversion_mode_errors;
...
@@ -415,31 +415,31 @@ extern char *conversion_mode_errors;
#endif
#endif
#if (PY_VERSION_HEX < 0x02040000)
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
# undef PyUnicode_FromWideChar
# undef PyUnicode_FromWideChar
# define PyUnicode_FromWideChar
My_PyUnicode_FromWideChar
# define PyUnicode_FromWideChar
PyUnicode_FromWideChar_fixed
# undef PyUnicode_AsWideChar
# undef PyUnicode_AsWideChar
# define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
# define PyUnicode_AsWideChar PyUnicode_AsWideChar_fixed
extern
PyObject
*
My_PyUnicode_FromWideChar
(
const
wchar_t
*
,
Py_ssize_t
);
extern
Py_ssize_t
My_PyUnicode_AsWideChar
(
PyUnicodeObject
*
,
wchar_t
*
,
Py_ssize_t
);
extern
PyObject
*
PyUnicode_FromWideChar_fixed
(
const
wchar_t
*
,
Py_ssize_t
);
extern
Py_ssize_t
PyUnicode_AsWideChar_fixed
(
PyUnicodeObject
*
,
wchar_t
*
,
Py_ssize_t
);
#endif
#endif
#endif
extern
void
FreeC
losure
(
void
*
);
extern
void
_ctypes_free_c
losure
(
void
*
);
extern
void
*
MallocC
losure
(
void
);
extern
void
*
_ctypes_alloc_c
losure
(
void
);
extern
void
_
AddT
raceback
(
char
*
,
char
*
,
int
);
extern
void
_
ctypes_add_t
raceback
(
char
*
,
char
*
,
int
);
extern
PyObject
*
CData_FromBaseObj
(
PyObject
*
type
,
PyObject
*
base
,
Py_ssize_t
index
,
char
*
adr
);
extern
PyObject
*
Py
CData_FromBaseObj
(
PyObject
*
type
,
PyObject
*
base
,
Py_ssize_t
index
,
char
*
adr
);
extern
char
*
alloc_format_string
(
const
char
*
prefix
,
const
char
*
suffix
);
extern
char
*
_ctypes_
alloc_format_string
(
const
char
*
prefix
,
const
char
*
suffix
);
/* XXX better name needed! */
extern
int
_ctypes_simple_instance
(
PyObject
*
obj
);
extern
int
IsSimpleSubType
(
PyObject
*
obj
);
extern
PyObject
*
_
pointer_
type_cache
;
extern
PyObject
*
_
ctypes_ptr
type_cache
;
PyObject
*
get_error_object
(
int
**
pspace
);
PyObject
*
_ctypes_get_errobj
(
int
**
pspace
);
#ifdef MS_WIN32
#ifdef MS_WIN32
extern
PyObject
*
ComError
;
extern
PyObject
*
ComError
;
...
...
Modules/_ctypes/malloc_closure.c
View file @
5c6af808
...
@@ -93,7 +93,7 @@ static void more_core(void)
...
@@ -93,7 +93,7 @@ static void more_core(void)
/******************************************************************/
/******************************************************************/
/* put the item back into the free list */
/* put the item back into the free list */
void
FreeC
losure
(
void
*
p
)
void
_ctypes_free_c
losure
(
void
*
p
)
{
{
ITEM
*
item
=
(
ITEM
*
)
p
;
ITEM
*
item
=
(
ITEM
*
)
p
;
item
->
next
=
free_list
;
item
->
next
=
free_list
;
...
@@ -101,7 +101,7 @@ void FreeClosure(void *p)
...
@@ -101,7 +101,7 @@ void FreeClosure(void *p)
}
}
/* return one item from the free list, allocating more if needed */
/* return one item from the free list, allocating more if needed */
void
*
MallocC
losure
(
void
)
void
*
_ctypes_alloc_c
losure
(
void
)
{
{
ITEM
*
item
;
ITEM
*
item
;
if
(
!
free_list
)
if
(
!
free_list
)
...
...
Modules/_ctypes/stgdict.c
View file @
5c6af808
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
* PyDict_SetItem() (ma_lookup is NULL)
* PyDict_SetItem() (ma_lookup is NULL)
*/
*/
static
int
static
int
StgDict_init
(
StgDictObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
PyC
StgDict_init
(
StgDictObject
*
self
,
PyObject
*
args
,
PyObject
*
kwds
)
{
{
if
(
PyDict_Type
.
tp_init
((
PyObject
*
)
self
,
args
,
kwds
)
<
0
)
if
(
PyDict_Type
.
tp_init
((
PyObject
*
)
self
,
args
,
kwds
)
<
0
)
return
-
1
;
return
-
1
;
...
@@ -32,7 +32,7 @@ StgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds)
...
@@ -32,7 +32,7 @@ StgDict_init(StgDictObject *self, PyObject *args, PyObject *kwds)
}
}
static
int
static
int
StgDict_clear
(
StgDictObject
*
self
)
PyC
StgDict_clear
(
StgDictObject
*
self
)
{
{
Py_CLEAR
(
self
->
proto
);
Py_CLEAR
(
self
->
proto
);
Py_CLEAR
(
self
->
argtypes
);
Py_CLEAR
(
self
->
argtypes
);
...
@@ -43,9 +43,9 @@ StgDict_clear(StgDictObject *self)
...
@@ -43,9 +43,9 @@ StgDict_clear(StgDictObject *self)
}
}
static
void
static
void
StgDict_dealloc
(
StgDictObject
*
self
)
PyC
StgDict_dealloc
(
StgDictObject
*
self
)
{
{
StgDict_clear
(
self
);
PyC
StgDict_clear
(
self
);
PyMem_Free
(
self
->
format
);
PyMem_Free
(
self
->
format
);
PyMem_Free
(
self
->
shape
);
PyMem_Free
(
self
->
shape
);
PyMem_Free
(
self
->
ffi_type_pointer
.
elements
);
PyMem_Free
(
self
->
ffi_type_pointer
.
elements
);
...
@@ -53,12 +53,12 @@ StgDict_dealloc(StgDictObject *self)
...
@@ -53,12 +53,12 @@ StgDict_dealloc(StgDictObject *self)
}
}
int
int
StgDict_clone
(
StgDictObject
*
dst
,
StgDictObject
*
src
)
PyC
StgDict_clone
(
StgDictObject
*
dst
,
StgDictObject
*
src
)
{
{
char
*
d
,
*
s
;
char
*
d
,
*
s
;
Py_ssize_t
size
;
Py_ssize_t
size
;
StgDict_clear
(
dst
);
PyC
StgDict_clear
(
dst
);
PyMem_Free
(
dst
->
ffi_type_pointer
.
elements
);
PyMem_Free
(
dst
->
ffi_type_pointer
.
elements
);
PyMem_Free
(
dst
->
format
);
PyMem_Free
(
dst
->
format
);
dst
->
format
=
NULL
;
dst
->
format
=
NULL
;
...
@@ -106,12 +106,12 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src)
...
@@ -106,12 +106,12 @@ StgDict_clone(StgDictObject *dst, StgDictObject *src)
return
0
;
return
0
;
}
}
PyTypeObject
StgDict_Type
=
{
PyTypeObject
PyC
StgDict_Type
=
{
PyVarObject_HEAD_INIT
(
NULL
,
0
)
PyVarObject_HEAD_INIT
(
NULL
,
0
)
"StgDict"
,
"StgDict"
,
sizeof
(
StgDictObject
),
sizeof
(
StgDictObject
),
0
,
0
,
(
destructor
)
StgDict_dealloc
,
/* tp_dealloc */
(
destructor
)
PyC
StgDict_dealloc
,
/* tp_dealloc */
0
,
/* tp_print */
0
,
/* tp_print */
0
,
/* tp_getattr */
0
,
/* tp_getattr */
0
,
/* tp_setattr */
0
,
/* tp_setattr */
...
@@ -142,7 +142,7 @@ PyTypeObject StgDict_Type = {
...
@@ -142,7 +142,7 @@ PyTypeObject StgDict_Type = {
0
,
/* tp_descr_get */
0
,
/* tp_descr_get */
0
,
/* tp_descr_set */
0
,
/* tp_descr_set */
0
,
/* tp_dictoffset */
0
,
/* tp_dictoffset */
(
initproc
)
StgDict_init
,
/* tp_init */
(
initproc
)
PyC
StgDict_init
,
/* tp_init */
0
,
/* tp_alloc */
0
,
/* tp_alloc */
0
,
/* tp_new */
0
,
/* tp_new */
0
,
/* tp_free */
0
,
/* tp_free */
...
@@ -159,7 +159,7 @@ PyType_stgdict(PyObject *obj)
...
@@ -159,7 +159,7 @@ PyType_stgdict(PyObject *obj)
type
=
(
PyTypeObject
*
)
obj
;
type
=
(
PyTypeObject
*
)
obj
;
if
(
!
PyType_HasFeature
(
type
,
Py_TPFLAGS_HAVE_CLASS
))
if
(
!
PyType_HasFeature
(
type
,
Py_TPFLAGS_HAVE_CLASS
))
return
NULL
;
return
NULL
;
if
(
!
type
->
tp_dict
||
!
StgDict_CheckExact
(
type
->
tp_dict
))
if
(
!
type
->
tp_dict
||
!
PyC
StgDict_CheckExact
(
type
->
tp_dict
))
return
NULL
;
return
NULL
;
return
(
StgDictObject
*
)
type
->
tp_dict
;
return
(
StgDictObject
*
)
type
->
tp_dict
;
}
}
...
@@ -175,7 +175,7 @@ PyObject_stgdict(PyObject *self)
...
@@ -175,7 +175,7 @@ PyObject_stgdict(PyObject *self)
PyTypeObject
*
type
=
self
->
ob_type
;
PyTypeObject
*
type
=
self
->
ob_type
;
if
(
!
PyType_HasFeature
(
type
,
Py_TPFLAGS_HAVE_CLASS
))
if
(
!
PyType_HasFeature
(
type
,
Py_TPFLAGS_HAVE_CLASS
))
return
NULL
;
return
NULL
;
if
(
!
type
->
tp_dict
||
!
StgDict_CheckExact
(
type
->
tp_dict
))
if
(
!
type
->
tp_dict
||
!
PyC
StgDict_CheckExact
(
type
->
tp_dict
))
return
NULL
;
return
NULL
;
return
(
StgDictObject
*
)
type
->
tp_dict
;
return
(
StgDictObject
*
)
type
->
tp_dict
;
}
}
...
@@ -215,7 +215,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
...
@@ -215,7 +215,7 @@ MakeFields(PyObject *type, CFieldObject *descr,
Py_DECREF
(
fieldlist
);
Py_DECREF
(
fieldlist
);
return
-
1
;
return
-
1
;
}
}
if
(
Py_TYPE
(
fdescr
)
!=
&
CField_Type
)
{
if
(
Py_TYPE
(
fdescr
)
!=
&
Py
CField_Type
)
{
PyErr_SetString
(
PyExc_TypeError
,
"unexpected type"
);
PyErr_SetString
(
PyExc_TypeError
,
"unexpected type"
);
Py_DECREF
(
fdescr
);
Py_DECREF
(
fdescr
);
Py_DECREF
(
fieldlist
);
Py_DECREF
(
fieldlist
);
...
@@ -232,13 +232,13 @@ MakeFields(PyObject *type, CFieldObject *descr,
...
@@ -232,13 +232,13 @@ MakeFields(PyObject *type, CFieldObject *descr,
}
}
continue
;
continue
;
}
}
new_descr
=
(
CFieldObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
CField_Type
,
NULL
);
new_descr
=
(
CFieldObject
*
)
PyObject_CallObject
((
PyObject
*
)
&
Py
CField_Type
,
NULL
);
if
(
new_descr
==
NULL
)
{
if
(
new_descr
==
NULL
)
{
Py_DECREF
(
fdescr
);
Py_DECREF
(
fdescr
);
Py_DECREF
(
fieldlist
);
Py_DECREF
(
fieldlist
);
return
-
1
;
return
-
1
;
}
}
assert
(
Py_TYPE
(
new_descr
)
==
&
CField_Type
);
assert
(
Py_TYPE
(
new_descr
)
==
&
Py
CField_Type
);
new_descr
->
size
=
fdescr
->
size
;
new_descr
->
size
=
fdescr
->
size
;
new_descr
->
offset
=
fdescr
->
offset
+
offset
;
new_descr
->
offset
=
fdescr
->
offset
+
offset
;
new_descr
->
index
=
fdescr
->
index
+
index
;
new_descr
->
index
=
fdescr
->
index
+
index
;
...
@@ -286,7 +286,7 @@ MakeAnonFields(PyObject *type)
...
@@ -286,7 +286,7 @@ MakeAnonFields(PyObject *type)
Py_DECREF
(
anon_names
);
Py_DECREF
(
anon_names
);
return
-
1
;
return
-
1
;
}
}
assert
(
Py_TYPE
(
descr
)
==
&
CField_Type
);
assert
(
Py_TYPE
(
descr
)
==
&
Py
CField_Type
);
descr
->
anonymous
=
1
;
descr
->
anonymous
=
1
;
/* descr is in the field descriptor. */
/* descr is in the field descriptor. */
...
@@ -309,7 +309,7 @@ MakeAnonFields(PyObject *type)
...
@@ -309,7 +309,7 @@ MakeAnonFields(PyObject *type)
and create an StgDictObject. Used for Structure and Union subclasses.
and create an StgDictObject. Used for Structure and Union subclasses.
*/
*/
int
int
StructUnionType_update_stgdict
(
PyObject
*
type
,
PyObject
*
fields
,
int
isStruct
)
PyC
StructUnionType_update_stgdict
(
PyObject
*
type
,
PyObject
*
fields
,
int
isStruct
)
{
{
StgDictObject
*
stgdict
,
*
basedict
;
StgDictObject
*
stgdict
,
*
basedict
;
Py_ssize_t
len
,
offset
,
size
,
align
,
i
;
Py_ssize_t
len
,
offset
,
size
,
align
,
i
;
...
@@ -418,12 +418,12 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -418,12 +418,12 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
assert
(
stgdict
->
format
==
NULL
);
assert
(
stgdict
->
format
==
NULL
);
if
(
isStruct
&&
!
isPacked
)
{
if
(
isStruct
&&
!
isPacked
)
{
stgdict
->
format
=
alloc_format_string
(
NULL
,
"T{"
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
NULL
,
"T{"
);
}
else
{
}
else
{
/* PEP3118 doesn't support union, or packed structures (well,
/* PEP3118 doesn't support union, or packed structures (well,
only standard packing, but we dont support the pep for
only standard packing, but we dont support the pep for
that). Use 'B' for bytes. */
that). Use 'B' for bytes. */
stgdict
->
format
=
alloc_format_string
(
NULL
,
"B"
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
NULL
,
"B"
);
}
}
#define realdict ((PyObject *)&stgdict->dict)
#define realdict ((PyObject *)&stgdict->dict)
...
@@ -468,9 +468,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -468,9 +468,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
case
FFI_TYPE_SINT8
:
case
FFI_TYPE_SINT8
:
case
FFI_TYPE_SINT16
:
case
FFI_TYPE_SINT16
:
case
FFI_TYPE_SINT32
:
case
FFI_TYPE_SINT32
:
if
(
dict
->
getfunc
!=
getentry
(
"c"
)
->
getfunc
if
(
dict
->
getfunc
!=
_ctypes_get_fielddesc
(
"c"
)
->
getfunc
#ifdef CTYPES_UNICODE
#ifdef CTYPES_UNICODE
&&
dict
->
getfunc
!=
getentry
(
"u"
)
->
getfunc
&&
dict
->
getfunc
!=
_ctypes_get_fielddesc
(
"u"
)
->
getfunc
#endif
#endif
)
)
break
;
break
;
...
@@ -500,7 +500,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -500,7 +500,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
sprintf
(
buf
,
"%s:%s:"
,
fieldfmt
,
fieldname
);
sprintf
(
buf
,
"%s:%s:"
,
fieldfmt
,
fieldname
);
ptr
=
stgdict
->
format
;
ptr
=
stgdict
->
format
;
stgdict
->
format
=
alloc_format_string
(
stgdict
->
format
,
buf
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
stgdict
->
format
,
buf
);
PyMem_Free
(
ptr
);
PyMem_Free
(
ptr
);
if
(
stgdict
->
format
==
NULL
)
{
if
(
stgdict
->
format
==
NULL
)
{
...
@@ -509,7 +509,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -509,7 +509,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
}
}
}
}
if
(
isStruct
)
{
if
(
isStruct
)
{
prop
=
CField_FromDesc
(
desc
,
i
,
prop
=
Py
CField_FromDesc
(
desc
,
i
,
&
field_size
,
bitsize
,
&
bitofs
,
&
field_size
,
bitsize
,
&
bitofs
,
&
size
,
&
offset
,
&
align
,
&
size
,
&
offset
,
&
align
,
pack
,
big_endian
);
pack
,
big_endian
);
...
@@ -517,7 +517,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -517,7 +517,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
size
=
0
;
size
=
0
;
offset
=
0
;
offset
=
0
;
align
=
0
;
align
=
0
;
prop
=
CField_FromDesc
(
desc
,
i
,
prop
=
Py
CField_FromDesc
(
desc
,
i
,
&
field_size
,
bitsize
,
&
bitofs
,
&
field_size
,
bitsize
,
&
bitofs
,
&
size
,
&
offset
,
&
align
,
&
size
,
&
offset
,
&
align
,
pack
,
big_endian
);
pack
,
big_endian
);
...
@@ -541,7 +541,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
...
@@ -541,7 +541,7 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
if
(
isStruct
&&
!
isPacked
)
{
if
(
isStruct
&&
!
isPacked
)
{
char
*
ptr
=
stgdict
->
format
;
char
*
ptr
=
stgdict
->
format
;
stgdict
->
format
=
alloc_format_string
(
stgdict
->
format
,
"}"
);
stgdict
->
format
=
_ctypes_
alloc_format_string
(
stgdict
->
format
,
"}"
);
PyMem_Free
(
ptr
);
PyMem_Free
(
ptr
);
if
(
stgdict
->
format
==
NULL
)
if
(
stgdict
->
format
==
NULL
)
return
-
1
;
return
-
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment