Skip to content

Commit baa2654

Browse files
Merge #1727: docs: Clarify that callback can be called more than once
4d90585 docs: Improve API docs of _context_set_illegal_callback (Tim Ruffing) 895f53d docs: Clarify that callback can be called more than once (Tim Ruffing) Pull request description: The tests in #1698 reminded me that some functions, e.g., `secp256k1_ec_pubkey_cmp`, may call the illegal callback more than once (see #1390 (comment) for more context). This PR clarifies the API docs to state explicitly that this is possible. This is the simplest solution. Any production code should crash anyway if it encounters a callback. And in debug code or in our test code, it doesn't really matter whether you see an error message once or twice. The alternative is to provide a guarantee that the callback is called only once. But that would make our code more complex for no good reason. The second commit fixes a few typos, wording, and consistency. ACKs for top commit: stratospher: ACK 4d90585. theStack: re-ACK 4d90585 Tree-SHA512: 97c31d68851e845b21e9ec2530432603917c019580feba98b62014b538f61be94ba963bf619217720d8f7331ac830e97e62c76c02e7297d3cf73dd085e6f4ca2
2 parents de6af6a + 4d90585 commit baa2654

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

include/secp256k1.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ SECP256K1_DEPRECATED("Use secp256k1_context_static instead");
261261
* secp256k1_context_create (or secp256k1_context_preallocated_create), which will
262262
* take care of performing the self tests.
263263
*
264-
* If the tests fail, this function will call the default error handler to abort the
264+
* If the tests fail, this function will call the default error callback to abort the
265265
* program (see secp256k1_context_set_error_callback).
266266
*/
267267
SECP256K1_API void secp256k1_selftest(void);
@@ -334,36 +334,37 @@ SECP256K1_API void secp256k1_context_destroy(
334334
* an API call. It will only trigger for violations that are mentioned
335335
* explicitly in the header.
336336
*
337-
* The philosophy is that these shouldn't be dealt with through a
338-
* specific return value, as calling code should not have branches to deal with
339-
* the case that this code itself is broken.
337+
* The philosophy is that these shouldn't be dealt with through a specific
338+
* return value, as calling code should not have branches to deal with the case
339+
* that this code itself is broken.
340340
*
341341
* On the other hand, during debug stage, one would want to be informed about
342-
* such mistakes, and the default (crashing) may be inadvisable.
343-
* When this callback is triggered, the API function called is guaranteed not
344-
* to cause a crash, though its return value and output arguments are
345-
* undefined.
346-
*
347-
* When this function has not been called (or called with fn==NULL), then the
348-
* default handler will be used. The library provides a default handler which
349-
* writes the message to stderr and calls abort. This default handler can be
342+
* such mistakes, and the default (crashing) may be inadvisable. Should this
343+
* callback return instead of crashing, the return value and output arguments
344+
* of the API function call are undefined. Moreover, the same API call may
345+
* trigger the callback again in this case.
346+
*
347+
* When this function has not been called (or called with fun==NULL), then the
348+
* default callback will be used. The library provides a default callback which
349+
* writes the message to stderr and calls abort. This default callback can be
350350
* replaced at link time if the preprocessor macro
351351
* USE_EXTERNAL_DEFAULT_CALLBACKS is defined, which is the case if the build
352352
* has been configured with --enable-external-default-callbacks. Then the
353353
* following two symbols must be provided to link against:
354354
* - void secp256k1_default_illegal_callback_fn(const char *message, void *data);
355355
* - void secp256k1_default_error_callback_fn(const char *message, void *data);
356-
* The library can call these default handlers even before a proper callback data
356+
* The library may call a default callback even before a proper callback data
357357
* pointer could have been set using secp256k1_context_set_illegal_callback or
358358
* secp256k1_context_set_error_callback, e.g., when the creation of a context
359-
* fails. In this case, the corresponding default handler will be called with
359+
* fails. In this case, the corresponding default callback will be called with
360360
* the data pointer argument set to NULL.
361361
*
362362
* Args: ctx: pointer to a context object.
363363
* In: fun: pointer to a function to call when an illegal argument is
364364
* passed to the API, taking a message and an opaque pointer.
365-
* (NULL restores the default handler.)
366-
* data: the opaque pointer to pass to fun above, must be NULL for the default handler.
365+
* (NULL restores the default callback.)
366+
* data: the opaque pointer to pass to fun above, must be NULL for the
367+
* default callback.
367368
*
368369
* See also secp256k1_context_set_error_callback.
369370
*/
@@ -380,18 +381,19 @@ SECP256K1_API void secp256k1_context_set_illegal_callback(
380381
* to abort the program.
381382
*
382383
* This can only trigger in case of a hardware failure, miscompilation,
383-
* memory corruption, serious bug in the library, or other error would can
384-
* otherwise result in undefined behaviour. It will not trigger due to mere
384+
* memory corruption, serious bug in the library, or other error that would
385+
* result in undefined behaviour. It will not trigger due to mere
385386
* incorrect usage of the API (see secp256k1_context_set_illegal_callback
386387
* for that). After this callback returns, anything may happen, including
387388
* crashing.
388389
*
389390
* Args: ctx: pointer to a context object.
390391
* In: fun: pointer to a function to call when an internal error occurs,
391392
* taking a message and an opaque pointer (NULL restores the
392-
* default handler, see secp256k1_context_set_illegal_callback
393+
* default callback, see secp256k1_context_set_illegal_callback
393394
* for details).
394-
* data: the opaque pointer to pass to fun above, must be NULL for the default handler.
395+
* data: the opaque pointer to pass to fun above, must be NULL for the
396+
* default callback.
395397
*
396398
* See also secp256k1_context_set_illegal_callback.
397399
*/

0 commit comments

Comments
 (0)