Jan Engelhardt writes:
 > Hi,
 > 
 > 
 > I notice that dbi_result is currently typedefed to be a void*.
 > This is rather bad, because if the library user screws up while 
 > refactoring his dbi-using code (and that's almost a given),
 > compilers will not generate a warning because void* is implicitly 
 > convertible to other pointer types. For example,
 >  dbi_conn derp = dbi_conn_query(...)
 > 
 > To solve this, you have to declare, in dbi.h:
 > 
 > -typedef void * dbi_inst;
 > -typedef void * dbi_driver;
 > -typedef void * dbi_conn;  
 > -typedef void * dbi_result;
 > +typedef struct _dbi_inst *dbi_inst;
 > +typedef struct _dbi_driver *dbi_driver;
 > +typedef struct _dbi_conn *dbi_conn;
 > +typedef struct _dbi_result *dbi_result;
 > 
 > Then, the types cannot be mixed anymore, which is really what
 > is wanted.
 > 

Hi,

I concur with your analysis, but I'm afraid we need a more thorough
overhaul of the headers. If I apply your suggested patch, I receive
lots of build warnings along the lines of:

dbi_main.c: In function 'dbi_driver_list_r':
dbi_main.c:302: warning: initialization from incompatible pointer type
dbi_main.c: In function 'dbi_driver_open_r':
dbi_main.c:322: warning: return from incompatible pointer type

The reason appears to be that libdbi does use typedef structs for
pointers to drivers, connections, results and the like. These are
defined in dbi-dev.h, e.g.

typedef struct dbi_driver_s {
        void *dlhandle;
        [... more stuff ...]
} dbi_driver_t;

Problem is that dbi-dev.h is not available to dbi.h whereas dbi-dev.h
includes dbi.h. I don't know why this layout was chosen in the
first place. Except for the sheer length of the resulting file it
should not harm to unite the contents of both headers into a single
file. It is just a bit suspicious that dbi-dev.h bends over backwards
to avoid compiler warnings by using fake definitions of structs. This
seems to be necessary as some structs include other structs which may
create circular dependencies otherwise.

Can anyone else remember or infer why the headers are separate?

regards,
Markus

-- 
Markus Hoenicka
http://www.mhoenicka.de
AQ score 38

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk
_______________________________________________
Libdbi-drivers-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/libdbi-drivers-devel

Reply via email to