Skip to content

[th/check-patch-priv] contrib: discourage g_type_class_add_private() via "checkpatch.pl"

Thomas Haller requested to merge th/check-patch-priv into main

Our GObject structs should be internal API. In which case, we should embed the private data in the struct themselves (_priv) and use the _NM_GET_PRIVATE() macro. The advantage is better debugability because following G_TYPE_INSTANCE_GET_PRIVATE() in the debugger is very cumbersome. Another (less relevant) advantage is better performance.

Thus, warn about uses of g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE().

Note that if the struct and is in a header file (which is usually only necessary when subclassing the type), then the private data should be an opaque pointer _priv instead, and we should use the _NM_GET_PRIVATE_PTR() macro. In that case, the use of g_type_class_add_private() and G_TYPE_INSTANCE_GET_PRIVATE() is correct and the warning is false. But this is only a warning, for the unusual case where we have deep object hierarchies.

Merge request reports