<feed xmlns='http://www.w3.org/2005/Atom'>
<title>unit.git, branch str-v4</title>
<subtitle>Universal Web Application Server</subtitle>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/'/>
<entry>
<title>Added nxt_usts2str() to make C strings from nxt_str_t.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@nginx.com</email>
</author>
<published>2022-10-27T11:22:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=e25c63995d5d52bcbd9c51c5f9ff14cb30bacf6b'/>
<id>e25c63995d5d52bcbd9c51c5f9ff14cb30bacf6b</id>
<content type='text'>
This function is identical to nxt_ustr2str(), except that it takes
a nxt_str_t structure as input, instead of a 'u_char *' and a size.

The documentation of the function:

/*
 * SYNOPSIS
 *      void nxt_usts2str(char dst[restrict .src-&gt;length+1],
 *                        const nxt_str_t *restrict src);
 *
 * ARGUMENTS
 *      dst     Pointer to the first byte of the destination buffer.
 *      src     Pointer to the source Unterminated STring Structure.
 *
 * DESCRIPTION
 *      Copy a string from the source nxt_str_t, which may be
 *      not-NUL-terminated, into a NUL-terminated string in the
 *      destination buffer.
 *
 * CAVEATS
 *      If the destination buffer is not wider than the source buffer
 *      at least by 1 byte, the behavior is undefined.
 *
 * EXAMPLES
 *      nxt_str_t  src = nxt_string("0123456789");
 *      char       dst[src.length + 1];
 *
 *      nxt_usts2str(dst, &amp;src);
 *
 * SEE ALSO
 *      ustr2str(3), strlcpy(3), strscpy(9)
 */

Suggested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This function is identical to nxt_ustr2str(), except that it takes
a nxt_str_t structure as input, instead of a 'u_char *' and a size.

The documentation of the function:

/*
 * SYNOPSIS
 *      void nxt_usts2str(char dst[restrict .src-&gt;length+1],
 *                        const nxt_str_t *restrict src);
 *
 * ARGUMENTS
 *      dst     Pointer to the first byte of the destination buffer.
 *      src     Pointer to the source Unterminated STring Structure.
 *
 * DESCRIPTION
 *      Copy a string from the source nxt_str_t, which may be
 *      not-NUL-terminated, into a NUL-terminated string in the
 *      destination buffer.
 *
 * CAVEATS
 *      If the destination buffer is not wider than the source buffer
 *      at least by 1 byte, the behavior is undefined.
 *
 * EXAMPLES
 *      nxt_str_t  src = nxt_string("0123456789");
 *      char       dst[src.length + 1];
 *
 *      nxt_usts2str(dst, &amp;src);
 *
 * SEE ALSO
 *      ustr2str(3), strlcpy(3), strscpy(9)
 */

Suggested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Added nxt_ustr2str() to make C strings from fixed-width buffers.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@nginx.com</email>
</author>
<published>2022-10-25T16:42:52+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=a0c0126b3b616fb2a0cf252c51300455f7899ba3'/>
<id>a0c0126b3b616fb2a0cf252c51300455f7899ba3</id>
<content type='text'>
This function makes it easy to transform a fixed-width buffer
(which is how we represent strings in Unit most of the time) into
a proper C string (NUL-terminated).  We need to do this when
interfacing libraries or the kernel, where most APIs expect
NUL-terminated strings.

The implementation is similar to strncpy_s(3), but avoids the
unnecessary runtime checks.  It's better to wrap the function in a
macro and do as many static_assert(3)s as one considers necessary;
in fact, if in the future C allows backwards VLA syntax, static
analysis could be better than those static_assert(3)s.

We use char for NUL-terminated strings, and u_char for the
*u*nterminated strings.

The documentation for the function:

/*
 * SYNOPSIS
 *   void ustr2str(char dst[restrict .n+1],
 *                 const u_char src[restrict .n],
 *                 size_t n);
 *
 * ARGUMENTS
 *	dst	Pointer to the first byte of the destination buffer.
 *	src	Pointer to the first byte of the source string.
 *	n	Size of 'src'.
 *
 * DESCRIPTION
 *	Copy a string from the fixed-width source string, which may be
 *	not-NUL-terminated, into a NUL-terminated string in the
 *	destination buffer.
 *
 * CAVEATS
 *	If the destination buffer is not wider than the source buffer
 *	at least by 1 byte, the behavior is undefined.
 *
 *	Use of this function normally indicates a problem in the design
 *	of the strings, since normally it's better to guarantee that all
 *	strings are properly terminated.  The main use for this function
 *	is to interface with some standard buffers, such as those
 *	defined in utmp(7), which for historical reasons are not
 *	guaranteed to be terminated.
 *
 * EXAMPLES
 *	u_char  src[10] = "0123456789";  // not NUL-terminated
 *	char    dst[sizeof(src) + 1];
 *
 *	static_assert(lengthof(src) &lt; lengthof(dst))
 *	ustr2str(dst, src, lengthof(src));
 *
 * SEE ALSO
 *	nxt_sts2str(3), strlcpy(3), strscpy(9)
 */

Cc: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This function makes it easy to transform a fixed-width buffer
(which is how we represent strings in Unit most of the time) into
a proper C string (NUL-terminated).  We need to do this when
interfacing libraries or the kernel, where most APIs expect
NUL-terminated strings.

The implementation is similar to strncpy_s(3), but avoids the
unnecessary runtime checks.  It's better to wrap the function in a
macro and do as many static_assert(3)s as one considers necessary;
in fact, if in the future C allows backwards VLA syntax, static
analysis could be better than those static_assert(3)s.

We use char for NUL-terminated strings, and u_char for the
*u*nterminated strings.

The documentation for the function:

/*
 * SYNOPSIS
 *   void ustr2str(char dst[restrict .n+1],
 *                 const u_char src[restrict .n],
 *                 size_t n);
 *
 * ARGUMENTS
 *	dst	Pointer to the first byte of the destination buffer.
 *	src	Pointer to the first byte of the source string.
 *	n	Size of 'src'.
 *
 * DESCRIPTION
 *	Copy a string from the fixed-width source string, which may be
 *	not-NUL-terminated, into a NUL-terminated string in the
 *	destination buffer.
 *
 * CAVEATS
 *	If the destination buffer is not wider than the source buffer
 *	at least by 1 byte, the behavior is undefined.
 *
 *	Use of this function normally indicates a problem in the design
 *	of the strings, since normally it's better to guarantee that all
 *	strings are properly terminated.  The main use for this function
 *	is to interface with some standard buffers, such as those
 *	defined in utmp(7), which for historical reasons are not
 *	guaranteed to be terminated.
 *
 * EXAMPLES
 *	u_char  src[10] = "0123456789";  // not NUL-terminated
 *	char    dst[sizeof(src) + 1];
 *
 *	static_assert(lengthof(src) &lt; lengthof(dst))
 *	ustr2str(dst, src, lengthof(src));
 *
 * SEE ALSO
 *	nxt_sts2str(3), strlcpy(3), strscpy(9)
 */

Cc: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Workarounded Ruby bug.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@nginx.com</email>
</author>
<published>2022-10-28T00:36:33+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=270f45d5c737d0f62978bdfec1803677d0f3e6c1'/>
<id>270f45d5c737d0f62978bdfec1803677d0f3e6c1</id>
<content type='text'>
Ruby redefines memcpy(3) in public headers.  Or at least they did until
they fixed it 4 months ago.  We need to undefine their broken definition.

Link: &lt;https://bugs.ruby-lang.org/issues/18893&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Ruby redefines memcpy(3) in public headers.  Or at least they did until
they fixed it 4 months ago.  We need to undefine their broken definition.

Link: &lt;https://bugs.ruby-lang.org/issues/18893&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Added nxt_char_cast() macro for casting safely.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@kernel.org</email>
</author>
<published>2022-11-11T23:48:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=4c7e1ee46506cdb63523b04a828fbdaa73743ddf'/>
<id>4c7e1ee46506cdb63523b04a828fbdaa73743ddf</id>
<content type='text'>
This macro is similar to C++'s static_cast().  It allows a very-limited
set of casts to be performed, but rejects most casts.  Basically, it
only allows converting from char to u_char and vice-versa, while
respecting the const qualifier.

/*
 * SYNOPSIS
 *      type char_cast(type, string);
 *
 * ARGUMENTS
 *      type    Type to which 'string' should be cast.
 *      string  String that should be cast to 'type'.  It should be a
 *              pointer, or a pointer to a pointer, to a character type,
 *              possibly const-qualified.
 *
 * DESCRIPTION
 *      This macro resembles C++'s static_cast().  It performs a cast,
 *      as if '(type) string' was written, but it performs additional
 *      checks that make sure the cast is limited to character types,
 *      that the input expression is also of a character type, and that
 *      it doesn't remove a const qualifier.
 *
 *      It also makes it easier to find all casts easily with grep(1).
 *
 * CAVEATS
 *      It doesn't allow using 'volatile'.  However, this isn't a big
 *      issue, since we don't use it with strings.  If necessary, the
 *      macro can be improved to support volatile.
 *
 * EXAMPLES
 *      int         *ip = &amp;i;
 *      char        *s = "foo";
 *      const char  *cs = "bar";
 *
 *      p = (char *) s;             /* OK.  Although unsafe, because it
 *                                     can be confused with the case in
 *                                     the next line. */
 *      p = (char *) cs;            /* Very unsafe; it will probably
 *                                     result in Undefined Behaviour. */
 *
 *      p = char_cast(char *, s);   // OK.
 *      p = char_cast(char *, cs);  // Compiler error.  Cast not allowed.
 *
 *      p = (const char *) s;       // OK.
 *      p = (const char *) cs;      // OK.
 *
 *      p = char_cast(const char *, s);   // OK.
 *      p = char_cast(const char *, cs);  // OK.
 *
 *      p = (int *) cs;             /* Extremely unsafe; it will almost
 *                                     certainly result in Undefined
 *                                     Behaviour. */
 *      p = char_cast(int *, cs);   // Compiler error.  Cast not allowed.
 *
 *      p = (char *) ip;            /* Technically OK, but probably
 *                                     not what you want. */
 *      p = char_cast(char *, ip);  // Compiler error.  Cast not allowed.
 *
 * SEE ALSO
 *      _Generic(3)
 */

Acked-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
This macro is similar to C++'s static_cast().  It allows a very-limited
set of casts to be performed, but rejects most casts.  Basically, it
only allows converting from char to u_char and vice-versa, while
respecting the const qualifier.

/*
 * SYNOPSIS
 *      type char_cast(type, string);
 *
 * ARGUMENTS
 *      type    Type to which 'string' should be cast.
 *      string  String that should be cast to 'type'.  It should be a
 *              pointer, or a pointer to a pointer, to a character type,
 *              possibly const-qualified.
 *
 * DESCRIPTION
 *      This macro resembles C++'s static_cast().  It performs a cast,
 *      as if '(type) string' was written, but it performs additional
 *      checks that make sure the cast is limited to character types,
 *      that the input expression is also of a character type, and that
 *      it doesn't remove a const qualifier.
 *
 *      It also makes it easier to find all casts easily with grep(1).
 *
 * CAVEATS
 *      It doesn't allow using 'volatile'.  However, this isn't a big
 *      issue, since we don't use it with strings.  If necessary, the
 *      macro can be improved to support volatile.
 *
 * EXAMPLES
 *      int         *ip = &amp;i;
 *      char        *s = "foo";
 *      const char  *cs = "bar";
 *
 *      p = (char *) s;             /* OK.  Although unsafe, because it
 *                                     can be confused with the case in
 *                                     the next line. */
 *      p = (char *) cs;            /* Very unsafe; it will probably
 *                                     result in Undefined Behaviour. */
 *
 *      p = char_cast(char *, s);   // OK.
 *      p = char_cast(char *, cs);  // Compiler error.  Cast not allowed.
 *
 *      p = (const char *) s;       // OK.
 *      p = (const char *) cs;      // OK.
 *
 *      p = char_cast(const char *, s);   // OK.
 *      p = char_cast(const char *, cs);  // OK.
 *
 *      p = (int *) cs;             /* Extremely unsafe; it will almost
 *                                     certainly result in Undefined
 *                                     Behaviour. */
 *      p = char_cast(int *, cs);   // Compiler error.  Cast not allowed.
 *
 *      p = (char *) ip;            /* Technically OK, but probably
 *                                     not what you want. */
 *      p = char_cast(char *, ip);  // Compiler error.  Cast not allowed.
 *
 * SEE ALSO
 *      _Generic(3)
 */

Acked-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Added NXT_HAVE_C11_GENERIC.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@kernel.org</email>
</author>
<published>2022-11-11T23:41:15+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=d0f5370f343a7786a1ab5d0325aa90518695662c'/>
<id>d0f5370f343a7786a1ab5d0325aa90518695662c</id>
<content type='text'>
Test if _Generic(3) is available.  Although we require GNU C11, some
old compilers, like the one in CentOS 7 still don't have full support
for C11, and _Generic(3) is not available there.

Acked-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Test if _Generic(3) is available.  Although we require GNU C11, some
old compilers, like the one in CentOS 7 still don't have full support
for C11, and _Generic(3) is not available there.

Acked-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Requiring GNU C11.</title>
<updated>2022-11-16T12:09:18+00:00</updated>
<author>
<name>Alejandro Colomar</name>
<email>alx@nginx.com</email>
</author>
<published>2022-10-27T23:49:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=ba919b7350eb79a08192c01b3db63973003da85c'/>
<id>ba919b7350eb79a08192c01b3db63973003da85c</id>
<content type='text'>
Suggested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Suggested-by: Andrew Clayton &lt;a.clayton@nginx.com&gt;
Signed-off-by: Alejandro Colomar &lt;alx@nginx.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>Tests: fixed _check_processes() checks in "--restart" mode.</title>
<updated>2022-11-15T01:07:41+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-11-15T01:07:41+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=9ea5ed2813c7dc57c8997ef21d779baae19d784c'/>
<id>9ea5ed2813c7dc57c8997ef21d779baae19d784c</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Tests: removed migration test.</title>
<updated>2022-11-15T00:56:49+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-11-15T00:56:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=bb11ef694ce49343a11bafee836addb6dd125848'/>
<id>bb11ef694ce49343a11bafee836addb6dd125848</id>
<content type='text'>
Migration of "share" behaviour was dropped after b57b4749b993.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Migration of "share" behaviour was dropped after b57b4749b993.
</pre>
</div>
</content>
</entry>
<entry>
<title>Tests: fixed assertion in test_variables_dynamic.</title>
<updated>2022-11-15T00:42:12+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-11-15T00:42:12+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=2c2156e236c18a67922617a4e43fb9eb1da0ab9e'/>
<id>2c2156e236c18a67922617a4e43fb9eb1da0ab9e</id>
<content type='text'>
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
</pre>
</div>
</content>
</entry>
<entry>
<title>Tests: features and options checks improved.</title>
<updated>2022-11-15T00:39:21+00:00</updated>
<author>
<name>Andrei Zeliankou</name>
<email>zelenkov@nginx.com</email>
</author>
<published>2022-11-15T00:39:21+00:00</published>
<link rel='alternate' type='text/html' href='https://git.sigsegv.uk/unit.git/commit/?id=0d3b31e6710afe4348eb25f1602f5271c92b9a77'/>
<id>0d3b31e6710afe4348eb25f1602f5271c92b9a77</id>
<content type='text'>
Now version output evaluates only once.
OpenSSL checks more carefully.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Now version output evaluates only once.
OpenSSL checks more carefully.
</pre>
</div>
</content>
</entry>
</feed>
