On Mon, 23 Aug 2010 14:30:12 -0500
Kent Yoder <[email protected]> wrote:

> How about this:
> 
> #define LOG_ERR(string_num)           st_err_log(string_num, __FILE__, 
> __LINE__)
> 
> enum {
>   ERR_MALLOC_FAILED=0,
>   ERR_NOT_ENOUGH_MEM_IN_CTX,
>   ...
> }
> 
> So
> 
> st_err_log(0, __FILE__, __LINE__);
> 
> becomes
> 
> LOG_ERR(ERR_MALLOC_FAILED);
> 
> This shouldn't increase the size of the binary at all, but is readable and 
> continues to log everything we currently log.  There will be 3 special cases 
> though, where the string in err_msg[] takes an argument.  Let me know what 
> you think.
> 
> Thanks,
> Kent

In case you're working on this, just a suggestion that in case you're
using both an enum and a static table to hold the codes and meanings
respectively, I think we can use a trick to have it more readable (and
maintainable) in the code:

enum {
  ERR_MALLOC_FAILED=0,
  ERR_NOT_ENOUGH_MEM_IN_CTX,
  ...
}

const char* code_map[] = {
  [ERR_MALLOC_FAILED] = "Malloc Failed",
  [ERR_NOT_ENOUGH_MEM_IN_CTX] = "Not enough context memory"
  ...
}

(I don't know if gcc would actually allow assigning table entries out
of their numerical order, but the above at least seems to work)

 -Klaus



-- 
Klaus Heinrich Kiwi | [email protected] | http://blog.klauskiwi.com
Open Source Security blog :     http://www.ratliff.net/blog
IBM Linux Technology Center :   http://www.ibm.com/linux/ltc

------------------------------------------------------------------------------
Sell apps to millions through the Intel(R) Atom(Tm) Developer Program
Be part of this innovative community and reach millions of netbook users 
worldwide. Take advantage of special opportunities to increase revenue and 
speed time-to-market. Join now, and jumpstart your future.
http://p.sf.net/sfu/intel-atom-d2d
_______________________________________________
Opencryptoki-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opencryptoki-tech

Reply via email to