@@ -230,6 +230,17 @@ typedef int (*secp256k1_nonce_function)(
230
230
# define SECP256K1_DEPRECATED (_msg )
231
231
#endif
232
232
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
+
233
244
/* All flags' lower 8 bits indicate what they're for. Do not use directly. */
234
245
#define SECP256K1_FLAGS_TYPE_MASK ((1 << 8) - 1)
235
246
#define SECP256K1_FLAGS_TYPE_CONTEXT (1 << 0)
@@ -325,7 +336,15 @@ SECP256K1_API void secp256k1_selftest(void);
325
336
*/
326
337
SECP256K1_API secp256k1_context * secp256k1_context_create (
327
338
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
+ ;
329
348
330
349
/** Copy a secp256k1 context object (into dynamically allocated memory).
331
350
*
@@ -341,7 +360,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_create(
341
360
*/
342
361
SECP256K1_API secp256k1_context * secp256k1_context_clone (
343
362
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
+ ;
345
372
346
373
/** Destroy a secp256k1 context object (created in dynamically allocated memory).
347
374
*
@@ -359,7 +386,15 @@ SECP256K1_API secp256k1_context *secp256k1_context_clone(
359
386
*/
360
387
SECP256K1_API void secp256k1_context_destroy (
361
388
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
+ ;
363
398
364
399
/** Set a callback function to be called when an illegal argument is passed to
365
400
* an API call. It will only trigger for violations that are mentioned
@@ -442,7 +477,14 @@ SECP256K1_API void secp256k1_context_set_error_callback(
442
477
SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space * secp256k1_scratch_space_create (
443
478
const secp256k1_context * ctx ,
444
479
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
+ ;
446
488
447
489
/** Destroy a secp256k1 scratch space.
448
490
*
@@ -453,7 +495,14 @@ SECP256K1_API SECP256K1_WARN_UNUSED_RESULT secp256k1_scratch_space *secp256k1_sc
453
495
SECP256K1_API void secp256k1_scratch_space_destroy (
454
496
const secp256k1_context * ctx ,
455
497
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
+ ;
457
506
458
507
/** Parse a variable-length public key into the pubkey object.
459
508
*
0 commit comments