[freetds] _DB_GETCOLINFO whacked

ZIGLIO, Frediano, VF-IT Frediano.Ziglio at vodafone.com
Mon Dec 3 05:02:41 EST 2007


> 
> I removed the _DB_GETCOLINFO macro, replacing it with a function
> dbcolptr().  The macro had gotten too complicated and wasn't 
> all that well
> conceived to begin with.  
> 
> In general I think it's a bad idea for macros to have side 
> effects.  This
> one required two variables to be declared, so it could assign 
> them, and
> contained return statements in case its checks turned up an error.  I
> didn't think "get column info" suggested "exit if you can't".  
> 
> The new function calls dbperror() for you and returns the 
> error code, so
> the caller can decide what to do next.  It takes the address of a
> TDSCOLUMN pointer, which is sets.  I think it makes what's going on a
> little clearer.  
> 


Yes, was quite complicated... however I would prefer if dbcolptr returns
TDSCOLUM* directly... of course cause it's better optimized!! Passing a
pointer to pointer means that compiler have to allocate space in memory
to pass the buffer while returning directly a pointer compiler can (and
probably do) return a register. Also you can use a macro that don't have
side effects like

#define _DB_GETCOLINFO(fail) \
	do { if ((colinfo = dbcolptr(dbproc, column)) == NULL) return
(fail); } while(0)

(or just inline it on every call...)

freddy77


More information about the FreeTDS mailing list