Control: severity -1 wishlist
Control: retitle -1 dpkg: Please refactor code to make filenamenode usage less 
confusing

Hi!

On Sat, 2014-05-03 at 13:49:29 +0200, Michael Tautschnig wrote:
> Package: dpkg
> Version: 1.17.9
> Usertags: goto-cc

[…]

> While this appears to be consistent, "struct filenamenode" actually refers to
> different structs:
> 
> struct filenamenode {
>   struct filenamenode * next;
>   const char * name;
>   struct pkg_list * packages;
>   struct diversion * divert;
>   struct file_stat * statoverride;
>   int flags;
>   const char * oldhash;
>   const char * newhash;
>   struct stat * filestat;
>   struct trigfileint * trig_interested;
> }
> 
> vs.
> 
> struct filenamenode {
>   struct filenamenode * next;
>   const char * name;
>   struct trigfileint * trig_interested;
> }

Yes, this is something I've been meaning to finish cleaning up as it
is very confusing for first-time readers of the code base, it goes
against my set of best practices, and it's prone to future errors if
forgotten. It was this way to avoid having to pull the entire filesdb
code (and its dependencies) into the dpkg-trigger command.

> Using one in place of the other appears to be dangerous at best,
> but may also be entirely broken.

This is actually fine, as you will notice the «struct filenamenode»
is only ever accessed inside triglib.c through the hooks, any other
function in that module only handles struct filenamenode pointers.

The code that actually uses the real «struct filenamenode» overrides
the hooks through trig_override_hooks().

Thanks,
Guillem


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to