Enlightenment CVS committal Author : pfritz Project : e17 Module : libs/ewl
Dir : e17/libs/ewl/src/lib Modified Files: ewl_misc.c ewl_macros.h ewl_debug.h Log Message: add macro to cast from pointer to int and vice versa =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_misc.c,v retrieving revision 1.112 retrieving revision 1.113 diff -u -3 -r1.112 -r1.113 --- ewl_misc.c 4 Jun 2008 20:18:27 -0000 1.112 +++ ewl_misc.c 14 Jul 2008 17:27:20 -0000 1.113 @@ -136,6 +136,26 @@ } /** + * @param ptr: the pointer to cast + * @return The integer value of the pointer + * + * This function casts a pointer into an integer. If there should be an + * information lost, i.e. the content of the pointer does not fit into + * an integer, it will print a runtime warning. + */ +int +ewl_cast_pointer_to_integer(void *ptr) +{ + DENTER_FUNCTION(DLEVEL_STABLE); + + if (sizeof(int) != sizeof(void *) + && (((unsigned long) ptr) & 0xffffffff) != 0) + DWARNING("Information lost while casting a pointer to an int"); + + DRETURN_INT((int)((long int)ptr), DLEVEL_STABLE); +} + +/** * @param argc: the argc passed into the main function * @param argv: the argv passed into the main function * @return Returns 1 or greater on success, 0 otherwise. =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_macros.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -3 -r1.14 -r1.15 --- ewl_macros.h 7 May 2008 13:38:24 -0000 1.14 +++ ewl_macros.h 14 Jul 2008 17:27:20 -0000 1.15 @@ -115,6 +115,24 @@ #endif /** + * @def PTRINT_TO_INT(x) + * Does a cast from a pointer to the type int, if debug is enabled at + * compile-time it will add a runtime check if any information get lost. + */ +#ifdef EWL_ENABLE_DEBUG +# define PTRINT_TO_INT(x) ewl_cast_pointer_to_integer(x) +#else +# define PTRINT_TO_INT(x) ((int)((long int)(x))) +#endif + +/** + * @def PRTINT_TO_INT(x) + * Does a cast from a pointer to the type int, if debug is enabled at + * compile-time it will add a runtime check if any information get lost. + */ +#define INT_TO_PTRINT(x) ((void *)((long int)(x))) + +/** * @} */ =================================================================== RCS file: /cvs/e/e17/libs/ewl/src/lib/ewl_debug.h,v retrieving revision 1.34 retrieving revision 1.35 diff -u -3 -r1.34 -r1.35 --- ewl_debug.h 7 May 2008 13:38:23 -0000 1.34 +++ ewl_debug.h 14 Jul 2008 17:27:20 -0000 1.35 @@ -14,6 +14,7 @@ void ewl_print_warning(void); void ewl_segv(void); void ewl_backtrace(void); +int ewl_cast_pointer_to_integer(void *ptr); /** * The Ewl_Config_Cache structure ------------------------------------------------------------------------- Sponsored by: SourceForge.net Community Choice Awards: VOTE NOW! Studies have shown that voting for your favorite open source project, along with a healthy diet, reduces your potential for chronic lameness and boredom. Vote Now at http://www.sourceforge.net/community/cca08 _______________________________________________ enlightenment-cvs mailing list enlightenment-cvs@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/enlightenment-cvs