implemented macro overriding for polarssl_* library functions
diff --git a/include/polarssl/check_config.h b/include/polarssl/check_config.h
index eb2fecd..818aef3 100644
--- a/include/polarssl/check_config.h
+++ b/include/polarssl/check_config.h
@@ -198,18 +198,11 @@
#error "POLARSSL_PKCS11_C defined, but not all prerequisites"
#endif
-#if defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) &&\
- !defined(POLARSSL_PLATFORM_C)
-#error "POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS defined, but not prerequisites"
-#endif
-
#if defined(POLARSSL_PLATFORM_EXIT_ALT) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_EXIT_ALT defined, but not all prerequisites"
#endif
-#if defined(POLARSSL_PLATFORM_EXIT_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+#if defined(POLARSSL_PLATFORM_EXIT_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_EXIT_MACRO defined, but not all prerequisites"
#endif
@@ -223,9 +216,7 @@
#error "POLARSSL_PLATFORM_FPRINTF_ALT defined, but not all prerequisites"
#endif
-#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_FPRINTF_MACRO defined, but not all prerequisites"
#endif
@@ -236,8 +227,7 @@
#endif
#if defined(POLARSSL_PLATFORM_FREE_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+ ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_PLATFORM_FREE_MACRO defined, but not all prerequisites"
#endif
@@ -246,9 +236,12 @@
#error "POLARSSL_PLATFORM_FREE_MACRO and POLARSSL_PLATFORM_STD_FREE cannot be defined simultaneously"
#endif
+#if defined(POLARSSL_PLATFORM_FREE_MACRO) && !defined(POLARSSL_PLATFORM_MALLOC_MACRO)
+#error "POLARSSL_PLATFORM_MALLOC_MACRO must be defined if POLARSSL_PLATFORM_FREE_MACRO is"
+#endif
+
#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+ ( !defined(POLARSSL_PLATFORM_C) || !defined(POLARSSL_PLATFORM_MEMORY) )
#error "POLARSSL_PLATFORM_MALLOC_MACRO defined, but not all prerequisites"
#endif
@@ -257,6 +250,10 @@
#error "POLARSSL_PLATFORM_MALLOC_MACRO and POLARSSL_PLATFORM_STD_MALLOC cannot be defined simultaneously"
#endif
+#if defined(POLARSSL_PLATFORM_MALLOC_MACRO) && !defined(POLARSSL_PLATFORM_FREE_MACRO)
+#error "POLARSSL_PLATFORM_FREE_MACRO must be defined if POLARSSL_PLATFORM_MALLOC_MACRO is"
+#endif
+
#if defined(POLARSSL_PLATFORM_MEMORY) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_MEMORY defined, but not all prerequisites"
#endif
@@ -265,9 +262,7 @@
#error "POLARSSL_PLATFORM_PRINTF_ALT defined, but not all prerequisites"
#endif
-#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+#if defined(POLARSSL_PLATFORM_PRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_PRINTF_MACRO defined, but not all prerequisites"
#endif
@@ -286,9 +281,7 @@
#error "POLARSSL_PLATFORM_SNPRINTF_ALT defined but not available on Windows"
#endif
-#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) &&\
- ( !defined(POLARSSL_PLATFORM_C) ||\
- !defined(POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS) )
+#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO) && !defined(POLARSSL_PLATFORM_C)
#error "POLARSSL_PLATFORM_SNPRINTF_MACRO defined, but not all prerequisites"
#endif
diff --git a/include/polarssl/config.h b/include/polarssl/config.h
index 6f13440..7425508 100644
--- a/include/polarssl/config.h
+++ b/include/polarssl/config.h
@@ -120,8 +120,14 @@
* This allows different allocators (self-implemented or provided) to be
* provided to the platform abstraction layer.
*
- * Enabling POLARSSL_PLATFORM_MEMORY will provide "platform_set_malloc_free()"
- * to allow you to set an alternative malloc() and free() function pointer.
+ * Enabling POLARSSL_PLATFORM_MEMORY without the
+ * POLARSSL_PLATFORM_{FREE,MALLOC}_MACROs will provide
+ * "platform_set_malloc_free()" allowing you to set an alternative malloc() and
+ * free() function pointer at runtime.
+ *
+ * Enabling POLARSSL_PLATFORM_MEMORY and specifying
+ * POLARSSL_PLATFORM_{MALLOC,FREE}_MACROs will allow you to specify the
+ * alternate function at compile time.
*
* Requires: POLARSSL_PLATFORM_C
*
@@ -138,7 +144,8 @@
* This makes sure there are no linking errors on platforms that do not support
* these functions. You will HAVE to provide alternatives, either at runtime
* via the platform_set_xxx() functions or at compile time by setting
- * the POLARSSL_PLATFORM_STD_XXX defines.
+ * the POLARSSL_PLATFORM_STD_XXX defines, or enabling a
+ * POLARSSL_PLATFORM_XXX_MACRO.
*
* Requires: POLARSSL_PLATFORM_C
*
@@ -148,16 +155,6 @@
//#define POLARSSL_PLATFORM_NO_STD_FUNCTIONS
/**
- * \def POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS
- *
- * TO-DO: ADD DESCRIPTION & ANY WARNINGS ETC
- *
- * Requires: POLARSSL_PLATFORM_C
- *
- */
-//#define POLARSSL_PLATFORM_ENABLE_FUNCTION_MACROS
-
-/**
* \def POLARSSL_PLATFORM_XXX_ALT
*
* Uncomment a macro to let mbed TLS support the function in the platform
@@ -172,6 +169,9 @@
* WARNING: POLARSSL_PLATFORM_SNPRINTF_ALT is not available on Windows
* for compatibility reasons.
*
+ * WARNING: POLARSSL_PLATFORM_XXX_ALT cannot be defined at the same time as
+ * POLARSSL_PLATFORM_XXX_MACRO!
+ *
* Uncomment a macro to enable alternate implementation of specific base
* platform function
*/
@@ -1907,6 +1907,10 @@
* Enable the platform abstraction layer that allows you to re-assign
* functions like malloc(), free(), snprintf(), printf(), fprintf(), exit()
*
+ * Enabling POLARSSL_PLATFORM_C enables to use of POLARSSL_PLATFORM_XXX_ALT
+ * or POLARSSL_PLATFORM_XXX_MACRO directives, allowing the functions mentioned
+ * above to be specified at runtime or compile time respectively.
+ *
* Module: library/platform.c
* Caller: Most other .c files
*
@@ -2258,6 +2262,8 @@
//#define POLARSSL_PLATFORM_STD_PRINTF printf /**< Default printf to use, can be undefined */
//#define POLARSSL_PLATFORM_STD_SNPRINTF snprintf /**< Default snprintf to use, can be undefined */
+/* To Use Function Macros POLARSSL_PLATFORM_C must be enabled */
+/* POLARSSL_PLATFORM_XXX_MACRO and POLARSSL_PLATFORM_XXX_ALT cannot both be defined */
//#define POLARSSL_PLATFORM_MALLOC_MACRO malloc /**< Default allocator macro to use, can be undefined */
//#define POLARSSL_PLATFORM_FREE_MACRO free /**< Default free macro to use, can be undefined */
//#define POLARSSL_PLATFORM_EXIT_MACRO exit /**< Default exit macro to use, can be undefined */
diff --git a/include/polarssl/platform.h b/include/polarssl/platform.h
index 1715030..dd7e558 100644
--- a/include/polarssl/platform.h
+++ b/include/polarssl/platform.h
@@ -97,43 +97,18 @@
#define polarssl_malloc malloc
#define polarssl_free free
#endif /* POLARSSL_PLATFORM_MEMORY */
-
-/*
- * The function pointers for snprintf
- */
-#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
-extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
-
-/**
- * \brief Set your own snprintf function pointer
- *
- * \param snprintf_func the snprintf function implementation
- *
- * \return 0
- */
-int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
- const char * format, ... ) );
-#else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
-#define polarssl_snprintf snprintf
-#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
-
-/*
- * The function pointers for printf
- */
-#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
-extern int (*polarssl_printf)( const char *format, ... );
-
-/**
- * \brief Set your own printf function pointer
- *
- * \param printf_func the printf function implementation
- *
- * \return 0
- */
-int platform_set_printf( int (*printf_func)( const char *, ... ) );
-#else /* POLARSSL_PLATFORM_PRINTF_ALT */
-#define polarssl_printf printf
-#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
+#else /* POLARSSL_PLATFORM_ENTROPY */
+#if defined(POLARSSL_PLATFORM_FREE_MACRO)
+#define polarssl_free POLARSSL_PLATFORM_FREE_MACRO
+#else
+#define polarssl_free free
+#endif /* POLARSSL_PLATFORM_FREE_MACRO */
+#if defined(POLARSSL_PLATFORM_MALLOC_MACRO)
+#define polarssl_malloc POLARSSL_PLATFORM_MALLOC_MACRO
+#else
+#define polarssl_malloc malloc
+#endif /* POLARSSL_PLATFORM_MALLOC_MACRO */
+#endif /* POLARSSL_PLATFORM_ENTROPY */
/*
* The function pointers for fprintf
@@ -151,10 +126,59 @@
int platform_set_fprintf( int (*fprintf_func)( FILE *stream, const char *,
... ) );
#else
+#if defined(POLARSSL_PLATFORM_FPRINTF_MACRO)
+#define polarssl_fprintf POLARSSL_PLATFORM_FPRINTF_MACRO
+#else
#define polarssl_fprintf fprintf
+#endif /* POLARSSL_PLATFORM_FPRINTF_MACRO */
#endif /* POLARSSL_PLATFORM_FPRINTF_ALT */
/*
+ * The function pointers for printf
+ */
+#if defined(POLARSSL_PLATFORM_PRINTF_ALT)
+extern int (*polarssl_printf)( const char *format, ... );
+
+/**
+ * \brief Set your own printf function pointer
+ *
+ * \param printf_func the printf function implementation
+ *
+ * \return 0
+ */
+int platform_set_printf( int (*printf_func)( const char *, ... ) );
+#else /* !POLARSSL_PLATFORM_PRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_PRINTF_MACRO)
+#define polarssl_printf POLARSSL_PLATFORM_PRINTF_MACRO
+#else
+#define polarssl_printf printf
+#endif /* POLARSSL_PLATFORM_PRINTF_MACRO */
+#endif /* POLARSSL_PLATFORM_PRINTF_ALT */
+
+/*
+ * The function pointers for snprintf
+ */
+#if defined(POLARSSL_PLATFORM_SNPRINTF_ALT)
+extern int (*polarssl_snprintf)( char * s, size_t n, const char * format, ... );
+
+/**
+ * \brief Set your own snprintf function pointer
+ *
+ * \param snprintf_func the snprintf function implementation
+ *
+ * \return 0
+ */
+int platform_set_snprintf( int (*snprintf_func)( char * s, size_t n,
+ const char * format, ... ) );
+#else /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+#if defined(POLARSSL_PLATFORM_SNPRINTF_MACRO)
+#define polarssl_snprintf POLARSSL_PLATFORM_SNPRINTF_MACRO
+#else
+#define polarssl_snprintf snprintf
+#endif /* POLARSSL_PLATFORM_SNPRINTF_MACRO */
+#endif /* POLARSSL_PLATFORM_SNPRINTF_ALT */
+
+/*
* The function pointers for exit
*/
#if defined(POLARSSL_PLATFORM_EXIT_ALT)
@@ -169,7 +193,11 @@
*/
int platform_set_exit( void (*exit_func)( int status ) );
#else
+#if defined(POLARSSL_PLATFORM_EXIT_MACRO)
+#define polarssl_exit POLARSSL_PLATFORM_EXIT_MACRO
+#else
#define polarssl_exit exit
+#endif /* POLARSSL_PLATFORM_EXIT_MACRO */
#endif /* POLARSSL_PLATFORM_EXIT_ALT */
#ifdef __cplusplus