@@ -230,6 +230,17 @@ typedef int (*secp256k1_nonce_function)(
230230# define SECP256K1_DEPRECATED (_msg )
231231#endif
232232
233+ /* Attribute for marking functions, types, and variables as unavailable */
234+ #if !defined(SECP256K1_BUILD ) && defined(__has_attribute )
235+ # if __has_attribute (__unavailable__ )
236+ # define SECP256K1_UNAVAILABLE (_msg ) __attribute__ ((__unavailable__(_msg)))
237+ # else
238+ # define SECP256K1_UNAVAILABLE (_msg )
239+ # endif
240+ #else
241+ # define SECP256K1_UNAVAILABLE (_msg )
242+ #endif
243+
233244/* All flags' lower 8 bits indicate what they're for. Do not use directly. */
234245#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
235246#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
@@ -325,7 +336,15 @@ SECP256K1_API void secp256k1_selftest(void);
325336 */
326337SECP256K1_API secp256k1_context * secp256k1_context_create (
327338 unsigned int flags
328- ) SECP256K1_WARN_UNUSED_RESULT ;
339+ ) SECP256K1_WARN_UNUSED_RESULT
340+ #if !SECP256K1_HAVE_STDLIB_H
341+ SECP256K1_UNAVAILABLE (
342+ "Needs malloc/free but <stdlib.h> seems unavailable on this platform, "
343+ "see secp256k1_prealloc.h for alternatives. "
344+ "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)"
345+ )
346+ #endif
347+ ;
329348
330349/** Copy a secp256k1 context object (into dynamically allocated memory).
331350 *
@@ -341,7 +360,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_create(
341360 */
342361SECP256K1_API secp256k1_context * secp256k1_context_clone (
343362 const secp256k1_context * ctx
344- ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_WARN_UNUSED_RESULT ;
363+ ) SECP256K1_ARG_NONNULL (1 ) SECP256K1_WARN_UNUSED_RESULT
364+ #if !SECP256K1_HAVE_STDLIB_H
365+ SECP256K1_UNAVAILABLE (
366+ "Needs malloc/free but <stdlib.h> seems unavailable on this platform, "
367+ "see secp256k1_prealloc.h for alternatives. "
368+ "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)"
369+ )
370+ #endif
371+ ;
345372
346373/** Destroy a secp256k1 context object (created in dynamically allocated memory).
347374 *
@@ -359,7 +386,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_clone(
359386 */
360387SECP256K1_API void secp256k1_context_destroy (
361388 secp256k1_context * ctx
362- ) SECP256K1_ARG_NONNULL (1 );
389+ ) SECP256K1_ARG_NONNULL (1 )
390+ #if !SECP256K1_HAVE_STDLIB_H
391+ SECP256K1_UNAVAILABLE (
392+ "Needs malloc/free but <stdlib.h> seems unavailable on this platform, "
393+ "see secp256k1_prealloc.h for alternatives. "
394+ "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)"
395+ )
396+ #endif
397+ ;
363398
364399/** Set a callback function to be called when an illegal argument is passed to
365400 * an API call. It will only trigger for violations that are mentioned
@@ -442,7 +477,14 @@ SECP256K1_API void secp256k1_context_set_error_callback(
442477SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space * secp256k1_scratch_space_create (
443478 const secp256k1_context * ctx ,
444479 size_t size
445- ) SECP256K1_ARG_NONNULL (1 );
480+ ) SECP256K1_ARG_NONNULL (1 )
481+ #if !SECP256K1_HAVE_STDLIB_H
482+ SECP256K1_UNAVAILABLE (
483+ "Needs malloc/free but <stdlib.h> seems unavailable on this platform. "
484+ "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)"
485+ )
486+ #endif
487+ ;
446488
447489/** Destroy a secp256k1 scratch space.
448490 *
@@ -453,7 +495,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_sc
453495SECP256K1_API void secp256k1_scratch_space_destroy (
454496 const secp256k1_context * ctx ,
455497 secp256k1_scratch_space * scratch
456- ) SECP256K1_ARG_NONNULL (1 );
498+ ) SECP256K1_ARG_NONNULL (1 )
499+ #if !SECP256K1_HAVE_STDLIB_H
500+ SECP256K1_UNAVAILABLE (
501+ "Needs malloc/free but <stdlib.h> seems unavailable on this platform. "
502+ "(#define SECP256K1_HAVE_STDLIB_H 1 to override.)"
503+ )
504+ #endif
505+ ;
457506
458507/** Parse a variable-length public key into the pubkey object.
459508 *
0 commit comments