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
f2eafa32
Kaydet (Commit)
f2eafa32
authored
Eki 14, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Split PyBytes_FromObject() into subfunctions
üst
2ec8063c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
114 additions
and
71 deletions
+114
-71
bytesobject.c
Objects/bytesobject.c
+114
-71
No files found.
Objects/bytesobject.c
Dosyayı görüntüle @
f2eafa32
...
...
@@ -3384,88 +3384,99 @@ bytes_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return
PyBytes_FromObject
(
x
);
}
PyObject
*
PyBytes_FromObject
(
PyObject
*
x
)
static
PyObject
*
_PyBytes_FromBuffer
(
PyObject
*
x
)
{
PyObject
*
new
,
*
it
;
Py_
ssize_t
i
,
size
;
PyObject
*
new
;
Py_
buffer
view
;
if
(
x
==
NULL
)
{
PyErr_BadInternalCall
();
if
(
PyObject_GetBuffer
(
x
,
&
view
,
PyBUF_FULL_RO
)
<
0
)
return
NULL
;
}
if
(
PyBytes_CheckExact
(
x
))
{
Py_INCREF
(
x
);
return
x
;
}
new
=
PyBytes_FromStringAndSize
(
NULL
,
view
.
len
);
if
(
!
new
)
goto
fail
;
if
(
PyBuffer_ToContiguous
(((
PyBytesObject
*
)
new
)
->
ob_sval
,
&
view
,
view
.
len
,
'C'
)
<
0
)
goto
fail
;
PyBuffer_Release
(
&
view
);
return
new
;
/* Use the modern buffer interface */
if
(
PyObject_CheckBuffer
(
x
))
{
Py_buffer
view
;
if
(
PyObject_GetBuffer
(
x
,
&
view
,
PyBUF_FULL_RO
)
<
0
)
return
NULL
;
new
=
PyBytes_FromStringAndSize
(
NULL
,
view
.
len
);
if
(
!
new
)
goto
fail
;
if
(
PyBuffer_ToContiguous
(((
PyBytesObject
*
)
new
)
->
ob_sval
,
&
view
,
view
.
len
,
'C'
)
<
0
)
goto
fail
;
PyBuffer_Release
(
&
view
);
return
new
;
fail:
Py_XDECREF
(
new
);
PyBuffer_Release
(
&
view
);
return
NULL
;
}
if
(
PyUnicode_Check
(
x
))
{
PyErr_SetString
(
PyExc_TypeError
,
"cannot convert unicode object to bytes"
);
fail:
Py_XDECREF
(
new
);
PyBuffer_Release
(
&
view
);
return
NULL
;
}
static
PyObject
*
_PyBytes_FromList
(
PyObject
*
x
)
{
PyObject
*
new
;
Py_ssize_t
i
;
Py_ssize_t
value
;
char
*
str
;
new
=
PyBytes_FromStringAndSize
(
NULL
,
Py_SIZE
(
x
));
if
(
new
==
NULL
)
return
NULL
;
}
str
=
((
PyBytesObject
*
)
new
)
->
ob_sval
;
if
(
PyList_CheckExact
(
x
))
{
new
=
PyBytes_FromStringAndSize
(
NULL
,
Py_SIZE
(
x
));
if
(
new
==
NULL
)
return
NULL
;
for
(
i
=
0
;
i
<
Py_SIZE
(
x
);
i
++
)
{
Py_ssize_t
value
=
PyNumber_AsSsize_t
(
PyList_GET_ITEM
(
x
,
i
),
PyExc_ValueError
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
{
Py_DECREF
(
new
);
return
NULL
;
}
if
(
value
<
0
||
value
>=
256
)
{
PyErr_SetString
(
PyExc_ValueError
,
"bytes must be in range(0, 256)"
);
Py_DECREF
(
new
);
return
NULL
;
}
((
PyBytesObject
*
)
new
)
->
ob_sval
[
i
]
=
(
char
)
value
;
for
(
i
=
0
;
i
<
Py_SIZE
(
x
);
i
++
)
{
value
=
PyNumber_AsSsize_t
(
PyList_GET_ITEM
(
x
,
i
),
PyExc_ValueError
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
goto
error
;
if
(
value
<
0
||
value
>=
256
)
{
PyErr_SetString
(
PyExc_ValueError
,
"bytes must be in range(0, 256)"
);
goto
error
;
}
return
new
;
*
str
++
=
(
char
)
value
;
}
if
(
PyTuple_CheckExact
(
x
))
{
new
=
PyBytes_FromStringAndSize
(
NULL
,
Py_SIZE
(
x
));
if
(
new
==
NULL
)
return
NULL
;
for
(
i
=
0
;
i
<
Py_SIZE
(
x
);
i
++
)
{
Py_ssize_t
value
=
PyNumber_AsSsize_t
(
PyTuple_GET_ITEM
(
x
,
i
),
PyExc_ValueError
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
{
Py_DECREF
(
new
);
return
NULL
;
}
if
(
value
<
0
||
value
>=
256
)
{
PyErr_SetString
(
PyExc_ValueError
,
"bytes must be in range(0, 256)"
);
Py_DECREF
(
new
);
return
NULL
;
}
((
PyBytesObject
*
)
new
)
->
ob_sval
[
i
]
=
(
char
)
value
;
return
new
;
error:
Py_DECREF
(
new
);
return
NULL
;
}
static
PyObject
*
_PyBytes_FromTuple
(
PyObject
*
x
)
{
PyObject
*
new
;
Py_ssize_t
i
;
Py_ssize_t
value
;
char
*
str
;
new
=
PyBytes_FromStringAndSize
(
NULL
,
Py_SIZE
(
x
));
if
(
new
==
NULL
)
return
NULL
;
str
=
((
PyBytesObject
*
)
new
)
->
ob_sval
;
for
(
i
=
0
;
i
<
Py_SIZE
(
x
);
i
++
)
{
value
=
PyNumber_AsSsize_t
(
PyTuple_GET_ITEM
(
x
,
i
),
PyExc_ValueError
);
if
(
value
==
-
1
&&
PyErr_Occurred
())
goto
error
;
if
(
value
<
0
||
value
>=
256
)
{
PyErr_SetString
(
PyExc_ValueError
,
"bytes must be in range(0, 256)"
);
goto
error
;
}
return
new
;
*
str
++
=
(
char
)
value
;
}
return
new
;
error:
Py_DECREF
(
new
);
return
NULL
;
}
static
PyObject
*
_PyBytes_FromIterator
(
PyObject
*
x
)
{
PyObject
*
new
,
*
it
;
Py_ssize_t
i
,
size
;
/* For iterator version, create a string object and resize as needed */
size
=
PyObject_LengthHint
(
x
,
64
);
...
...
@@ -3533,6 +3544,38 @@ PyBytes_FromObject(PyObject *x)
return
NULL
;
}
PyObject
*
PyBytes_FromObject
(
PyObject
*
x
)
{
if
(
x
==
NULL
)
{
PyErr_BadInternalCall
();
return
NULL
;
}
if
(
PyBytes_CheckExact
(
x
))
{
Py_INCREF
(
x
);
return
x
;
}
/* Use the modern buffer interface */
if
(
PyObject_CheckBuffer
(
x
))
return
_PyBytes_FromBuffer
(
x
);
if
(
PyList_CheckExact
(
x
))
return
_PyBytes_FromList
(
x
);
if
(
PyTuple_CheckExact
(
x
))
return
_PyBytes_FromTuple
(
x
);
if
(
PyUnicode_Check
(
x
))
{
PyErr_SetString
(
PyExc_TypeError
,
"cannot convert unicode object to bytes"
);
return
NULL
;
}
return
_PyBytes_FromIterator
(
x
);
}
static
PyObject
*
str_subtype_new
(
PyTypeObject
*
type
,
PyObject
*
args
,
PyObject
*
kwds
)
{
...
...
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