Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
eb2389be
Kaydet (Commit)
eb2389be
authored
Mar 26, 2011
tarafından
Benjamin Peterson
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
merge 3.2
üst
b04d70d9
1a07f073
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
20 deletions
+72
-20
test_as_parameter.py
Lib/ctypes/test/test_as_parameter.py
+12
-0
NEWS
Misc/NEWS
+6
-0
_ctypes.c
Modules/_ctypes/_ctypes.c
+54
-20
No files found.
Lib/ctypes/test/test_as_parameter.py
Dosyayı görüntüle @
eb2389be
...
@@ -187,6 +187,18 @@ class BasicWrapTestCase(unittest.TestCase):
...
@@ -187,6 +187,18 @@ class BasicWrapTestCase(unittest.TestCase):
self
.
assertEqual
((
s8i
.
a
,
s8i
.
b
,
s8i
.
c
,
s8i
.
d
,
s8i
.
e
,
s8i
.
f
,
s8i
.
g
,
s8i
.
h
),
self
.
assertEqual
((
s8i
.
a
,
s8i
.
b
,
s8i
.
c
,
s8i
.
d
,
s8i
.
e
,
s8i
.
f
,
s8i
.
g
,
s8i
.
h
),
(
9
*
2
,
8
*
3
,
7
*
4
,
6
*
5
,
5
*
6
,
4
*
7
,
3
*
8
,
2
*
9
))
(
9
*
2
,
8
*
3
,
7
*
4
,
6
*
5
,
5
*
6
,
4
*
7
,
3
*
8
,
2
*
9
))
def
test_recursive_as_param
(
self
):
from
ctypes
import
c_int
class
A
(
object
):
pass
a
=
A
()
a
.
_as_parameter_
=
a
with
self
.
assertRaises
(
RuntimeError
):
c_int
.
from_param
(
a
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class
AsParamWrapper
(
object
):
class
AsParamWrapper
(
object
):
...
...
Misc/NEWS
Dosyayı görüntüle @
eb2389be
...
@@ -322,6 +322,12 @@ Tools/Demos
...
@@ -322,6 +322,12 @@ Tools/Demos
-
Issue
#
11179
:
Make
ccbench
work
under
Python
3.1
and
2.7
again
.
-
Issue
#
11179
:
Make
ccbench
work
under
Python
3.1
and
2.7
again
.
Extensions
----------
-
Issue
#
1838
:
Prevent
segfault
in
ctypes
,
when
_as_parameter_
on
a
class
is
set
to
an
instance
of
the
class
.
Tests
Tests
-----
-----
...
...
Modules/_ctypes/_ctypes.c
Dosyayı görüntüle @
eb2389be
...
@@ -585,7 +585,10 @@ static PyObject *
...
@@ -585,7 +585,10 @@ static PyObject *
CDataType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
CDataType_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
if
(
1
==
PyObject_IsInstance
(
value
,
type
))
{
int
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -598,10 +601,14 @@ CDataType_from_param(PyObject *type, PyObject *value)
...
@@ -598,10 +601,14 @@ CDataType_from_param(PyObject *type, PyObject *value)
/* If we got a PyCArgObject, we must check if the object packed in it
/* If we got a PyCArgObject, we must check if the object packed in it
is an instance of the type's dict->proto */
is an instance of the type's dict->proto */
if
(
dict
&&
ob
if
(
dict
&&
ob
)
{
&&
PyObject_IsInstance
(
ob
,
dict
->
proto
))
{
res
=
PyObject_IsInstance
(
ob
,
dict
->
proto
);
Py_INCREF
(
value
);
if
(
res
==
-
1
)
return
value
;
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
return
value
;
}
}
}
ob_name
=
(
ob
)
?
Py_TYPE
(
ob
)
->
tp_name
:
"???"
;
ob_name
=
(
ob
)
?
Py_TYPE
(
ob
)
->
tp_name
:
"???"
;
PyErr_Format
(
PyExc_TypeError
,
PyErr_Format
(
PyExc_TypeError
,
...
@@ -951,8 +958,7 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
...
@@ -951,8 +958,7 @@ PyCPointerType_from_param(PyObject *type, PyObject *value)
Py_INCREF
(
value
);
/* _byref steals a refcount */
Py_INCREF
(
value
);
/* _byref steals a refcount */
return
_byref
(
value
);
return
_byref
(
value
);
case
-
1
:
case
-
1
:
PyErr_Clear
();
return
NULL
;
break
;
default:
default:
break
;
break
;
}
}
...
@@ -1431,6 +1437,7 @@ static PyObject *
...
@@ -1431,6 +1437,7 @@ static PyObject *
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
c_wchar_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
...
@@ -1451,7 +1458,10 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
...
@@ -1451,7 +1458,10 @@ c_wchar_p_from_param(PyObject *type, PyObject *value)
}
}
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1492,6 +1502,7 @@ static PyObject *
...
@@ -1492,6 +1502,7 @@ static PyObject *
c_char_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
c_char_p_from_param
(
PyObject
*
type
,
PyObject
*
value
)
{
{
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
Py_INCREF
(
Py_None
);
Py_INCREF
(
Py_None
);
return
Py_None
;
return
Py_None
;
...
@@ -1512,7 +1523,10 @@ c_char_p_from_param(PyObject *type, PyObject *value)
...
@@ -1512,7 +1523,10 @@ c_char_p_from_param(PyObject *type, PyObject *value)
}
}
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -1554,6 +1568,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1554,6 +1568,7 @@ c_void_p_from_param(PyObject *type, PyObject *value)
{
{
StgDictObject
*
stgd
;
StgDictObject
*
stgd
;
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
/* None */
/* None */
if
(
value
==
Py_None
)
{
if
(
value
==
Py_None
)
{
...
@@ -1631,7 +1646,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
...
@@ -1631,7 +1646,10 @@ c_void_p_from_param(PyObject *type, PyObject *value)
return
(
PyObject
*
)
parg
;
return
(
PyObject
*
)
parg
;
}
}
/* c_void_p instance (or subclass) */
/* c_void_p instance (or subclass) */
if
(
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
/* c_void_p instances */
/* c_void_p instances */
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
...
@@ -1990,10 +2008,14 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
...
@@ -1990,10 +2008,14 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
PyCArgObject
*
parg
;
PyCArgObject
*
parg
;
struct
fielddesc
*
fd
;
struct
fielddesc
*
fd
;
PyObject
*
as_parameter
;
PyObject
*
as_parameter
;
int
res
;
/* If the value is already an instance of the requested type,
/* If the value is already an instance of the requested type,
we can use it as is */
we can use it as is */
if
(
1
==
PyObject_IsInstance
(
value
,
type
))
{
res
=
PyObject_IsInstance
(
value
,
type
);
if
(
res
==
-
1
)
return
NULL
;
if
(
res
)
{
Py_INCREF
(
value
);
Py_INCREF
(
value
);
return
value
;
return
value
;
}
}
...
@@ -2022,7 +2044,12 @@ PyCSimpleType_from_param(PyObject *type, PyObject *value)
...
@@ -2022,7 +2044,12 @@ PyCSimpleType_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
)
{
if
(
Py_EnterRecursiveCall
(
"while processing _as_parameter_"
))
{
Py_DECREF
(
as_parameter
);
return
NULL
;
}
value
=
PyCSimpleType_from_param
(
type
,
as_parameter
);
value
=
PyCSimpleType_from_param
(
type
,
as_parameter
);
Py_LeaveRecursiveCall
();
Py_DECREF
(
as_parameter
);
Py_DECREF
(
as_parameter
);
return
value
;
return
value
;
}
}
...
@@ -2714,6 +2741,7 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2714,6 +2741,7 @@ _PyCData_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
;
int
err
;
if
(
setfunc
)
if
(
setfunc
)
return
setfunc
(
ptr
,
value
,
size
);
return
setfunc
(
ptr
,
value
,
size
);
...
@@ -2754,7 +2782,10 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
...
@@ -2754,7 +2782,10 @@ _PyCData_set(CDataObject *dst, PyObject *type, SETFUNC setfunc, PyObject *value,
}
}
src
=
(
CDataObject
*
)
value
;
src
=
(
CDataObject
*
)
value
;
if
(
PyObject_IsInstance
(
value
,
type
))
{
err
=
PyObject_IsInstance
(
value
,
type
);
if
(
err
==
-
1
)
return
NULL
;
if
(
err
)
{
memcpy
(
ptr
,
memcpy
(
ptr
,
src
->
b_ptr
,
src
->
b_ptr
,
size
);
size
);
...
@@ -4749,14 +4780,17 @@ Pointer_set_contents(CDataObject *self, PyObject *value, void *closure)
...
@@ -4749,14 +4780,17 @@ Pointer_set_contents(CDataObject *self, PyObject *value, 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 */
assert
(
stgdict
->
proto
);
assert
(
stgdict
->
proto
);
if
(
!
CDataObject_Check
(
value
)
if
(
!
CDataObject_Check
(
value
))
{
||
0
==
PyObject_IsInstance
(
value
,
stgdict
->
proto
))
{
int
res
=
PyObject_IsInstance
(
value
,
stgdict
->
proto
);
/* XXX PyObject_IsInstance could return -1! */
if
(
res
==
-
1
)
PyErr_Format
(
PyExc_TypeError
,
return
-
1
;
"expected %s instead of %s"
,
if
(
!
res
)
{
((
PyTypeObject
*
)(
stgdict
->
proto
))
->
tp_name
,
PyErr_Format
(
PyExc_TypeError
,
Py_TYPE
(
value
)
->
tp_name
);
"expected %s instead of %s"
,
return
-
1
;
((
PyTypeObject
*
)(
stgdict
->
proto
))
->
tp_name
,
Py_TYPE
(
value
)
->
tp_name
);
return
-
1
;
}
}
}
dst
=
(
CDataObject
*
)
value
;
dst
=
(
CDataObject
*
)
value
;
...
...
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