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
e81c9f6d
Commit
e81c9f6d
authored
Jun 08, 2007
by
Thomas Heller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[ 1715718 ] x64 clean compile patch for _ctypes, by Kristj?n Valur
with small modifications.
parent
da587ab4
Changes
6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
158 additions
and
142 deletions
+158
-142
Modules/_ctypes/_ctypes.c
Modules/_ctypes/_ctypes.c
+35
-34
Modules/_ctypes/callbacks.c
Modules/_ctypes/callbacks.c
+5
-4
Modules/_ctypes/callproc.c
Modules/_ctypes/callproc.c
+16
-12
Modules/_ctypes/cfield.c
Modules/_ctypes/cfield.c
+86
-79
Modules/_ctypes/ctypes.h
Modules/_ctypes/ctypes.h
+8
-7
Modules/_ctypes/stgdict.c
Modules/_ctypes/stgdict.c
+8
-6
No files found.
Modules/_ctypes/_ctypes.c
View file @
e81c9f6d
...
...
@@ -789,7 +789,7 @@ static int
CharArray_set_value
(
CDataObject
*
self
,
PyObject
*
value
)
{
char
*
ptr
;
in
t
size
;
Py_ssize_
t
size
;
if
(
PyUnicode_Check
(
value
))
{
value
=
PyUnicode_AsEncodedString
(
value
,
...
...
@@ -844,7 +844,7 @@ WCharArray_get_value(CDataObject *self)
static
int
WCharArray_set_value
(
CDataObject
*
self
,
PyObject
*
value
)
{
in
t
result
=
0
;
Py_ssize_
t
result
=
0
;
if
(
PyString_Check
(
value
))
{
value
=
PyUnicode_FromEncodedObject
(
value
,
...
...
@@ -868,14 +868,12 @@ WCharArray_set_value(CDataObject *self, PyObject *value)
result
=
PyUnicode_AsWideChar
((
PyUnicodeObject
*
)
value
,
(
wchar_t
*
)
self
->
b_ptr
,
self
->
b_size
/
sizeof
(
wchar_t
));
if
(
result
>=
0
&&
(
unsigned
)
result
<
self
->
b_size
/
sizeof
(
wchar_t
))
if
(
result
>=
0
&&
(
size_t
)
result
<
self
->
b_size
/
sizeof
(
wchar_t
))
((
wchar_t
*
)
self
->
b_ptr
)[
result
]
=
(
wchar_t
)
0
;
if
(
result
>
0
)
result
=
0
;
done:
Py_DECREF
(
value
);
return
result
;
return
result
>=
0
?
0
:
-
1
;
}
static
PyGetSetDef
WCharArray_getsets
[]
=
{
...
...
@@ -966,7 +964,7 @@ ArrayType_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
PyObject
*
typedict
;
int
length
;
in
t
itemsize
,
itemalign
;
Py_ssize_
t
itemsize
,
itemalign
;
typedict
=
PyTuple_GetItem
(
args
,
2
);
if
(
!
typedict
)
...
...
@@ -1737,8 +1735,8 @@ static PyObject *
converters_from_argtypes
(
PyObject
*
ob
)
{
PyObject
*
converters
;
in
t
i
;
in
t
nArgs
;
Py_ssize_
t
i
;
Py_ssize_
t
nArgs
;
ob
=
PySequence_Tuple
(
ob
);
/* new reference */
if
(
!
ob
)
{
...
...
@@ -2591,18 +2589,18 @@ static PyGetSetDef CFuncPtr_getsets[] = {
#ifdef MS_WIN32
static
PPROC
FindAddress
(
void
*
handle
,
char
*
name
,
PyObject
*
type
)
{
#ifdef MS_WIN64
/* win64 has no stdcall calling conv, so it should
also not have the name mangling of it.
*/
return
(
PPROC
)
GetProcAddress
(
handle
,
name
);
#else
PPROC
address
;
char
*
mangled_name
;
int
i
;
StgDictObject
*
dict
;
address
=
(
PPROC
)
GetProcAddress
(
handle
,
name
);
#ifdef _WIN64
/* win64 has no stdcall calling conv, so it should
also not have the name mangling of it.
*/
return
address
;
#else
if
(
address
)
return
address
;
if
(((
size_t
)
name
&
~
0xFFFF
)
==
0
)
{
...
...
@@ -2634,7 +2632,7 @@ static PPROC FindAddress(void *handle, char *name, PyObject *type)
/* Return 1 if usable, 0 else and exception set. */
static
int
_check_outarg_type
(
PyObject
*
arg
,
in
t
index
)
_check_outarg_type
(
PyObject
*
arg
,
Py_ssize_
t
index
)
{
StgDictObject
*
dict
;
...
...
@@ -2655,7 +2653,7 @@ _check_outarg_type(PyObject *arg, int index)
PyErr_Format
(
PyExc_TypeError
,
"'out' parameter %d must be a pointer type, not %s"
,
index
,
Py_SAFE_DOWNCAST
(
index
,
Py_ssize_t
,
int
)
,
PyType_Check
(
arg
)
?
((
PyTypeObject
*
)
arg
)
->
tp_name
:
arg
->
ob_type
->
tp_name
);
...
...
@@ -2666,7 +2664,7 @@ _check_outarg_type(PyObject *arg, int index)
static
int
_validate_paramflags
(
PyTypeObject
*
type
,
PyObject
*
paramflags
)
{
in
t
i
,
len
;
Py_ssize_
t
i
,
len
;
StgDictObject
*
dict
;
PyObject
*
argtypes
;
...
...
@@ -3051,12 +3049,12 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
PyObject
*
paramflags
=
self
->
paramflags
;
PyObject
*
callargs
;
StgDictObject
*
dict
;
in
t
i
,
len
;
Py_ssize_
t
i
,
len
;
int
inargs_index
=
0
;
/* It's a little bit difficult to determine how many arguments the
function call requires/accepts. For simplicity, we count the consumed
args and compare this to the number of supplied args. */
in
t
actual_args
;
Py_ssize_
t
actual_args
;
*
poutmask
=
0
;
*
pinoutmask
=
0
;
...
...
@@ -3093,7 +3091,7 @@ _build_callargs(CFuncPtrObject *self, PyObject *argtypes,
/* This way seems to be ~2 us faster than the PyArg_ParseTuple
calls below. */
/* We HAVE already checked that the tuple can be parsed with "i|zO", so... */
in
t
tsize
=
PyTuple_GET_SIZE
(
item
);
Py_ssize_
t
tsize
=
PyTuple_GET_SIZE
(
item
);
flag
=
PyInt_AS_LONG
(
PyTuple_GET_ITEM
(
item
,
0
));
name
=
tsize
>
1
?
PyString_AS_STRING
(
PyTuple_GET_ITEM
(
item
,
1
))
:
NULL
;
defval
=
tsize
>
2
?
PyTuple_GET_ITEM
(
item
,
2
)
:
NULL
;
...
...
@@ -3339,8 +3337,10 @@ CFuncPtr_call(CFuncPtrObject *self, PyObject *inargs, PyObject *kwds)
return
NULL
;
if
(
converters
)
{
int
required
=
PyTuple_GET_SIZE
(
converters
);
int
actual
=
PyTuple_GET_SIZE
(
callargs
);
int
required
=
Py_SAFE_DOWNCAST
(
PyTuple_GET_SIZE
(
converters
),
Py_ssize_t
,
int
);
int
actual
=
Py_SAFE_DOWNCAST
(
PyTuple_GET_SIZE
(
callargs
),
Py_ssize_t
,
int
);
if
((
dict
->
flags
&
FUNCFLAG_CDECL
)
==
FUNCFLAG_CDECL
)
{
/* For cdecl functions, we allow more actual arguments
...
...
@@ -3679,8 +3679,8 @@ static PyTypeObject Union_Type = {
static
int
Array_init
(
CDataObject
*
self
,
PyObject
*
args
,
PyObject
*
kw
)
{
in
t
i
;
in
t
n
;
Py_ssize_
t
i
;
Py_ssize_
t
n
;
if
(
!
PyTuple_Check
(
args
))
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
@@ -3701,7 +3701,7 @@ static PyObject *
Array_item
(
PyObject
*
_self
,
Py_ssize_t
index
)
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
in
t
offset
,
size
;
Py_ssize_
t
offset
,
size
;
StgDictObject
*
stgdict
;
...
...
@@ -3773,7 +3773,7 @@ static int
Array_ass_item
(
PyObject
*
_self
,
Py_ssize_t
index
,
PyObject
*
value
)
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
in
t
size
,
offset
;
Py_ssize_
t
size
,
offset
;
StgDictObject
*
stgdict
;
char
*
ptr
;
...
...
@@ -3802,7 +3802,7 @@ static int
Array_ass_slice
(
PyObject
*
_self
,
Py_ssize_t
ilow
,
Py_ssize_t
ihigh
,
PyObject
*
value
)
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
in
t
i
,
len
;
Py_ssize_
t
i
,
len
;
if
(
value
==
NULL
)
{
PyErr_SetString
(
PyExc_TypeError
,
...
...
@@ -4164,7 +4164,7 @@ static PyObject *
Pointer_item
(
PyObject
*
_self
,
Py_ssize_t
index
)
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
in
t
size
;
Py_ssize_
t
size
;
Py_ssize_t
offset
;
StgDictObject
*
stgdict
,
*
itemdict
;
PyObject
*
proto
;
...
...
@@ -4195,7 +4195,7 @@ static int
Pointer_ass_item
(
PyObject
*
_self
,
Py_ssize_t
index
,
PyObject
*
value
)
{
CDataObject
*
self
=
(
CDataObject
*
)
_self
;
in
t
size
;
Py_ssize_
t
size
;
Py_ssize_t
offset
;
StgDictObject
*
stgdict
,
*
itemdict
;
PyObject
*
proto
;
...
...
@@ -4629,9 +4629,10 @@ cast(void *ptr, PyObject *src, PyObject *ctype)
static
PyObject
*
wstring_at
(
const
wchar_t
*
ptr
,
int
size
)
{
if
(
size
==
-
1
)
size
=
wcslen
(
ptr
);
return
PyUnicode_FromWideChar
(
ptr
,
size
);
Py_ssize_t
ssize
=
size
;
if
(
ssize
==
-
1
)
ssize
=
wcslen
(
ptr
);
return
PyUnicode_FromWideChar
(
ptr
,
ssize
);
}
#endif
...
...
@@ -4831,7 +4832,7 @@ PyObject *My_PyUnicode_FromWideChar(register const wchar_t *w,
return
(
PyObject
*
)
unicode
;
}
in
t
My_PyUnicode_AsWideChar
(
PyUnicodeObject
*
unicode
,
Py_ssize_
t
My_PyUnicode_AsWideChar
(
PyUnicodeObject
*
unicode
,
register
wchar_t
*
w
,
Py_ssize_t
size
)
{
...
...
Modules/_ctypes/callbacks.c
View file @
e81c9f6d
...
...
@@ -123,10 +123,10 @@ static void _CallPythonObject(void *mem,
PyObject
*
converters
,
void
**
pArgs
)
{
in
t
i
;
Py_ssize_
t
i
;
PyObject
*
result
;
PyObject
*
arglist
=
NULL
;
in
t
nArgs
;
Py_ssize_
t
nArgs
;
#ifdef WITH_THREAD
PyGILState_STATE
state
=
PyGILState_Ensure
();
#endif
...
...
@@ -264,7 +264,7 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
{
int
result
;
ffi_info
*
p
;
in
t
nArgs
,
i
;
Py_ssize_
t
nArgs
,
i
;
ffi_abi
cc
;
nArgs
=
PySequence_Size
(
converters
);
...
...
@@ -307,7 +307,8 @@ ffi_info *AllocFunctionCallback(PyObject *callable,
if
(
is_cdecl
==
0
)
cc
=
FFI_STDCALL
;
#endif
result
=
ffi_prep_cif
(
&
p
->
cif
,
cc
,
nArgs
,
result
=
ffi_prep_cif
(
&
p
->
cif
,
cc
,
Py_SAFE_DOWNCAST
(
nArgs
,
Py_ssize_t
,
int
),
GetType
(
restype
),
&
p
->
atypes
[
0
]);
if
(
result
!=
FFI_OK
)
{
...
...
Modules/_ctypes/callproc.c
View file @
e81c9f6d
...
...
@@ -361,13 +361,13 @@ PyCArg_repr(PyCArgObject *self)
case
'z'
:
case
'Z'
:
case
'P'
:
sprintf
(
buffer
,
"<cparam '%c' (%
08lx
)>"
,
self
->
tag
,
(
long
)
self
->
value
.
p
);
sprintf
(
buffer
,
"<cparam '%c' (%
p
)>"
,
self
->
tag
,
self
->
value
.
p
);
break
;
default:
sprintf
(
buffer
,
"<cparam '%c' at %
08lx
>"
,
self
->
tag
,
(
long
)
self
);
sprintf
(
buffer
,
"<cparam '%c' at %
p
>"
,
self
->
tag
,
self
);
break
;
}
return
PyString_FromString
(
buffer
);
...
...
@@ -464,7 +464,7 @@ struct argument {
/*
* Convert a single Python object into a PyCArgObject and return it.
*/
static
int
ConvParam
(
PyObject
*
obj
,
in
t
index
,
struct
argument
*
pa
)
static
int
ConvParam
(
PyObject
*
obj
,
Py_ssize_
t
index
,
struct
argument
*
pa
)
{
StgDictObject
*
dict
;
pa
->
keep
=
NULL
;
/* so we cannot forget it later */
...
...
@@ -572,7 +572,8 @@ static int ConvParam(PyObject *obj, int index, struct argument *pa)
return
result
;
}
PyErr_Format
(
PyExc_TypeError
,
"Don't know how to convert parameter %d"
,
index
);
"Don't know how to convert parameter %d"
,
Py_SAFE_DOWNCAST
(
index
,
Py_ssize_t
,
int
));
return
-
1
;
}
}
...
...
@@ -912,7 +913,7 @@ PyObject *_CallProc(PPROC pProc,
PyObject
*
restype
,
PyObject
*
checker
)
{
in
t
i
,
n
,
argcount
,
argtype_count
;
Py_ssize_
t
i
,
n
,
argcount
,
argtype_count
;
void
*
resbuf
;
struct
argument
*
args
,
*
pa
;
ffi_type
**
atypes
;
...
...
@@ -1002,7 +1003,10 @@ PyObject *_CallProc(PPROC pProc,
}
if
(
-
1
==
_call_function_pointer
(
flags
,
pProc
,
avalues
,
atypes
,
rtype
,
resbuf
,
argcount
))
rtype
,
resbuf
,
Py_SAFE_DOWNCAST
(
argcount
,
Py_ssize_t
,
int
)))
goto
cleanup
;
#ifdef WORDS_BIGENDIAN
...
...
@@ -1358,10 +1362,10 @@ sizeof_func(PyObject *self, PyObject *obj)
dict
=
PyType_stgdict
(
obj
);
if
(
dict
)
return
PyInt_From
Long
(
dict
->
size
);
return
PyInt_From
Ssize_t
(
dict
->
size
);
if
(
CDataObject_Check
(
obj
))
return
PyInt_From
Long
(((
CDataObject
*
)
obj
)
->
b_size
);
return
PyInt_From
Ssize_t
(((
CDataObject
*
)
obj
)
->
b_size
);
PyErr_SetString
(
PyExc_TypeError
,
"this type has no size"
);
return
NULL
;
...
...
@@ -1379,11 +1383,11 @@ align_func(PyObject *self, PyObject *obj)
dict
=
PyType_stgdict
(
obj
);
if
(
dict
)
return
PyInt_From
Long
(
dict
->
align
);
return
PyInt_From
Ssize_t
(
dict
->
align
);
dict
=
PyObject_stgdict
(
obj
);
if
(
dict
)
return
PyInt_From
Long
(
dict
->
align
);
return
PyInt_From
Ssize_t
(
dict
->
align
);
PyErr_SetString
(
PyExc_TypeError
,
"no alignment info"
);
...
...
Modules/_ctypes/cfield.c
View file @
e81c9f6d
This diff is collapsed.
Click to expand it.
Modules/_ctypes/ctypes.h
View file @
e81c9f6d
...
...
@@ -4,6 +4,7 @@
#if (PY_VERSION_HEX < 0x02050000)
typedef
int
Py_ssize_t
;
#define PyInt_FromSsize_t PyInt_FromLong
#endif
#ifndef MS_WIN32
...
...
@@ -31,8 +32,8 @@ typedef int Py_ssize_t;
typedef
struct
tagPyCArgObject
PyCArgObject
;
typedef
struct
tagCDataObject
CDataObject
;
typedef
PyObject
*
(
*
GETFUNC
)(
void
*
,
unsigned
size
);
typedef
PyObject
*
(
*
SETFUNC
)(
void
*
,
PyObject
*
value
,
unsigned
size
);
typedef
PyObject
*
(
*
GETFUNC
)(
void
*
,
Py_ssize_t
size
);
typedef
PyObject
*
(
*
SETFUNC
)(
void
*
,
PyObject
*
value
,
Py_ssize_t
size
);
typedef
PyCArgObject
*
(
*
PARAMFUNC
)(
CDataObject
*
obj
);
/* A default buffer in CDataObject, which can be used for small C types. If
...
...
@@ -137,9 +138,9 @@ extern struct fielddesc *getentry(char *fmt);
extern
PyObject
*
CField_FromDesc
(
PyObject
*
desc
,
in
t
index
,
in
t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
int
*
psize
,
int
*
poffset
,
in
t
*
palign
,
CField_FromDesc
(
PyObject
*
desc
,
Py_ssize_
t
index
,
Py_ssize_
t
*
pfield_size
,
int
bitsize
,
int
*
pbitofs
,
Py_ssize_t
*
psize
,
Py_ssize_t
*
poffset
,
Py_ssize_
t
*
palign
,
int
pack
,
int
is_big_endian
);
extern
PyObject
*
CData_AtAddress
(
PyObject
*
type
,
void
*
buf
);
...
...
@@ -310,7 +311,7 @@ struct tagPyCArgObject {
void
*
p
;
}
value
;
PyObject
*
obj
;
in
t
size
;
/* for the 'V' tag */
Py_ssize_
t
size
;
/* for the 'V' tag */
};
extern
PyTypeObject
PyCArg_Type
;
...
...
@@ -387,7 +388,7 @@ extern char *conversion_mode_errors;
# define PyUnicode_AsWideChar My_PyUnicode_AsWideChar
extern
PyObject
*
My_PyUnicode_FromWideChar
(
const
wchar_t
*
,
Py_ssize_t
);
extern
in
t
My_PyUnicode_AsWideChar
(
PyUnicodeObject
*
,
wchar_t
*
,
Py_ssize_t
);
extern
Py_ssize_
t
My_PyUnicode_AsWideChar
(
PyUnicodeObject
*
,
wchar_t
*
,
Py_ssize_t
);
#endif
...
...
Modules/_ctypes/stgdict.c
View file @
e81c9f6d
...
...
@@ -50,7 +50,7 @@ int
StgDict_clone
(
StgDictObject
*
dst
,
StgDictObject
*
src
)
{
char
*
d
,
*
s
;
in
t
size
;
Py_ssize_
t
size
;
StgDict_clear
(
dst
);
PyMem_Free
(
dst
->
ffi_type_pointer
.
elements
);
...
...
@@ -289,13 +289,13 @@ int
StructUnionType_update_stgdict
(
PyObject
*
type
,
PyObject
*
fields
,
int
isStruct
)
{
StgDictObject
*
stgdict
,
*
basedict
;
in
t
len
,
offset
,
size
,
align
,
i
;
in
t
union_size
,
total_align
;
in
t
field_size
=
0
;
Py_ssize_
t
len
,
offset
,
size
,
align
,
i
;
Py_ssize_
t
union_size
,
total_align
;
Py_ssize_
t
field_size
=
0
;
int
bitofs
;
PyObject
*
isPacked
;
int
pack
=
0
;
in
t
ffi_ofs
;
Py_ssize_
t
ffi_ofs
;
int
big_endian
;
/* HACK Alert: I cannot be bothered to fix ctypes.com, so there has to
...
...
@@ -484,7 +484,9 @@ StructUnionType_update_stgdict(PyObject *type, PyObject *fields, int isStruct)
/* Adjust the size according to the alignment requirements */
size
=
((
size
+
total_align
-
1
)
/
total_align
)
*
total_align
;
stgdict
->
ffi_type_pointer
.
alignment
=
total_align
;
stgdict
->
ffi_type_pointer
.
alignment
=
Py_SAFE_DOWNCAST
(
total_align
,
Py_ssize_t
,
unsigned
short
);
stgdict
->
ffi_type_pointer
.
size
=
size
;
stgdict
->
size
=
size
;
...
...
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