Skip to content

Add optional external assertion handler for debug builds#19744

Closed
juanbelonepic wants to merge 2 commits intocurl:masterfrom
juanbelonepic:add-external-assert-handler
Closed

Add optional external assertion handler for debug builds#19744
juanbelonepic wants to merge 2 commits intocurl:masterfrom
juanbelonepic:add-external-assert-handler

Conversation

@juanbelonepic
Copy link
Contributor

@juanbelonepic juanbelonepic commented Nov 28, 2025

This PR allows applications to override the default DEBUGASSERT behavior by defining a custom CURL_DEBUGASSERT macro at compile or run time. We needed this to integrate applications where assert is a no-op.

Changes:

  • Modified lib/curl_setup_once.h:
    Added check for user-defined CURL_DEBUGASSERT macro before falling back to default assert()
    Allows applications to inject custom assertion handling via compile-time flags

Usage:
Applications can now define their own assertion handler by adding to compiler flags:
-DCURL_DEBUGASSERT(x)="MyAssertHandler(#x, __FILE__, __LINE__);"

And implementing the handler function

extern "C" void MyAssertHandler(const char* expr, const char* file, int line)
{
    // Your custom logging/error handling
}

@juanbelonepic juanbelonepic marked this pull request as draft November 28, 2025 15:18
@dfandrich
Copy link
Contributor

dfandrich commented Nov 28, 2025 via email

@juanbelonepic
Copy link
Contributor Author

juanbelonepic commented Nov 28, 2025

Does this need to be so complicated? Why not simply allow the DEBUGASSERT macro to be redefined as desired at compile time?

I am trying to find a way to replace the macro since we use a precompiled binary of the lib (can't redefine the macro).

@dfandrich
Copy link
Contributor

dfandrich commented Nov 28, 2025 via email

@juanbelonepic
Copy link
Contributor Author

CURL_DEBUGASSERT

We can add this to define DEBUGASSERT based on it, but the lib needs to be built before being used so we can't really redefine the macro, that's why I needed to do a external var , what other options can we think of ? Thanks

@dfandrich
Copy link
Contributor

dfandrich commented Nov 29, 2025 via email

@juanbelonepic juanbelonepic marked this pull request as ready for review December 1, 2025 09:02
Copy link
Contributor Author

@juanbelonepic juanbelonepic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User that will benefit from Changes are those who need another custom approach to deal with asserts

@bagder
Copy link
Member

bagder commented Dec 9, 2025

I don't understand what this means!

@juanbelonepic
Copy link
Contributor Author

juanbelonepic commented Dec 9, 2025

I don't understand what this means!

I was doing the review, not sure if I need to do that.
The comment means that the changes in this PR are for those who has assert as a no-op or want to redirect them (through the macro) to their custom function.
Thanks

@juanbelonepic juanbelonepic reopened this Dec 14, 2025
@jay
Copy link
Member

jay commented Dec 15, 2025

If your assert is a no-op isn't that on you to correct and not us? I think if you are going to have to patch libcurl for your custom assertion routine then you could patch the DEBUGASSERT lines as well but in your own fork. I don't see why this needs to be in all libcurl as it seems like a special requirement that only applies to you.

@bagder
Copy link
Member

bagder commented Dec 20, 2025

"This branch cannot be rebased due to conflicts"

Please rebase against master and force-push.

@juanbelonepic juanbelonepic force-pushed the add-external-assert-handler branch from c65a5b3 to 0581e87 Compare December 22, 2025 11:24
@bagder bagder closed this in 12a1be5 Feb 5, 2026
@bagder
Copy link
Member

bagder commented Feb 5, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants