Bug 39759

Summary: remove dead code that is only compiled when tests are enabled
Product: dbus Reporter: Simon McVittie <smcv>
Component: coreAssignee: Simon McVittie <smcv>
Status: RESOLVED FIXED QA Contact: John (J5) Palmieri <johnp>
Severity: normal    
Priority: medium CC: hp, lennart
Version: 1.5Keywords: patch
Hardware: Other   
OS: All   
URL: http://cgit.freedesktop.org/~smcv/dbus/log/?h=remove-test-only-code-39759
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 36164    
Attachments: _dbus_string_append_unichar, _dbus_string_get_unichar: remove
_dbus_string_append_double, _dbus_string_parse_double: remove
_dbus_getgid: remove, unused
Remove unused _dbus_string_append_4_aligned, _dbus_string_append_8_aligned
_dbus_header_field_to_string: remove, unused
_dbus_list_insert_before: remove, unused
_dbus_list_pop_last_link: remove, unused
DBUS_HASH_TWO_STRINGS, DBUS_HASH_POINTER: remove, unused
_dbus_connection_queue_received_message: remove, unused
[1/3] _dbus_list_pop_last_link: remove, unused
[2/3] _dbus_string_append_unichar, _dbus_string_get_unichar: remove
[3/3] _dbus_string_append_double, _dbus_string_parse_double: remove

Description Simon McVittie 2011-08-02 05:03:14 UTC
Various features of libdbus are neither externally-accessible nor used internally. At the moment, they're compiled if and only if DBUS_BUILD_TESTS is defined.

Some of these functions are obvious generalizations of things we do use (_dbus_list_pop_last_link, _dbus_list_insert_before), but most are just unnecessary.

If we find that we do need some of these things, we can get them back from git history by reverting their removal.
Comment 1 Simon McVittie 2011-08-02 05:15:29 UTC
Created attachment 49828 [details] [review]
_dbus_string_append_unichar, _dbus_string_get_unichar: remove

These are unused (except by their regression test!) and not visible to
external callers.
Comment 2 Simon McVittie 2011-08-02 05:15:34 UTC
Created attachment 49829 [details] [review]
_dbus_string_append_double, _dbus_string_parse_double: remove

They're unused, except by their own regression tests.
Comment 3 Simon McVittie 2011-08-02 05:15:39 UTC
Created attachment 49830 [details] [review]
_dbus_getgid: remove, unused
Comment 4 Simon McVittie 2011-08-02 05:15:44 UTC
Created attachment 49831 [details] [review]
Remove unused _dbus_string_append_4_aligned, _dbus_string_append_8_aligned
Comment 5 Simon McVittie 2011-08-02 05:15:48 UTC
Created attachment 49832 [details] [review]
_dbus_header_field_to_string: remove, unused
Comment 6 Simon McVittie 2011-08-02 05:15:54 UTC
Created attachment 49833 [details] [review]
_dbus_list_insert_before: remove, unused
Comment 7 Simon McVittie 2011-08-02 05:16:01 UTC
Created attachment 49834 [details] [review]
_dbus_list_pop_last_link: remove, unused
Comment 8 Simon McVittie 2011-08-02 05:16:07 UTC
Created attachment 49835 [details] [review]
DBUS_HASH_TWO_STRINGS, DBUS_HASH_POINTER: remove, unused
Comment 9 Simon McVittie 2011-08-02 05:16:14 UTC
Created attachment 49836 [details] [review]
_dbus_connection_queue_received_message: remove, unused
Comment 10 Lennart Poettering 2012-02-09 13:24:19 UTC
All look good to me.

(I have some doubts though that anybody would look for these bits in the git history though later on, but that shouldn't stop us from deleting dead code.)

(As a side note, how did you determine the dead code? Any tool you can recommend?)
Comment 11 Simon McVittie 2012-02-10 06:27:29 UTC
(In reply to comment #10)
> (As a side note, how did you determine the dead code? Any tool you can recommend?)

In this particular case I determined it by looking for things that were #ifdef DBUS_BUILD_TESTS, but were not actually tests.

In general I use `git grep` and intuition - "does this function look hopelessly obscure? is it interfering with maintenance? let's see if we can delete it".
Comment 12 Simon McVittie 2012-02-10 07:01:21 UTC
Created attachment 56869 [details] [review]
[1/3] _dbus_list_pop_last_link: remove, unused

---

With some changes to the test-case to avoid a gcc "assigned but unused" warning.
Comment 13 Simon McVittie 2012-02-10 07:02:04 UTC
Created attachment 56870 [details] [review]
[2/3] _dbus_string_append_unichar, _dbus_string_get_unichar:  remove

These are unused (except by their regression test!) and not visible to
external callers.

---

Now without unused variables in the test.
Comment 14 Simon McVittie 2012-02-10 07:02:32 UTC
Created attachment 56871 [details] [review]
[3/3] _dbus_string_append_double, _dbus_string_parse_double:  remove

They're unused, except by their own regression tests.

----

Now without unused variables.
Comment 15 Simon McVittie 2012-02-10 07:03:25 UTC
(In reply to comment #10)
> All look good to me.

Thanks, I applied the ones that didn't cause new compiler warnings when I rebased them, and fixed the three that did (see attached).
Comment 16 Lennart Poettering 2012-02-10 12:04:18 UTC
(In reply to comment #15)
> (In reply to comment #10)
> > All look good to me.
> 
> Thanks, I applied the ones that didn't cause new compiler warnings when I rebased them, and fixed the three that did (see attached).

These look good to me, still.
Comment 17 Simon McVittie 2012-02-13 10:23:47 UTC
Fixed in git for 1.5.10, thanks for reviewing

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.