Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-132070: Use _PyObject_IsUniquelyReferenced in unicodeobject#133039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
corona10 merged 4 commits intopython:mainfromcorona10:kumar-test
Apr 29, 2025
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletionsObjects/unicodeobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1139,6 +1139,21 @@ unicode_fill_invalid(PyObject *unicode, Py_ssize_t old_length)
}
#endif

static PyObject*
resize_copy(PyObject *unicode, Py_ssize_t length)
{
Py_ssize_t copy_length;
PyObject *copy;

copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
if (copy == NULL)
return NULL;

copy_length = Py_MIN(length, PyUnicode_GET_LENGTH(unicode));
_PyUnicode_FastCopyCharacters(copy, 0, unicode, 0, copy_length);
return copy;
}

static PyObject*
resize_compact(PyObject *unicode, Py_ssize_t length)
{
Expand All@@ -1150,7 +1165,14 @@ resize_compact(PyObject *unicode, Py_ssize_t length)
Py_ssize_t old_length = _PyUnicode_LENGTH(unicode);
#endif

assert(unicode_modifiable(unicode));
if (!unicode_modifiable(unicode)) {
PyObject *copy = resize_copy(unicode, length);
if (copy == NULL) {
return NULL;
}
Py_DECREF(unicode);
return copy;
}
assert(PyUnicode_IS_COMPACT(unicode));

char_size = PyUnicode_KIND(unicode);
Expand DownExpand Up@@ -1250,21 +1272,6 @@ resize_inplace(PyObject *unicode, Py_ssize_t length)
return 0;
}

static PyObject*
resize_copy(PyObject *unicode, Py_ssize_t length)
{
Py_ssize_t copy_length;
PyObject *copy;

copy = PyUnicode_New(length, PyUnicode_MAX_CHAR_VALUE(unicode));
if (copy == NULL)
return NULL;

copy_length = Py_MIN(length, PyUnicode_GET_LENGTH(unicode));
_PyUnicode_FastCopyCharacters(copy, 0, unicode, 0, copy_length);
return copy;
}

static const char*
unicode_kind_name(PyObject *unicode)
{
Expand DownExpand Up@@ -1816,7 +1823,7 @@ static int
unicode_modifiable(PyObject *unicode)
{
assert(_PyUnicode_CHECK(unicode));
if (Py_REFCNT(unicode) != 1)
if (!_PyObject_IsUniquelyReferenced(unicode))
return 0;
if (PyUnicode_HASH(unicode) != -1)
return 0;
Expand DownExpand Up@@ -14738,7 +14745,7 @@ _PyUnicode_FormatLong(PyObject *val, int alt, int prec, int type)
assert(PyUnicode_IS_ASCII(result));

/* To modify the string in-place, there can only be one reference. */
if (Py_REFCNT(result) != 1) {
if (!_PyObject_IsUniquelyReferenced(result)) {
Py_DECREF(result);
PyErr_BadInternalCall();
return NULL;
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp