Skip to content

Simplify using g_type_class_peek() #4594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 11 additions & 24 deletions libvips/iofuncs/operation.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,14 +292,9 @@ vips_operation_class_usage_classify(VipsArgumentClass *argument_class)
/* Display a set of flags as "a:b:c"
*/
static void
vips__flags_to_str(VipsBuf *buf, GType type, guint value)
vips__flags_to_str(VipsBuf *buf, GFlagsClass *flags, guint value)
{
GTypeClass *class = g_type_class_ref(type);
GFlagsClass *flags = G_FLAGS_CLASS(class);

gboolean first;

first = TRUE;
gboolean first = TRUE;
for (int i = 0; i < flags->n_values; i++)
// can't be 0 (would match everything), and all bits
// should match all bits in the value, or "all" would always match
Expand All @@ -321,18 +316,14 @@ vips_operation_pspec_usage(VipsBuf *buf, GParamSpec *pspec)
/* These are the pspecs that vips uses that have interesting values.
*/
if (G_IS_PARAM_SPEC_ENUM(pspec)) {
GTypeClass *class = g_type_class_ref(type);
/* GParamSpecEnum holds a ref on the class so we just peek.
*/
GEnumClass *genum = g_type_class_peek(type);
GParamSpecEnum *pspec_enum = (GParamSpecEnum *) pspec;

GEnumClass *genum;
int i;

/* Should be impossible, no need to warn.
*/
if (!class)
return;

genum = G_ENUM_CLASS(class);
g_assert(genum);

vips_buf_appendf(buf, "\t\t\t");
vips_buf_appendf(buf, "%s", _("default enum"));
Expand All @@ -351,23 +342,19 @@ vips_operation_pspec_usage(VipsBuf *buf, GParamSpec *pspec)
vips_buf_appendf(buf, "\n");
}
if (G_IS_PARAM_SPEC_FLAGS(pspec)) {
GTypeClass *class = g_type_class_ref(type);
/* GParamSpecFlags holds a ref on the class so we just peek.
*/
GFlagsClass *gflags = g_type_class_peek(type);
GParamSpecFlags *pspec_flags = (GParamSpecFlags *) pspec;

GFlagsClass *gflags;
int i;

/* Should be impossible, no need to warn.
*/
if (!class)
return;

gflags = G_FLAGS_CLASS(class);
g_assert(gflags);

vips_buf_appendf(buf, "\t\t\t");
vips_buf_appendf(buf, "%s", _("default flags"));
vips_buf_appendf(buf, ": ");
vips__flags_to_str(buf, type, pspec_flags->default_value);
vips__flags_to_str(buf, gflags, pspec_flags->default_value);
vips_buf_appendf(buf, "\n");
vips_buf_appendf(buf, "\t\t\t");
vips_buf_appendf(buf, "%s", _("allowed flags"));
Expand Down
12 changes: 4 additions & 8 deletions tools/vips.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,13 @@ list_operation_arg(VipsObjectClass *object_class,
/* These are the pspecs that vips uses that have interesting values.
*/
if (G_IS_PARAM_SPEC_ENUM(pspec)) {
GTypeClass *class = g_type_class_ref(type);
/* GParamSpecEnum holds a ref on the class so we just peek.
*/
GEnumClass *genum = g_type_class_peek(type);

GEnumClass *genum;
int i;

/* Should be impossible, no need to warn.
*/
if (!class)
return NULL;

genum = G_ENUM_CLASS(class);
g_assert(genum);

printf("word:");

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy