Skip to content

Commit a54419a

Browse files
committed
small fixes
1 parent 38ba41e commit a54419a

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

docs/source/core/data-structures/zend_string.rst

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ hashing, and interning helpers.
8989
- - ``zend_string_concat2(s1, l1, s2, l2)``
9090
- Creates a non-persistent string by concatenating two character buffers.
9191

92-
- - ``zend_string_concat3(...)``
92+
- - ``zend_string_concat3(s1, l1, s2, l2, s3, l3)``
9393
- Same as ``zend_string_concat2``, but for three character buffers.
9494

9595
- - ``ZSTR_EMPTY_ALLOC()``
@@ -116,11 +116,13 @@ hashing, and interning helpers.
116116
- Description
117117

118118
- - ``zend_string_realloc(s, l, p)``
119-
- Resizes a string to length ``l``. May return a different pointer. If shared/interned, a new
120-
allocation is created.
119+
- Changes the size of the string. If the string has a reference count greater than 1 or if
120+
the string is interned, a new string is created. You must always use the return value of
121+
this function, as the original array may have been moved to a new location in memory.
121122

122123
- - ``zend_string_safe_realloc(s, n, m, l, p)``
123-
- Resizes a string to ``n * m + l`` bytes with overflow checks.
124+
- Resizes a string to ``n * m + l`` bytes with overflow checks. Allocates a string of
125+
length ``n * m + l``. This function is commonly useful for encoding changes.
124126

125127
- - ``zend_string_extend(s, l, p)``
126128
- Extends a string to a larger length (``l >= ZSTR_LEN(s)``).
@@ -194,7 +196,9 @@ strings.
194196
- Returns the reference count. Interned strings always report ``1``.
195197

196198
- - ``zend_string_addref(s)``
197-
- Increments the reference count of a non-interned string.
199+
- Increments the reference count of a non-interned string. the function that is used
200+
most often by far is zend_string_copy(). This function not only increments the refcount,
201+
but also returns the original string. This makes code more readable in practice.
198202

199203
- - ``zend_string_delref(s)``
200204
- Decrements the reference count of a non-interned string.
@@ -203,14 +207,18 @@ strings.
203207
- Decreases the reference count and frees the string if it goes to 0.
204208

205209
- - ``zend_string_release_ex(s, p)``
206-
- Like ``zend_string_release()``, but chooses the deallocator from ``p``. Use only if the
207-
persistence mode is known by the caller.
210+
- Like ``zend_string_release()``, but allows you to specify whether the passed string is
211+
persistent or non-persistent. If it is persistent, ``p`` should be ``0``.
208212

209213
- - ``zend_string_free(s)``
210214
- Frees a non-interned string directly. The caller must ensure it is no longer shared.
215+
Requires refcount 1 or immutable.You should avoid using these functions, as it is
216+
easy to introduce critical bugs when some API changes from returning new strings to
217+
reusing existing ones.
211218

212219
- - ``zend_string_efree(s)``
213-
- Frees a non-persistent, non-interned string with ``efree``.
220+
- Similar to ``zend_string_free``. Frees a non-persistent, non-interned string
221+
with ``efree``. Requires refcount 1 and not immutable.
214222

215223
There are various functions to compare strings.
216224

@@ -314,7 +322,7 @@ There are various functions to compare strings.
314322
- Same as ``ZSTR_ALLOCA_ALLOC``, then copies data from ``s`` and appends ``'\0'``.
315323

316324
- - ``ZSTR_ALLOCA_FREE(str, use_heap)``
317-
- Frees memory previously allocated with ``ZSTR_ALLOCA_ALLOC``/``ZSTR_ALLOCA_INIT``.
325+
- Frees memory previously allocated with ``ZSTR_ALLOCA_ALLOC`` / ``ZSTR_ALLOCA_INIT``.
318326

319327
.. list-table:: Interned string APIs
320328
:header-rows: 1

0 commit comments

Comments
 (0)