Skip to content

Commit 9fcd26c

Browse files
jc21jpauli
authored andcommitted
Fix some spelling and grammar (#27)
* Fix some spelling errors * Fix some spelling errors * Fix some spelling errors * Fix some spelling errors * Fix some spelling errors
1 parent c29a2e3 commit 9fcd26c

File tree

8 files changed

+464
-464
lines changed

8 files changed

+464
-464
lines changed

Book/php7/extensions_design/extension_infos.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ macro resolves to `display_ini_entries()
8787
A note about the Reflection API
8888
-------------------------------
8989

90-
The Reflection heavilly uses your ``zend_module_entry`` structure. For example, when you call
90+
The Reflection heavily uses your ``zend_module_entry`` structure. For example, when you call
9191
``ReflectionExtension::getVersion()``, the API just reads the version field of your ``zend_module_entry`` structure.
9292

9393
Same to discover functions, your ``zend_module_entry`` has got a ``const struct _zend_function_entry *functions`` member

Book/php7/extensions_design/extension_skeleton.rst

Lines changed: 64 additions & 64 deletions
Large diffs are not rendered by default.

Book/php7/extensions_design/zend_extensions.rst

Lines changed: 154 additions & 154 deletions
Large diffs are not rendered by default.
Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
11
PHP's custom printf functions
22
=============================
33

4-
You all know libc's ``printf()`` and family. This chapter will detail those many clones PHP declares and use, what's
4+
You all know libc's ``printf()`` and family. This chapter will detail those many clones PHP declares and use, what's
55
their goal, why use them and when to use them.
66

7-
.. note:: Libc's documentation about ``printf()`` and friends
7+
.. note:: Libc's documentation about ``printf()`` and friends
88
`is located here <https://www.gnu.org/software/libc/manual/html_node/Formatted-Output-Functions.html>`_
9-
9+
1010
You know that those functions are useful, but sometimes don't provide enough functionalities.
11-
Also, you know that
12-
`adding format strings <https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html>`_ to ``printf()``
11+
Also, you know that
12+
`adding format strings <https://www.gnu.org/software/libc/manual/html_node/Customizing-Printf.html>`_ to ``printf()``
1313
family is not trivial, not portable and security risky.
1414

1515
PHP adds its own printf-like functions to replace libc ones and to be used by the internal developer.
16-
They will mainly add new formats, play with :doc:`zend_string<zend_strings>` instead of
16+
They will mainly add new formats, play with :doc:`zend_string<zend_strings>` instead of
1717
``char *``, etc... Let's see them together.
1818

19-
.. warning:: You must master your libc default ``printf()`` formats. Read
19+
.. warning:: You must master your libc default ``printf()`` formats. Read
2020
`their documentation here <http://www.cplusplus.com/reference/cstdio/printf/>`_.
21-
22-
.. note:: Those functions are added **to replace** libc ones, that means that if you use ``sprintf()`` f.e, that won't
23-
lead to libc's ``sprintf()``, but to PHP replacement. Except the traditionnal ``printf()``, everything else
21+
22+
.. note:: Those functions are added **to replace** libc ones, that means that if you use ``sprintf()`` f.e, that won't
23+
lead to libc's ``sprintf()``, but to PHP replacement. Except the traditional ``printf()``, everything else
2424
is replaced.
2525

26-
Traditionnal use
27-
****************
26+
Traditional use
27+
***************
2828

29-
First of all, you should not use ``sprintf()``, as that function doesn't perform any check and allows many buffer
29+
First of all, you should not use ``sprintf()``, as that function doesn't perform any check and allows many buffer
3030
overflow errors. Please, try to avoid using it.
3131

3232
.. warning:: Please try to avoid using ``sprintf()`` as much as possible.
@@ -36,12 +36,12 @@ Then, you have some choice.
3636
You know your result buffer size
3737
--------------------------------
3838

39-
If you know your buffer size, ``snprintf()`` or ``slprintf()`` will do the job for you. There is a difference in what
39+
If you know your buffer size, ``snprintf()`` or ``slprintf()`` will do the job for you. There is a difference in what
4040
those functions return, but not in what those functions do.
4141

42-
They both print according to the formats passed, and they both terminate your buffer by a ``NUL`` byte *'\\0'* whatever
43-
happens. However, ``snprintf()`` returns the number of characters that could have been used, whereas ``slprintf()``
44-
returns the number of characters that have effectively been used, thus enabling to detect too-small buffers and string
42+
They both print according to the formats passed, and they both terminate your buffer by a ``NUL`` byte *'\\0'* whatever
43+
happens. However, ``snprintf()`` returns the number of characters that could have been used, whereas ``slprintf()``
44+
returns the number of characters that have effectively been used, thus enabling to detect too-small buffers and string
4545
truncation. This, is not counting the final *'\\0'*.
4646

4747
Here is an example so that you fully understand::
@@ -52,12 +52,12 @@ Here is an example so that you fully understand::
5252

5353
r = snprintf(foo, sizeof(foo), "%s", str);
5454
/* r = 11 here even if only 7 printable chars were written in foo */
55-
55+
5656
/* foo value is now 'H' 'e' 'l' 'l' 'o' ' ' 'w' '\0' */
5757

5858
``snprintf()`` is not a good function to use, as it does not allows to detect an eventual string truncation.
59-
As you can see from the example above, "Hello world\\0" doesn't fit in an eight-byte buffer, that's obvious, but
60-
``snprintf()`` still returns you 11, which is ``strlen("Hello world\0")``. You have no way to detect that the string's
59+
As you can see from the example above, "Hello world\\0" doesn't fit in an eight-byte buffer, that's obvious, but
60+
``snprintf()`` still returns you 11, which is ``strlen("Hello world\0")``. You have no way to detect that the string's
6161
got truncated.
6262

6363
Here is ``slprintf()``::
@@ -68,10 +68,10 @@ Here is ``slprintf()``::
6868

6969
r = slprintf(foo, sizeof(foo), "%s", str);
7070
/* r = 7 here , because 7 printable chars were written in foo */
71-
71+
7272
/* foo value is now 'H' 'e' 'l' 'l' 'o' ' ' 'w' '\0' */
7373

74-
With ``slprintf()``, the result buffer ``foo`` contains the exact same string, but the returned value is now 7. 7 is
74+
With ``slprintf()``, the result buffer ``foo`` contains the exact same string, but the returned value is now 7. 7 is
7575
less than the 11 chars from the *"Hello world"* string, thus you can detect that it got truncated::
7676

7777
if (slprintf(foo, sizeof(foo), "%s", str) < strlen(str)) {
@@ -83,7 +83,7 @@ Remember:
8383
* Those two function always ``NUL`` terminate the string, truncation or not. Result strings are then safe C strings.
8484
* Only ``slprintf()`` allows to detect a string truncation.
8585

86-
Those two functions are defined in
86+
Those two functions are defined in
8787
`main/snprintf.c <https://github.com/php/php-src/blob/648be8600ff89e1b0e4a4ad25cebad42b53bed6d/main/snprintf.c>`_
8888

8989
You don't know your buffer size
@@ -95,106 +95,106 @@ Remember that **you'll have to free** the buffer by yourself !
9595
Here is an example::
9696

9797
#include <time.h>
98-
98+
9999
char *result;
100100
int r;
101101

102102
time_t timestamp = time(NULL);
103103

104104
r = spprintf(&result, 0, "Here is the date: %s", asctime(localtime(&timestamp)));
105-
105+
106106
/* now use result that contains something like "Here is the date: Thu Jun 15 19:12:51 2017\n" */
107-
107+
108108
efree(result);
109109

110-
``spprintf()`` returns the number of characters that've been printed into the result buffer, not counting the final
110+
``spprintf()`` returns the number of characters that've been printed into the result buffer, not counting the final
111111
*'\\0'*, hence you know the number of bytes that got allocated for you (minus one).
112112

113-
Please, note that the allocation is done using ZendMM (request allocation), and should thus be used as part of a
113+
Please, note that the allocation is done using ZendMM (request allocation), and should thus be used as part of a
114114
request and freed using ``efree()`` and not ``free()``.
115115

116-
.. note:: :doc:`The chapter about Zend Memory Manager <../../memory_management/zend_memory_manager>` (ZendMM) details
116+
.. note:: :doc:`The chapter about Zend Memory Manager <../../memory_management/zend_memory_manager>` (ZendMM) details
117117
how dynamic memory is allocated through PHP.
118118

119-
If you want to limit the buffer size, you pass that limit as the second argument, if you pass *0*, that means
119+
If you want to limit the buffer size, you pass that limit as the second argument, if you pass *0*, that means
120120
unlimited::
121121

122122
#include <time.h>
123-
123+
124124
char *result;
125125
int r;
126126

127127
time_t timestamp = time(NULL);
128128

129129
/* Do not print more than 10 bytes || allocate more than 11 bytes */
130130
r = spprintf(&result, 10, "Here is the date: %s", asctime(localtime(&timestamp)));
131-
131+
132132
/* r == 10 here, and 11 bytes were allocated into result */
133-
133+
134134
efree(result);
135135

136-
.. note:: Whenever possible, try not to use dynamic memory allocations. That impacts performances. If you got the
136+
.. note:: Whenever possible, try not to use dynamic memory allocations. That impacts performances. If you got the
137137
choice, go for the static stack allocated buffer.
138138

139-
``spprintf()`` is written in
139+
``spprintf()`` is written in
140140
`main/spprintf.c <https://github.com/php/php-src/blob/648be8600ff89e1b0e4a4ad25cebad42b53bed6d/main/spprintf.c>`_.
141141

142142
What about printf() ?
143143
---------------------
144144

145-
If you need to ``printf()``, aka to print formatted to the output stream, use ``php_printf()``. That function
146-
internally uses ``spprintf()``, and thus performs a dynamic allocation that it frees itself just after having sent it
145+
If you need to ``printf()``, aka to print formatted to the output stream, use ``php_printf()``. That function
146+
internally uses ``spprintf()``, and thus performs a dynamic allocation that it frees itself just after having sent it
147147
to the SAPI output, aka stdout in case of CLI, or the output buffer (CGI buffer f.e) for other SAPIs.
148148

149149
Special PHP printf formats
150150
--------------------------
151151

152-
Remember that PHP replaces most libc's ``printf()`` functions by its own of its own design. You can have a look at
153-
the argument parsing API which is easy to understand `from reading the source
152+
Remember that PHP replaces most libc's ``printf()`` functions by its own of its own design. You can have a look at
153+
the argument parsing API which is easy to understand `from reading the source
154154
<https://github.com/php/php-src/blob/509f5097ab0b578adc311c720afcea8de266aadd/main/spprintf.c#L203>`_.
155155

156156
What that means is that arguments parsing algo has been fully rewritten, and may differ from what you're used to in libc.
157-
F.e, the libc locale is note taken care of in most cases.
157+
F.e, the libc locale is not taken care of in most cases.
158158

159159
Special formats may be used, like *"%I64"* to explicitely print to an int64, or *"%I32"*.
160160
You can also use *"%Z"* to make a zval printable (according to PHP cast rules to string), that one is a great addition.
161161

162162
The formatter will also recognize infinite numbers and print "INF", or "NAN" for not-a-number.
163163

164-
If you make a mistake, and ask the formatter to print a ``NULL`` pointer, where libc will crash for sure, PHP will
164+
If you make a mistake, and ask the formatter to print a ``NULL`` pointer, where libc will crash for sure, PHP will
165165
return *"(null)"* as a result string.
166166

167-
.. note:: If in a printf you see a magic *"(null)"* appearing, that means you passed a NULL pointer to one of PHP
167+
.. note:: If in a printf you see a magic *"(null)"* appearing, that means you passed a NULL pointer to one of PHP
168168
printf family functions.
169169

170170

171171
Printf()ing into zend_strings
172172
-----------------------------
173173

174-
As :doc:`zend_string <zend_strings>` are a very common structure into PHP source, you may need to ``printf()`` into a
175-
``zend_string`` instead of a traditionnal C ``char *``. For this, use ``strpprintf()``.
174+
As :doc:`zend_string <zend_strings>` are a very common structure into PHP source, you may need to ``printf()`` into a
175+
``zend_string`` instead of a traditional C ``char *``. For this, use ``strpprintf()``.
176176

177-
Tha API is ``zend_string *strpprintf(size_t max_len, const char *format, ...)`` that means that the ``zend_string`` is
178-
returned to you, and not the number of printed chars as you may expect. You can limit that number though, using the
179-
first parameter (pass 0 to mean infinite); and you must remember that the ``zend_string`` will be allocated using the
177+
The API is ``zend_string *strpprintf(size_t max_len, const char *format, ...)`` that means that the ``zend_string`` is
178+
returned to you, and not the number of printed chars as you may expect. You can limit that number though, using the
179+
first parameter (pass 0 to mean infinite); and you must remember that the ``zend_string`` will be allocated using the
180180
Zend Memory Manager, and thus bound to the current request.
181181

182182
Obviously, the format API is shared with the one seen above.
183183

184184
Here is a quick example::
185185

186186
zend_string *result;
187-
187+
188188
result = strpprintf(0, "You are using PHP %s", PHP_VERSION);
189-
189+
190190
/* Do something with result */
191-
191+
192192
zend_string_release(result);
193193

194194
A note on ``zend_`` API
195195
-----------------------
196196

197197
You may meet ``zend_spprintf()``, or ``zend_strpprintf()`` functions. Those are the exact same as the ones seen above.
198198

199-
They are just here as part of the separation between the Zend Engine and PHP Core, a detail that is not important for
199+
They are just here as part of the separation between the Zend Engine and PHP Core, a detail that is not important for
200200
us, as into the source code, everything gets mixed together.
Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
smart_str API
22
=============
33

4-
That may seem strange, but the C language offers nearly nothing to play with strings (build, concatenate, shrink,
5-
expand, transform, etc...). C is a low level general purpose language one can use to build APIs to deal with more
4+
That may seem strange, but the C language offers nearly nothing to play with strings (build, concatenate, shrink,
5+
expand, transform, etc...). C is a low level general purpose language one can use to build APIs to deal with more
66
specific tasks, such as string constructions.
77

88
.. note:: Obviously you all got that we talk about ASCII strings, aka bytes. No Unicode in there.
99

1010
PHP's ``smart_str`` is an API that will help you build strings and especially concatenate chunks of bytes into strings.
11-
This API seats next to :doc:`PHP's special printf() APIs<printing_functions>` and :doc:`zend_string <zend_strings>` to
11+
This API seats next to :doc:`PHP's special printf() APIs<printing_functions>` and :doc:`zend_string <zend_strings>` to
1212
help with strings management.
1313

1414
smart_str VS smart_string
@@ -26,29 +26,29 @@ Here are the two structures::
2626
zend_string *s;
2727
size_t a;
2828
} smart_str;
29-
30-
Like you can see, one will work with traditionnal C strings (as ``char*/size_t``) and the other will make use of the
29+
30+
Like you can see, one will work with traditional C strings (as ``char*/size_t``) and the other will make use of the
3131
PHP's specific ``zend_string`` structure.
3232

33-
We will detail the later: ``smart_str``, that works with :doc:`zend_strings`. Both APIs are exactly the same, simply
34-
note that one (the one we'll detail here) starts by ``smart_str_**()`` and the other by ``smart_string_***()``. Don't
33+
We will detail the latter: ``smart_str``, that works with :doc:`zend_strings`. Both APIs are exactly the same, simply
34+
note that one (the one we'll detail here) starts by ``smart_str_**()`` and the other by ``smart_string_***()``. Don't
3535
confuse !
3636

37-
The ``smart_str`` API is detailed into `Zend/zend_smart_str.h
38-
<https://github.com/php/php-src/blob/509f5097ab0b578adc311c720afcea8de266aadd/Zend/zend_smart_str.h>`_ (also the .c
37+
The ``smart_str`` API is detailed into `Zend/zend_smart_str.h
38+
<https://github.com/php/php-src/blob/509f5097ab0b578adc311c720afcea8de266aadd/Zend/zend_smart_str.h>`_ (also the .c
3939
file).
4040

4141
.. warning:: ``smart_str`` is not to be confused with ``smart_string``.
4242

4343
Basic API usage
4444
***************
4545

46-
So far so good, that API is really easy to manage. You basically stack-allocate a ``smart_str``, and pass its pointer to
47-
``smart_str_***()`` API functions that manage the embedded ``zend_string`` for you. You build your string, use it, and
46+
So far so good, that API is really easy to manage. You basically stack-allocate a ``smart_str``, and pass its pointer to
47+
``smart_str_***()`` API functions that manage the embedded ``zend_string`` for you. You build your string, use it, and
4848
then you free it. Nothing very strong in there right ?
4949

50-
The embedded ``zend_string`` will be allocated whether
51-
:doc:`permanently or request-bound <../../memory_management/zend_memory_manager>`, that depends on the last extended API
50+
The embedded ``zend_string`` will be allocated whether
51+
:doc:`permanently or request-bound <../../memory_management/zend_memory_manager>`, that depends on the last extended API
5252
parameter you'll use::
5353

5454
smart_str my_str = {0};
@@ -66,36 +66,36 @@ parameter you'll use::
6666

6767
/* Use my_str now */
6868
PHPWRITE(ZSTR_VAL(my_str.s), ZSTR_LEN(my_str.s));
69-
69+
7070
/* Don't forget to release/free it */
7171
smart_str_free(&my_str);
7272

7373

74-
We used here the simple API, the extended one ends with ``_ex()``, and allows you to tell if you want a persistent or
74+
We used here the simple API, the extended one ends with ``_ex()``, and allows you to tell if you want a persistent or
7575
a request-bound allocation for the underlying ``zend_string``. Example::
7676

7777
smart_str my_str = {0};
78-
78+
7979
smart_str_appends_ex(&my_str, "Hello world", 1); /* 1 means persistent allocation */
8080

81-
Then, depending on what you want to append, you'll use the right API call. If you append a classical C string, you can
82-
use ``smart_str_appends(smart_str *dst, const char *src)``. If you make use of a binary string, and thus know its
81+
Then, depending on what you want to append, you'll use the right API call. If you append a classical C string, you can
82+
use ``smart_str_appends(smart_str *dst, const char *src)``. If you make use of a binary string, and thus know its
8383
length, then use ``smart_str_appendl(smart_str *dst, const char *src, size_t len)``.
8484

85-
The less specific ``smart_str_append(smart_str *dest, const zend_string *src)`` simply appends a ``zend_string`` to
86-
your ``smart_str`` string. And if you come to play with others ``smart_str``, use
85+
The less specific ``smart_str_append(smart_str *dest, const zend_string *src)`` simply appends a ``zend_string`` to
86+
your ``smart_str`` string. And if you come to play with others ``smart_str``, use
8787
``smart_str_append_smart_str(smart_str *dst, const smart_str *src)`` to combine them together.
8888

8989
smart_str specific tricks
9090
*************************
9191

92-
* Never forget to finish your string with a call to ``smart_str_0()``. That puts a *NUL* char at the end of the embed
92+
* Never forget to finish your string with a call to ``smart_str_0()``. That puts a *NUL* char at the end of the embed
9393
string and make it compatible with libc string functions.
9494
* Never forget to free your string, with ``smart_str_free()``, once you're done with it.
95-
* ``smart_str`` embeds a ``zend_string``, and then allows you to share that later elsewhere playing with its reference
95+
* ``smart_str`` embeds a ``zend_string``, and then allows you to share that later elsewhere playing with its reference
9696
counter. Please, visit the :doc:`zend_string dedicated chapter <zend_strings>` to know more about it.
9797
* You can play with ``smart_str`` allocations. Look at ``smart_str_alloc()`` and friends.
98-
* ``smart_str`` is heavilly used into PHP's heart. For example, PHP's
99-
:doc:`specific printf() functions <printing_functions>` internally use a ``smart_str`` buffer.
98+
* ``smart_str`` is heavily used into PHP's heart. For example, PHP's
99+
:doc:`specific printf() functions <printing_functions>` internally use a ``smart_str`` buffer.
100100
* ``smart_str`` is definitely an easy structure you need to master.
101101

0 commit comments

Comments
 (0)