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
c5c3ba4b
Kaydet (Commit)
c5c3ba4b
authored
Eki 14, 2015
tarafından
Victor Stinner
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add _PyBytesWriter_Resize() function
This function gives a control to the buffer size without using min_size.
üst
3c50ce39
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
48 additions
and
19 deletions
+48
-19
bytesobject.h
Include/bytesobject.h
+18
-1
bytesobject.c
Objects/bytesobject.c
+30
-18
No files found.
Include/bytesobject.h
Dosyayı görüntüle @
c5c3ba4b
...
...
@@ -178,7 +178,9 @@ PyAPI_FUNC(void) _PyBytesWriter_Dealloc(_PyBytesWriter *writer);
PyAPI_FUNC
(
void
*
)
_PyBytesWriter_Alloc
(
_PyBytesWriter
*
writer
,
Py_ssize_t
size
);
/* Add *size* bytes to the buffer.
/* Ensure that the buffer is large enough to write *size* bytes.
Add size to the writer minimum size (min_size attribute).
str is the current pointer inside the buffer.
Return the updated current pointer inside the buffer.
Raise an exception and return NULL on error. */
...
...
@@ -186,6 +188,21 @@ PyAPI_FUNC(void*) _PyBytesWriter_Prepare(_PyBytesWriter *writer,
void
*
str
,
Py_ssize_t
size
);
/* Resize the buffer to make it larger.
The new buffer may be larger than size bytes because of overallocation.
Return the updated current pointer inside the buffer.
Raise an exception and return NULL on error.
Note: size must be greater than the number of allocated bytes in the writer.
This function doesn't use the writer minimum size (min_size attribute).
See also _PyBytesWriter_Prepare().
*/
PyAPI_FUNC
(
void
*
)
_PyBytesWriter_Resize
(
_PyBytesWriter
*
writer
,
void
*
str
,
Py_ssize_t
size
);
/* Write bytes.
Raise an exception and return NULL on error. */
PyAPI_FUNC
(
void
*
)
_PyBytesWriter_WriteBytes
(
_PyBytesWriter
*
writer
,
...
...
Objects/bytesobject.c
Dosyayı görüntüle @
c5c3ba4b
...
...
@@ -3997,29 +3997,14 @@ _PyBytesWriter_CheckConsistency(_PyBytesWriter *writer, char *str)
}
void
*
_PyBytesWriter_
Prepar
e
(
_PyBytesWriter
*
writer
,
void
*
str
,
Py_ssize_t
size
)
_PyBytesWriter_
Resiz
e
(
_PyBytesWriter
*
writer
,
void
*
str
,
Py_ssize_t
size
)
{
Py_ssize_t
allocated
,
pos
;
_PyBytesWriter_CheckConsistency
(
writer
,
str
);
assert
(
size
>=
0
);
if
(
size
==
0
)
{
/* nothing to do */
return
str
;
}
if
(
writer
->
min_size
>
PY_SSIZE_T_MAX
-
size
)
{
PyErr_NoMemory
();
goto
error
;
}
writer
->
min_size
+=
size
;
allocated
=
writer
->
allocated
;
if
(
writer
->
min_size
<=
allocated
)
return
str
;
assert
(
writer
->
allocated
<
size
);
allocated
=
writer
->
min_
size
;
allocated
=
size
;
if
(
writer
->
overallocate
&&
allocated
<=
(
PY_SSIZE_T_MAX
-
allocated
/
OVERALLOCATE_FACTOR
))
{
/* overallocate to limit the number of realloc() */
...
...
@@ -4080,6 +4065,33 @@ error:
return
NULL
;
}
void
*
_PyBytesWriter_Prepare
(
_PyBytesWriter
*
writer
,
void
*
str
,
Py_ssize_t
size
)
{
Py_ssize_t
new_min_size
;
_PyBytesWriter_CheckConsistency
(
writer
,
str
);
assert
(
size
>=
0
);
if
(
size
==
0
)
{
/* nothing to do */
return
str
;
}
if
(
writer
->
min_size
>
PY_SSIZE_T_MAX
-
size
)
{
PyErr_NoMemory
();
_PyBytesWriter_Dealloc
(
writer
);
return
NULL
;
}
new_min_size
=
writer
->
min_size
+
size
;
if
(
new_min_size
>
writer
->
allocated
)
str
=
_PyBytesWriter_Resize
(
writer
,
str
,
new_min_size
);
writer
->
min_size
=
new_min_size
;
return
str
;
}
/* Allocate the buffer to write size bytes.
Return the pointer to the beginning of buffer data.
Raise an exception and return NULL on error. */
...
...
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