Commit dfcec18
authored
gtk.cfg: Remove pure annotation from g_str_has_prefix/suffix (#8788)
`g_str_has_prefix` and `g_str_has_suffix` are not technically pure
because they can log to the console if a precondition fails.
This partially reverts commit 7cc7c0b.
---
Some notes:
The original `gtk.cfg` change hasn't been released yet, so the revert
shouldn't cause any churn for users.
GLib has code like this:
```c
gboolean (g_str_has_prefix) (const gchar *str,
const gchar *prefix)
{
g_return_val_if_fail (str != NULL, FALSE);
g_return_val_if_fail (prefix != NULL, FALSE);
return strncmp (str, prefix, strlen (prefix)) == 0;
}
```
Most real-world code is treating this function as safe to call inside of
an assert, even though it could technically have side effects if one of
the preconditions fails.
I removed the pure annotation to err on the side of correctness and
pedantry, even though most projects would view the warnings as "false
positives" from a practical perspective.
Here is example usage from QEMU:
```c
char *qemu_chr_get_filename(Chardev *chr)
{
ChardevClass *cc = CHARDEV_GET_CLASS(chr);
const char *typename;
if (cc->chr_get_filename) {
return cc->chr_get_filename(chr);
}
typename = object_get_typename(OBJECT(chr));
assert(g_str_has_prefix(typename, "chardev-"));
return g_strdup(typename + 8);
}
```1 parent b1b7e3c commit dfcec18
2 files changed
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5221 | 5221 | | |
5222 | 5222 | | |
5223 | 5223 | | |
5224 | | - | |
5225 | 5224 | | |
5226 | 5225 | | |
5227 | 5226 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
62 | 66 | | |
| 67 | + | |
63 | 68 | | |
| 69 | + | |
64 | 70 | | |
65 | 71 | | |
66 | 72 | | |
| |||
0 commit comments