diff --git a/include/secp256k1.h b/include/secp256k1.h index ce065f1d57..0763213cc8 100644 --- a/include/secp256k1.h +++ b/include/secp256k1.h @@ -220,6 +220,17 @@ typedef int (*secp256k1_nonce_function)( # define SECP256K1_DEPRECATED(_msg) #endif +/* Attribute for marking functions, types, and variables as deprecated */ +#if !defined(SECP256K1_BUILD) && defined(__has_attribute) +# if __has_attribute(__unavailable__) +# define SECP256K1_UNAVAILABLE(_msg) __attribute__ ((__unavailable__(_msg))) +# else +# define SECP256K1_UNAVAILABLE(_msg) +# endif +#else +# define SECP256K1_UNAVAILABLE(_msg) +#endif + /* All flags' lower 8 bits indicate what they're for. Do not use directly. */ #define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1) #define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0) @@ -315,7 +326,15 @@ SECP256K1_API void secp256k1_selftest(void); */ SECP256K1_API secp256k1_context *secp256k1_context_create( unsigned int flags -) SECP256K1_WARN_UNUSED_RESULT; +) SECP256K1_WARN_UNUSED_RESULT +#if !SECP256K1_HAVE_STDLIB_H +SECP256K1_UNAVAILABLE( + "Needs malloc/free but seems unavailable on this platform, " + "see secp256k1_prealloc.h for alternatives. " + "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)" +) +#endif +; /** Copy a secp256k1 context object (into dynamically allocated memory). * @@ -331,7 +350,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_create( */ SECP256K1_API secp256k1_context *secp256k1_context_clone( const secp256k1_context *ctx -) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT; +) SECP256K1_ARG_NONNULL(1) SECP256K1_WARN_UNUSED_RESULT +#if !SECP256K1_HAVE_STDLIB_H +SECP256K1_UNAVAILABLE( + "Needs malloc/free but seems unavailable on this platform, " + "see secp256k1_prealloc.h for alternatives. " + "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)" +) +#endif +; /** Destroy a secp256k1 context object (created in dynamically allocated memory). * @@ -349,7 +376,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_clone( */ SECP256K1_API void secp256k1_context_destroy( secp256k1_context *ctx -) SECP256K1_ARG_NONNULL(1); +) SECP256K1_ARG_NONNULL(1) +#if !SECP256K1_HAVE_STDLIB_H +SECP256K1_UNAVAILABLE( + "Needs malloc/free but seems unavailable on this platform, " + "see secp256k1_prealloc.h for alternatives. " + "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)" +) +#endif +; /** Set a callback function to be called when an illegal argument is passed to * an API call. It will only trigger for violations that are mentioned @@ -432,7 +467,14 @@ SECP256K1_API void secp256k1_context_set_error_callback( SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_scratch_space_create( const secp256k1_context *ctx, size_t size -) SECP256K1_ARG_NONNULL(1); +) SECP256K1_ARG_NONNULL(1) +#if !SECP256K1_HAVE_STDLIB_H +SECP256K1_UNAVAILABLE( + "Needs malloc/free but seems unavailable on this platform. " + "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)" +) +#endif +; /** Destroy a secp256k1 scratch space. * @@ -443,7 +485,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_sc SECP256K1_API void secp256k1_scratch_space_destroy( const secp256k1_context *ctx, secp256k1_scratch_space *scratch -) SECP256K1_ARG_NONNULL(1); +) SECP256K1_ARG_NONNULL(1) +#if !SECP256K1_HAVE_STDLIB_H +SECP256K1_UNAVAILABLE( + "Needs malloc/free but seems unavailable on this platform. " + "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)" +) +#endif +; /** Parse a variable-length public key into the pubkey object. *