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
9e7a4c97
Kaydet (Commit)
9e7a4c97
authored
Mar 22, 2010
tarafından
Florent Xicluna
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #7703: ctypes supports both buffer() and memoryview(). The former is deprecated.
Complement of r79288.
üst
c9d1a784
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
6 deletions
+25
-6
test_strings.py
Lib/ctypes/test/test_strings.py
+9
-2
NEWS
Misc/NEWS
+3
-0
_ctypes.c
Modules/_ctypes/_ctypes.c
+13
-4
No files found.
Lib/ctypes/test/test_strings.py
Dosyayı görüntüle @
9e7a4c97
import
unittest
from
ctypes
import
*
from
test
import
test_support
class
StringArrayTestCase
(
unittest
.
TestCase
):
def
test
(
self
):
...
...
@@ -24,7 +25,7 @@ class StringArrayTestCase(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"value"
,
"aaaaaaaa"
)
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
42
)
def
test_c_buffer_value
(
self
):
def
test_c_buffer_value
(
self
,
memoryview
=
memoryview
):
buf
=
c_buffer
(
32
)
buf
.
value
=
"Hello, World"
...
...
@@ -34,7 +35,7 @@ class StringArrayTestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
memoryview
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
memoryview
(
"x"
*
100
))
def
test_c_buffer_raw
(
self
):
def
test_c_buffer_raw
(
self
,
memoryview
=
memoryview
):
buf
=
c_buffer
(
32
)
buf
.
raw
=
memoryview
(
"Hello, World"
)
...
...
@@ -42,6 +43,12 @@ class StringArrayTestCase(unittest.TestCase):
self
.
assertRaises
(
TypeError
,
setattr
,
buf
,
"value"
,
memoryview
(
"abc"
))
self
.
assertRaises
(
ValueError
,
setattr
,
buf
,
"raw"
,
memoryview
(
"x"
*
100
))
def
test_c_buffer_deprecated
(
self
):
# Compatibility with 2.x
with
test_support
.
check_py3k_warnings
():
self
.
test_c_buffer_value
(
buffer
)
self
.
test_c_buffer_raw
(
buffer
)
def
test_param_1
(
self
):
BUF
=
c_char
*
4
buf
=
BUF
()
...
...
Misc/NEWS
Dosyayı görüntüle @
9e7a4c97
...
...
@@ -29,6 +29,9 @@ Core and Builtins
Library
-------
- Issue #7703: ctypes supports both buffer() and memoryview(). The former is
deprecated.
- Issue #7860: platform.uname now reports the correct 'machine' type
when Python is running in WOW64 mode on 64 bit Windows.
...
...
Modules/_ctypes/_ctypes.c
Dosyayı görüntüle @
9e7a4c97
...
...
@@ -1076,22 +1076,31 @@ CharArray_set_raw(CDataObject *self, PyObject *value)
{
char
*
ptr
;
Py_ssize_t
size
;
Py_buffer
view
=
{
0
};
if
(
PyBuffer_Check
(
value
))
{
size
=
Py_TYPE
(
value
)
->
tp_as_buffer
->
bf_getreadbuffer
(
value
,
0
,
(
void
*
)
&
ptr
);
if
(
size
<
0
)
return
-
1
;
}
else
if
(
-
1
==
PyString_AsStringAndSize
(
value
,
&
ptr
,
&
size
))
{
return
-
1
;
goto
fail
;
}
else
{
if
(
PyObject_GetBuffer
(
value
,
&
view
,
PyBUF_SIMPLE
)
<
0
)
goto
fail
;
size
=
view
.
len
;
ptr
=
view
.
buf
;
}
if
(
size
>
self
->
b_size
)
{
PyErr_SetString
(
PyExc_ValueError
,
"string too long"
);
return
-
1
;
goto
fail
;
}
memcpy
(
self
->
b_ptr
,
ptr
,
size
);
PyBuffer_Release
(
&
view
);
return
0
;
fail
:
PyBuffer_Release
(
&
view
);
return
-
1
;
}
static
PyObject
*
...
...
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