debug: don't crash if an object is NULL in wp_*_object() and point it out in the log

by using G_TYPE_NONE (== 1), we can pass this in the log handler
to point out the fact that we expected something but it's null

As a bonus, a null object always gets printed in red because that's
the first color in object_colors
This commit is contained in:
George Kiagiadakis
2020-05-20 18:27:09 +03:00
parent a54ff34863
commit b807b666a0
2 changed files with 14 additions and 14 deletions

View File

@@ -287,7 +287,7 @@ wp_log_writer_default (GLogLevelFlags log_level,
}
/* format the message to include the object */
if (cf.object && cf.message) {
if (cf.object_type && cf.message) {
cf.message_field->value = cf.message = full_message =
format_message (&cf);
}
@@ -331,14 +331,14 @@ wp_log_structured_standard (
n_fields++;
}
if (object != NULL) {
if (object_type != 0) {
fields[n_fields].key = "WP_OBJECT_TYPE";
fields[n_fields].value = &object_type;
fields[n_fields].length = sizeof (GType);
n_fields++;
}
if (object_type != 0) {
fields[n_fields].key = "WP_OBJECT_TYPE";
fields[n_fields].value = &object_type;
fields[n_fields].length = sizeof (GType);
n_fields++;
}
if (object != NULL) {
fields[n_fields].key = "WP_OBJECT";
fields[n_fields].value = &object;
fields[n_fields].length = sizeof (gconstpointer);