2020-09-29 14:42:22 +00:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2019-09-25 11:13:40 +00:00
|
|
|
/*
|
2019-10-01 07:20:35 +00:00
|
|
|
* Copyright (C) 2017 Red Hat, Inc.
|
2017-03-29 16:40:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nm-default.h"
|
|
|
|
|
|
|
|
#include "nm-enum-utils.h"
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
#include "nm-str-buf.h"
|
2017-03-29 16:40:32 +00:00
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
#define IS_FLAGS_SEPARATOR(ch) (NM_IN_SET((ch), ' ', '\t', ',', '\n', '\r'))
|
|
|
|
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
static void
|
|
|
|
_ASSERT_enum_values_info(GType type, const NMUtilsEnumValueInfo *value_infos)
|
|
|
|
{
|
|
|
|
#if NM_MORE_ASSERTS > 5
|
|
|
|
nm_auto_unref_gtypeclass GTypeClass *klass = NULL;
|
|
|
|
gs_unref_hashtable GHashTable *ht = NULL;
|
|
|
|
|
|
|
|
klass = g_type_class_ref(type);
|
|
|
|
|
|
|
|
g_assert(G_IS_ENUM_CLASS(klass) || G_IS_FLAGS_CLASS(klass));
|
|
|
|
|
|
|
|
if (!value_infos)
|
|
|
|
return;
|
|
|
|
|
2018-05-30 09:44:39 +00:00
|
|
|
ht = g_hash_table_new(g_str_hash, g_str_equal);
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
|
|
|
|
for (; value_infos->nick; value_infos++) {
|
|
|
|
g_assert(value_infos->nick[0]);
|
|
|
|
|
|
|
|
/* duplicate nicks make no sense!! */
|
|
|
|
g_assert(!g_hash_table_contains(ht, value_infos->nick));
|
|
|
|
g_hash_table_add(ht, (gpointer) value_infos->nick);
|
|
|
|
|
|
|
|
if (G_IS_ENUM_CLASS(klass)) {
|
|
|
|
GEnumValue *enum_value;
|
|
|
|
|
|
|
|
enum_value = g_enum_get_value_by_nick(G_ENUM_CLASS(klass), value_infos->nick);
|
|
|
|
if (enum_value) {
|
|
|
|
/* we do allow specifying the same name via @value_infos and @type.
|
|
|
|
* That might make sense, if @type comes from a library where older versions
|
|
|
|
* of the library don't yet support the value. In this case, the caller can
|
|
|
|
* provide the nick via @value_infos, to support the older library version.
|
|
|
|
* And then, when actually running against a newer library version where
|
|
|
|
* @type knows the nick, we have this situation.
|
|
|
|
*
|
2018-06-01 10:26:07 +00:00
|
|
|
* Another reason for specifying a nick both in @value_infos and @type,
|
|
|
|
* is to specify an alias which is not used with highest preference. For
|
|
|
|
* example, if you add an alias "disabled" for "none" (both numerically
|
|
|
|
* equal), then the first alias in @value_infos will be preferred over
|
|
|
|
* the name from @type. So, to still use "none" as preferred name, you may
|
|
|
|
* explicitly specify the "none" alias in @value_infos before "disabled".
|
|
|
|
*
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
* However, what never is allowed, is to use a name (nick) to re-number
|
|
|
|
* the value. That is, if both @value_infos and @type contain a particular
|
|
|
|
* nick, their numeric values must agree as well.
|
2018-06-01 10:26:07 +00:00
|
|
|
* Allowing this, would be very confusing, because the name would have a different
|
|
|
|
* value from the regular GLib GEnum API.
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
*/
|
|
|
|
g_assert(enum_value->value == value_infos->value);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GFlagsValue *flags_value;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
flags_value = g_flags_get_value_by_nick(G_FLAGS_CLASS(klass), value_infos->nick);
|
|
|
|
if (flags_value) {
|
|
|
|
/* see ENUM case above. */
|
|
|
|
g_assert(flags_value->value == (guint) value_infos->value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
static gboolean
|
|
|
|
_is_hex_string(const char *str)
|
|
|
|
{
|
|
|
|
return str[0] == '0' && str[1] == 'x' && str[2]
|
|
|
|
&& NM_STRCHAR_ALL(&str[2], ch, g_ascii_isxdigit(ch));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_is_dec_string(const char *str)
|
|
|
|
{
|
|
|
|
return str[0] && NM_STRCHAR_ALL(&str[0], ch, g_ascii_isdigit(ch));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_enum_is_valid_enum_nick(const char *str)
|
|
|
|
{
|
|
|
|
return str[0] && !NM_STRCHAR_ANY(str, ch, g_ascii_isspace(ch)) && !_is_dec_string(str)
|
|
|
|
&& !_is_hex_string(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_enum_is_valid_flags_nick(const char *str)
|
|
|
|
{
|
|
|
|
return str[0] && !NM_STRCHAR_ANY(str, ch, IS_FLAGS_SEPARATOR(ch)) && !_is_dec_string(str)
|
|
|
|
&& !_is_hex_string(str);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
_nm_utils_enum_to_str_full(GType type,
|
|
|
|
int value,
|
2018-04-04 07:31:54 +00:00
|
|
|
const char * flags_separator,
|
|
|
|
const NMUtilsEnumValueInfo *value_infos)
|
2017-03-29 16:40:32 +00:00
|
|
|
{
|
2018-05-29 13:18:54 +00:00
|
|
|
nm_auto_unref_gtypeclass GTypeClass *klass = NULL;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
_ASSERT_enum_values_info(type, value_infos);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
if (flags_separator
|
|
|
|
&& (!flags_separator[0] || NM_STRCHAR_ANY(flags_separator, ch, !IS_FLAGS_SEPARATOR(ch))))
|
|
|
|
g_return_val_if_reached(NULL);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
klass = g_type_class_ref(type);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
if (G_IS_ENUM_CLASS(klass)) {
|
2017-03-29 16:40:32 +00:00
|
|
|
GEnumValue *enum_value;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-04-04 07:31:54 +00:00
|
|
|
for (; value_infos && value_infos->nick; value_infos++) {
|
|
|
|
if (value_infos->value == value)
|
|
|
|
return g_strdup(value_infos->nick);
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
enum_value = g_enum_get_value(G_ENUM_CLASS(klass), value);
|
2017-03-29 16:40:32 +00:00
|
|
|
if (!enum_value || !_enum_is_valid_enum_nick(enum_value->value_nick))
|
2018-04-04 07:31:54 +00:00
|
|
|
return g_strdup_printf("%d", value);
|
2017-03-29 16:40:32 +00:00
|
|
|
else
|
2018-04-04 07:31:54 +00:00
|
|
|
return g_strdup(enum_value->value_nick);
|
2018-05-29 13:18:54 +00:00
|
|
|
} else if (G_IS_FLAGS_CLASS(klass)) {
|
2017-03-29 16:40:32 +00:00
|
|
|
unsigned uvalue = (unsigned) value;
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
GFlagsValue *flags_value;
|
|
|
|
NMStrBuf strbuf;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
flags_separator = flags_separator ?: " ";
|
2020-09-28 14:03:33 +00:00
|
|
|
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
nm_str_buf_init(&strbuf, 16, FALSE);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-04-04 07:31:54 +00:00
|
|
|
for (; value_infos && value_infos->nick; value_infos++) {
|
|
|
|
nm_assert(_enum_is_valid_flags_nick(value_infos->nick));
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-04-04 07:31:54 +00:00
|
|
|
if (uvalue == 0) {
|
|
|
|
if (value_infos->value != 0)
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
if (!NM_FLAGS_ALL(uvalue, (unsigned) value_infos->value))
|
|
|
|
continue;
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
if (strbuf.len)
|
|
|
|
nm_str_buf_append(&strbuf, flags_separator);
|
|
|
|
nm_str_buf_append(&strbuf, value_infos->nick);
|
2018-04-04 07:31:54 +00:00
|
|
|
uvalue &= ~((unsigned) value_infos->value);
|
|
|
|
if (uvalue == 0) {
|
|
|
|
/* we printed all flags. Done. */
|
|
|
|
goto flags_done;
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
do {
|
2018-05-29 13:18:54 +00:00
|
|
|
flags_value = g_flags_get_first_value(G_FLAGS_CLASS(klass), uvalue);
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
if (strbuf.len)
|
|
|
|
nm_str_buf_append(&strbuf, flags_separator);
|
2017-03-29 16:40:32 +00:00
|
|
|
if (!flags_value || !_enum_is_valid_flags_nick(flags_value->value_nick)) {
|
|
|
|
if (uvalue)
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
nm_str_buf_append_printf(&strbuf, "0x%x", uvalue);
|
2017-03-29 16:40:32 +00:00
|
|
|
break;
|
|
|
|
}
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
nm_str_buf_append(&strbuf, flags_value->value_nick);
|
2017-03-29 16:40:32 +00:00
|
|
|
uvalue &= ~flags_value->value;
|
|
|
|
} while (uvalue);
|
|
|
|
|
2018-04-04 07:31:54 +00:00
|
|
|
flags_done:
|
shared: use NMStrBuf in _nm_utils_enum_to_str_full()
Just for showcase and to hit the code from the unit-tests
that we have.
Also, just to show, the following runs about 25 % faster than before,
which isn't bad for such a simple replacement.
{
GType gtype = nm_test_general_color_flags_get_type ();
const int N_RUN = 1000000;
int i_run;
guint8 c = 0;
for (i_run = 0; i_run < N_RUN; i_run++) {
gs_free char *str = NULL;
str = _nm_utils_enum_to_str_full (gtype, i_run % 10, ",", NULL);
c += str[0];
}
return c % 3;
}
$ perf stat -r 200 -B libnm-core/tests/test-general
Before:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
204.48 msec task-clock:u # 0.997 CPUs utilized ( +- 0.53% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
267 page-faults:u # 0.001 M/sec ( +- 0.05% )
702,987,494 cycles:u # 3.438 GHz ( +- 0.54% )
1,698,874,415 instructions:u # 2.42 insn per cycle ( +- 0.00% )
410,394,229 branches:u # 2006.970 M/sec ( +- 0.00% )
1,770,484 branch-misses:u # 0.43% of all branches ( +- 0.40% )
0.20502 +- 0.00108 seconds time elapsed ( +- 0.53% )
After:
Performance counter stats for 'libnm-core/tests/test-general' (200 runs):
155.71 msec task-clock:u # 0.996 CPUs utilized ( +- 0.50% )
0 context-switches:u # 0.000 K/sec
0 cpu-migrations:u # 0.000 K/sec
266 page-faults:u # 0.002 M/sec ( +- 0.05% )
539,994,118 cycles:u # 3.468 GHz ( +- 0.49% )
1,116,016,733 instructions:u # 2.07 insn per cycle ( +- 0.00% )
283,974,158 branches:u # 1823.760 M/sec ( +- 0.00% )
1,377,786 branch-misses:u # 0.49% of all branches ( +- 0.43% )
0.156255 +- 0.000786 seconds time elapsed ( +- 0.50% )
2018-11-14 15:42:27 +00:00
|
|
|
return nm_str_buf_finalize(&strbuf, NULL);
|
2018-04-04 07:31:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_return_val_if_reached(NULL);
|
2017-03-29 16:40:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-29 16:56:01 +00:00
|
|
|
static const NMUtilsEnumValueInfo *
|
|
|
|
_find_value_info(const NMUtilsEnumValueInfo *value_infos, const char *needle)
|
|
|
|
{
|
|
|
|
if (value_infos) {
|
|
|
|
for (; value_infos->nick; value_infos++) {
|
|
|
|
if (nm_streq(needle, value_infos->nick))
|
|
|
|
return value_infos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
_nm_utils_enum_from_str_full(GType type,
|
|
|
|
const char * str,
|
|
|
|
int * out_value,
|
|
|
|
char ** err_token,
|
|
|
|
const NMUtilsEnumValueInfo *value_infos)
|
2017-03-29 16:40:32 +00:00
|
|
|
{
|
2019-08-09 06:53:05 +00:00
|
|
|
nm_auto_unref_gtypeclass GTypeClass *klass = NULL;
|
2017-03-29 16:40:32 +00:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
int value = 0;
|
|
|
|
gs_free char * str_clone = NULL;
|
|
|
|
char * s;
|
|
|
|
gint64 v64;
|
2017-03-29 16:56:01 +00:00
|
|
|
const NMUtilsEnumValueInfo * nick;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
g_return_val_if_fail(str, FALSE);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
_ASSERT_enum_values_info(type, value_infos);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
str_clone = strdup(str);
|
|
|
|
s = nm_str_skip_leading_spaces(str_clone);
|
|
|
|
g_strchomp(s);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
klass = g_type_class_ref(type);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
if (G_IS_ENUM_CLASS(klass)) {
|
2017-03-29 16:40:32 +00:00
|
|
|
GEnumValue *enum_value;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
if (s[0]) {
|
|
|
|
if (_is_hex_string(s)) {
|
|
|
|
v64 = _nm_utils_ascii_str_to_int64(s, 16, 0, G_MAXUINT, -1);
|
|
|
|
if (v64 != -1) {
|
|
|
|
value = (int) v64;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
} else if (_is_dec_string(s)) {
|
|
|
|
v64 = _nm_utils_ascii_str_to_int64(s, 10, 0, G_MAXUINT, -1);
|
|
|
|
if (v64 != -1) {
|
|
|
|
value = (int) v64;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
} else if ((nick = _find_value_info(value_infos, s))) {
|
|
|
|
value = nick->value;
|
|
|
|
ret = TRUE;
|
|
|
|
} else if ((enum_value = g_enum_get_value_by_nick(G_ENUM_CLASS(klass), s))) {
|
|
|
|
value = enum_value->value;
|
|
|
|
ret = TRUE;
|
2017-03-29 16:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-29 13:18:54 +00:00
|
|
|
} else if (G_IS_FLAGS_CLASS(klass)) {
|
2017-03-29 16:40:32 +00:00
|
|
|
GFlagsValue *flags_value;
|
|
|
|
unsigned uvalue = 0;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
ret = TRUE;
|
|
|
|
while (s[0]) {
|
|
|
|
char *s_end;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
for (s_end = s; s_end[0]; s_end++) {
|
|
|
|
if (IS_FLAGS_SEPARATOR(s_end[0])) {
|
|
|
|
s_end[0] = '\0';
|
|
|
|
s_end++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
if (s[0]) {
|
|
|
|
if (_is_hex_string(s)) {
|
|
|
|
v64 = _nm_utils_ascii_str_to_int64(&s[2], 16, 0, G_MAXUINT, -1);
|
|
|
|
if (v64 == -1) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uvalue |= (unsigned) v64;
|
|
|
|
} else if (_is_dec_string(s)) {
|
|
|
|
v64 = _nm_utils_ascii_str_to_int64(s, 10, 0, G_MAXUINT, -1);
|
|
|
|
if (v64 == -1) {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
uvalue |= (unsigned) v64;
|
shared: don't allow aliases re-numbering in _nm_utils_enum_from_str_full()
For _nm_utils_enum_to_str_full(), we always first look whether we have
an alias/nick for the numeric value, and preferably use that. That makes a
lot of sense, as it allows the caller to provide better names (aliases),
which are preferred over the name from the GLib type. It renames the
numeric value.
For the reverse conversion, this makes less sense. A name should have a
unique numeric value. That is, we should not use one name that maps to
a different numeric value based on value_infos and GLib type. IOW, we
should not re-number names.
Add an assertion that we don't provide such a value_infos parameter,
that conflicts with names from GLib type.
Also, although the case where GLib type and value_infos disagree is now
forbidden by an assert, reorder the statements in _nm_utils_enum_from_str_full()
too. There is no difference in practice, but it mirros what we do in the
to-str case.
2018-05-29 11:21:06 +00:00
|
|
|
} else if ((nick = _find_value_info(value_infos, s)))
|
|
|
|
uvalue |= (unsigned) nick->value;
|
|
|
|
else if ((flags_value = g_flags_get_value_by_nick(G_FLAGS_CLASS(klass), s)))
|
|
|
|
uvalue |= flags_value->value;
|
|
|
|
else {
|
|
|
|
ret = FALSE;
|
|
|
|
break;
|
2017-03-29 16:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
s = s_end;
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
value = (int) uvalue;
|
|
|
|
} else
|
|
|
|
g_return_val_if_reached(FALSE);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
NM_SET_OUT(err_token, !ret && s[0] ? g_strdup(s) : NULL);
|
|
|
|
NM_SET_OUT(out_value, ret ? value : 0);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-04-05 16:32:23 +00:00
|
|
|
const char **
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 05:40:19 +00:00
|
|
|
_nm_utils_enum_get_values(GType type, int from, int to)
|
2017-03-29 16:40:32 +00:00
|
|
|
{
|
2018-05-29 13:18:54 +00:00
|
|
|
GTypeClass *klass;
|
2017-03-29 16:40:32 +00:00
|
|
|
GPtrArray * array;
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 05:40:19 +00:00
|
|
|
int i;
|
2017-03-29 16:40:32 +00:00
|
|
|
char sbuf[64];
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
klass = g_type_class_ref(type);
|
2017-03-29 16:40:32 +00:00
|
|
|
array = g_ptr_array_new();
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
if (G_IS_ENUM_CLASS(klass)) {
|
|
|
|
GEnumClass *enum_class = G_ENUM_CLASS(klass);
|
2017-03-29 16:40:32 +00:00
|
|
|
GEnumValue *enum_value;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
for (i = 0; i < enum_class->n_values; i++) {
|
|
|
|
enum_value = &enum_class->values[i];
|
|
|
|
if (enum_value->value >= from && enum_value->value <= to) {
|
|
|
|
if (_enum_is_valid_enum_nick(enum_value->value_nick))
|
|
|
|
g_ptr_array_add(array, (gpointer) enum_value->value_nick);
|
|
|
|
else
|
|
|
|
g_ptr_array_add(
|
|
|
|
array,
|
|
|
|
(gpointer) g_intern_string(nm_sprintf_buf(sbuf, "%d", enum_value->value)));
|
|
|
|
}
|
|
|
|
}
|
2018-05-29 13:18:54 +00:00
|
|
|
} else if (G_IS_FLAGS_CLASS(klass)) {
|
|
|
|
GFlagsClass *flags_class = G_FLAGS_CLASS(klass);
|
2017-03-29 16:40:32 +00:00
|
|
|
GFlagsValue *flags_value;
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
for (i = 0; i < flags_class->n_values; i++) {
|
|
|
|
flags_value = &flags_class->values[i];
|
2017-04-27 16:01:58 +00:00
|
|
|
if (flags_value->value >= (guint) from && flags_value->value <= (guint) to) {
|
2017-03-29 16:40:32 +00:00
|
|
|
if (_enum_is_valid_flags_nick(flags_value->value_nick))
|
|
|
|
g_ptr_array_add(array, (gpointer) flags_value->value_nick);
|
|
|
|
else
|
|
|
|
g_ptr_array_add(
|
|
|
|
array,
|
|
|
|
(gpointer) g_intern_string(
|
|
|
|
nm_sprintf_buf(sbuf, "0x%x", (unsigned) flags_value->value)));
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
}
|
2017-03-29 16:40:32 +00:00
|
|
|
} else {
|
2018-05-29 13:18:54 +00:00
|
|
|
g_type_class_unref(klass);
|
2017-03-29 16:40:32 +00:00
|
|
|
g_ptr_array_free(array, TRUE);
|
|
|
|
g_return_val_if_reached(NULL);
|
|
|
|
}
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2018-05-29 13:18:54 +00:00
|
|
|
g_type_class_unref(klass);
|
2017-03-29 16:40:32 +00:00
|
|
|
g_ptr_array_add(array, NULL);
|
2020-09-28 14:03:33 +00:00
|
|
|
|
2017-03-29 16:40:32 +00:00
|
|
|
return (const char **) g_ptr_array_free(array, FALSE);
|
|
|
|
}
|