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
eb6f8de8
Kaydet (Commit)
eb6f8de8
authored
Ara 31, 2009
tarafından
Alexandre Vassalotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #6687: Moved the special-case for integers out of PyBytes_FromObject.
üst
b05e73d9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
25 deletions
+33
-25
object.rst
Doc/c-api/object.rst
+5
-4
NEWS
Misc/NEWS
+3
-0
bytesobject.c
Objects/bytesobject.c
+25
-21
No files found.
Doc/c-api/object.rst
Dosyayı görüntüle @
eb6f8de8
...
...
@@ -142,10 +142,11 @@ Object Protocol
.. index:: builtin: bytes
Compute a bytes representation of object *o*. *NULL* is returned on failure
and a bytes object on success. This is equivalent to the Python expression
``bytes(o)``.
Compute a bytes representation of object *o*. *NULL* is returned on
failure and a bytes object on success. This is equivalent to the Python
expression ``bytes(o)``, when *o* is not an integer. Unlike ``bytes(o)``,
a TypeError is raised when *o* is an integer instead of a zero-initialized
bytes object.
.. cfunction:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
...
...
Misc/NEWS
Dosyayı görüntüle @
eb6f8de8
...
...
@@ -140,6 +140,9 @@ Core and Builtins
- Issue #4856: Remove checks for win NT.
- Issue #6687: PyBytes_FromObject() no longer accepts an integer as its
argument to construct a null-initialized bytes object.
C-API
-----
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
eb6f8de8
...
...
@@ -2884,6 +2884,7 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
const
char
*
encoding
=
NULL
;
const
char
*
errors
=
NULL
;
PyObject
*
new
=
NULL
;
Py_ssize_t
size
;
static
char
*
kwlist
[]
=
{
"source"
,
"encoding"
,
"errors"
,
0
};
if
(
type
!=
&
PyBytes_Type
)
...
...
@@ -2914,6 +2915,25 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
assert
(
PyBytes_Check
(
new
));
return
new
;
}
/* Is it an integer? */
size
=
PyNumber_AsSsize_t
(
x
,
PyExc_ValueError
);
if
(
size
==
-
1
&&
PyErr_Occurred
())
{
PyErr_Clear
();
}
else
{
if
(
size
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
NULL
;
}
new
=
PyBytes_FromStringAndSize
(
NULL
,
size
);
if
(
new
==
NULL
)
{
return
NULL
;
}
if
(
size
>
0
)
{
memset
(((
PyBytesObject
*
)
new
)
->
ob_sval
,
0
,
size
);
}
return
new
;
}
/* If it's not unicode, there can't be encoding or errors */
if
(
encoding
!=
NULL
||
errors
!=
NULL
)
{
...
...
@@ -2934,27 +2954,6 @@ PyBytes_FromObject(PyObject *x)
PyErr_BadInternalCall
();
return
NULL
;
}
/* Is it an int? */
size
=
PyNumber_AsSsize_t
(
x
,
PyExc_ValueError
);
if
(
size
==
-
1
&&
PyErr_Occurred
())
{
PyErr_Clear
();
}
else
{
if
(
size
<
0
)
{
PyErr_SetString
(
PyExc_ValueError
,
"negative count"
);
return
NULL
;
}
new
=
PyBytes_FromStringAndSize
(
NULL
,
size
);
if
(
new
==
NULL
)
{
return
NULL
;
}
if
(
size
>
0
)
{
memset
(((
PyBytesObject
*
)
new
)
->
ob_sval
,
0
,
size
);
}
return
new
;
}
/* Use the modern buffer interface */
if
(
PyObject_CheckBuffer
(
x
))
{
Py_buffer
view
;
...
...
@@ -2974,6 +2973,11 @@ PyBytes_FromObject(PyObject *x)
PyBuffer_Release
(
&
view
);
return
NULL
;
}
if
(
PyUnicode_Check
(
x
))
{
PyErr_SetString
(
PyExc_TypeError
,
"cannot convert unicode object to bytes"
);
return
NULL
;
}
/* For iterator version, create a string object and resize as needed */
/* XXX(gb): is 64 a good value? also, optimize if length is known */
...
...
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