Opened 10 months ago

Last modified 10 months ago

#1361 new defect/bug

item.priv_data type causes confusion

Reported by: mvglasow (2) Owned by: mvglasow (2)
Priority: minor Milestone: version 0.5.2
Component: core Version: git master
Severity: normal Keywords:
Cc:

Description

Currently, the priv_data member of struct item is of type void *, allowing map providers to tack any kind of data to their items. Consequently, the following function prototypes take a void * argument:

item_attr_get()
item_attr_rewind()
item_coord_get()
item_coord_rewind()

To add to the confusion, some map providers (notably route and route graph) tack the map rect's private data (a struct map_rect_priv) to each item. Thus, by examining the code, it is very easy to get confused about what is passed in the first argument of the above functions. Also, there doesn't really seem to be a convenient place to document function prototypes to be implemented by another dev.

Suggestion: change the type of priv_data to struct item_priv * and declare it as an incomplete type, to be implemented independently by each map provider.

Map providers who maintain item-specific private structs could then use this type.

If a map provider decides to stick a different struct to their items (as route.c does), this could be solved either by an explicit cast (though that's ugly) or, more elegantly, by doing:

typedef struct item_priv {
    struct map_rect_priv mr_priv;
}

which would be backward-comptaible with existing code.

Not a major issue—Navit still runs, but devs of future map plugins will likely appreciate the clarification (would have saved me a good deal of debugging).

Assigning to myself; I'll take care of it once my current traffic project approaches completion.

Change History (1)

comment:1 Changed 10 months ago by mvglasow (2)

  • Component changed from CI to core
  • Owner changed from jkoan to mvglasow (2)
Note: See TracTickets for help on using tickets.