Repository navigation
Fix #15179 (gtk.cfg: Complete and sort G_DEFINE_* list) - #8991
Conversation
|
FYI there is this ticket regarding G_DEFINE_TYPE: https://trac.cppcheck.net/ticket/10890 |
I've never seen warnings like these when running cppcheck on the Xfce codebase (which makes extensive use of G_DEFINE_TYPE). I'm inclined to believe that the problem stems from the code in question, which is using this macro incorrectly. |
|
Can you add test code using (some of) the new macros in gtk.c? |
c855854 to
977dcde
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no correctness problems. The reordering keeps every existing G_DEFINE_* define unchanged: I compared the sorted name lists of base and PR, and the only difference is the six new defines. The updated test/cfg/gtk.c passes, and it does exercise the new G_DEFINE_ENUM_TYPE, G_DEFINE_FLAGS_TYPE and G_DEFINE_ENUM_VALUE defines: with the base gtk.cfg it fails with unknownMacro.
There are two minor points, neither a blocker:
G_DEFINE_EXTENDED_ERROR,G_DEFINE_POINTER_TYPEandG_DEFINE_POINTER_TYPE_WITH_CODEhave no test code in gtk.c.- Because
G_DEFINE_EXTENDED_ERRORexpands to nothing, the user's<error_type>_private_init/_copy/_clearfunctions getunusedFunctionwith--enable=all.G_DEFINE_TYPEalready does the same thing to*_class_init/*_init, so this matches the existing approach.
Testing
- Built
cppcheckfrompr/. - Ran the gtk.c cfg test with the options from
test/cfg/runtests.sh(--check-library --platform=unix64 --enable=style,information --inconclusive --force --check-level=exhaustive --inline-suppr --debug-warnings --suppress=checkersReport --library=gtk test/cfg/gtk.c): no output, exit code 0. There is no pkg-config or GTK in the container, so the compiler syntax check of gtk.c was skipped. - Ran the same check on the PR's gtk.c with
--library=../base/cfg/gtk.cfg. It fails withgtk.c:684: unknownMacro ... G_DEFINE_ENUM_TYPE, so the new test covers the change. - Compared the sorted
G_DEFINE_*names in base and PR gtk.cfg: the only difference is the six added defines, so none was lost in the reorder. - Wrote a scratch file that uses
G_DEFINE_EXTENDED_ERROR(MyError, my_error)with staticmy_error_private_init/copy/clearfunctions, plusG_DEFINE_POINTER_TYPEandG_DEFINE_POINTER_TYPE_WITH_CODE. It parses with no syntax or unknownMacro errors. With--enable=all, the three private functions getunusedFunction. AG_DEFINE_TYPEfile withw_class_init/w_initgives the same warning for those two functions, so this behaviour was already there before the PR.
Automated review of 977dcde by Claude. The pull request was built and tested locally.
| <define name="G_DEFINE_DYNAMIC_TYPE_EXTENDED(TN, t_n, T_P, _f_, _C_)" value=""/> | ||
| <define name="G_DEFINE_ENUM_TYPE(TypeName, type_name, ...)" value=""/> | ||
| <define name="G_DEFINE_ENUM_VALUE(EnumValue, EnumNick)" value=""/> | ||
| <define name="G_DEFINE_EXTENDED_ERROR(ErrorType, error_type)" value=""/> |
There was a problem hiding this comment.
AI review
Minor: the real G_DEFINE_EXTENDED_ERROR calls the user-written <error_type>_private_init, _private_copy and _private_clear functions. Because this define expands to nothing, --enable=unusedFunction reports all three as never used. G_DEFINE_TYPE already has the same problem with *_class_init/*_init, so this is consistent and not a blocker. It might still be worth a line in gtk.c, together with the G_DEFINE_POINTER_TYPE* defines, which also have no test yet.
|
This pull request has merge conflicts that must be resolved. |
Added: G_DEFINE_ENUM_TYPE G_DEFINE_ENUM_VALUE G_DEFINE_EXTENDED_ERROR G_DEFINE_FLAGS_TYPE G_DEFINE_POINTER_TYPE G_DEFINE_POINTER_TYPE_WITH_CODE
977dcde to
59cabea
Compare
dmcppcheck
left a comment
There was a problem hiding this comment.
AI review
I found no new problems. The earlier AI review already raised the only gaps I saw: G_DEFINE_EXTENDED_ERROR, G_DEFINE_POINTER_TYPE and G_DEFINE_POINTER_TYPE_WITH_CODE have no test code, and the empty expansion leads to unusedFunction reports.
The new gtk.c code passes the cfg check, and every inline suppression in it is used. The G_DEFINE_ENUM_TYPE/G_DEFINE_ENUM_VALUE block runs under --force even though GLIB_CHECK_VERSION is not defined in gtk.cfg, so the new test does cover those defines. The reordered define list has no duplicate names and loses no define. All defines pass the gcc -Werror syntax check that runtests.sh does.
The PR currently has merge conflicts, which was reported earlier.
Testing
- Built
cppcheckinpr/; the build succeeded. - Ran the cfg test with the options from
test/cfg/runtests.sh:
./cppcheck --check-library --platform=unix64 --enable=style,information --inconclusive --force --check-level=exhaustive --inline-suppr --debug-warnings --suppress=checkersReport --library=gtk -q test/cfg/gtk.c
It printed nothing and exited with 0, so there were no unmatched suppressions. - Ran it again without
--forceand with-DGLIB_CHECK_VERSION(a,b,c)=1: no output. - Ran the PR's
gtk.cagainst the basegtk.cfg. It givesgtk.c:716:1: error: ... G_DEFINE_ENUM_TYPE ... [unknownMacro], which shows the new test covers the change. - Took every
<define>fromgtk.cfgwith a Python XML parser, wrote them out as#definelines and rangcc -fsyntax-only -xc -Werroron them. This copiescheck_defines_syntax; I used Python because xmlstarlet and xmllint are not installed. The check passed, and there are no duplicate define names. - Not tested:
- The compiler syntax check of
gtk.c, because GTK and pkg-config are not available in the container. - The RelaxNG validation of
gtk.cfg, because xmllint is not installed.
- The compiler syntax check of
Automated review of 59cabea by Claude. The pull request was built and tested locally.
Added:
G_DEFINE_ENUM_TYPE
G_DEFINE_ENUM_VALUE
G_DEFINE_EXTENDED_ERROR
G_DEFINE_FLAGS_TYPE
G_DEFINE_POINTER_TYPE
G_DEFINE_POINTER_TYPE_WITH_CODE