Skip to content
Snippets Groups Projects
Commit 62db795a authored by Thomas Schwinge's avatar Thomas Schwinge
Browse files

GTY: Enhance 'string_length' option documentation

We're (currently) not aware of any actual use of 'ht_identifier's with NUL
characters embedded; its 'len' field appears to exist for optimization
purposes, since "forever".  Before 'struct ht_identifier' was added in
commit 2a967f3d (Subversion r42334), we had in
'gcc/cpplib.h:struct cpp_hashnode': 'unsigned short len', or earlier 'length',
earlier in 'gcc/cpphash.h:struct hashnode': 'unsigned short length', earlier
'size_t length' with comment: "length of token, for quick comparison", earlier
'int length', ever since the 'gcc/cpp*' files were added in
commit 7f2935c7 (Subversion r9191).

This amends commit f3b957ea
"pch: Fix streaming of strings with embedded null bytes".

	gcc/
	* doc/gty.texi (GTY Options) <string_length>: Enhance.
	libcpp/
	* include/symtab.h (struct ht_identifier): Document different
	rationale.
parent ee8ed948
No related branches found
No related tags found
No related merge requests found
...@@ -217,6 +217,17 @@ struct GTY(()) non_terminated_string @{ ...@@ -217,6 +217,17 @@ struct GTY(()) non_terminated_string @{
@}; @};
@end smallexample @end smallexample
Similarly, this is useful for (regular NUL-terminated) strings with
NUL characters embedded (that the default @code{strlen} use would run
afoul of):
@smallexample
struct GTY(()) multi_string @{
const char * GTY((string_length ("%h.len + 1"))) str;
size_t len;
@};
@end smallexample
The @code{string_length} option currently is not supported for (fields The @code{string_length} option currently is not supported for (fields
in) global variables. in) global variables.
@c <https://inbox.sourceware.org/87bkgqvlst.fsf@euler.schwinge.homeip.net> @c <https://inbox.sourceware.org/87bkgqvlst.fsf@euler.schwinge.homeip.net>
......
...@@ -29,9 +29,7 @@ along with this program; see the file COPYING3. If not see ...@@ -29,9 +29,7 @@ along with this program; see the file COPYING3. If not see
typedef struct ht_identifier ht_identifier; typedef struct ht_identifier ht_identifier;
typedef struct ht_identifier *ht_identifier_ptr; typedef struct ht_identifier *ht_identifier_ptr;
struct GTY(()) ht_identifier { struct GTY(()) ht_identifier {
/* This GTY markup arranges that the null-terminated identifier would still /* We know the 'len'gth of the 'str'ing; use it in the GTY markup. */
stream to PCH correctly, if a null byte were to make its way into an
identifier somehow. */
const unsigned char * GTY((string_length ("1 + %h.len"))) str; const unsigned char * GTY((string_length ("1 + %h.len"))) str;
unsigned int len; unsigned int len;
unsigned int hash_value; unsigned int hash_value;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment