SDL2::assert - SDL Assertion Functions
use SDL2::FFI qw[:assert]; SDL_assert( 1 == 1 ); my $test = 'nope'; SDL_assert( sub { warn 'testing'; my $retval = $test eq "blah"; $test = "blah"; $retval; } );
SDL2::assert implements an assertion system. Failures even cause the perl debugger to halt if enabled.
These may be imported by name or with the :assert tag.
:assert
SDL_ReportAssertion( ... )
Never call this directly. Use SDL_assert( ... ), SDL_assert_release( ... ), SDL_assert_paranoid( ... ), and SDL_assert_always( ... ).
SDL_assert( ... )
SDL_assert_release( ... )
SDL_assert_paranoid( ... )
SDL_assert_always( ... )
SDL_SetAssertionHandler( ... )
Set an application-defined assertion handler.
SDL_SetAssertionHandler( sub { ... } );
This function allows an application to show its own assertion UI and/or force the response to an assertion failure. If the application doesn't provide this, SDL will try to do the right thing, popping up a system-specific GUI dialog, and probably minimizing any fullscreen windows.
This callback may fire from any thread, but it runs wrapped in a mutex, so it will only fire from one thread at a time.
This callback is NOT reset to SDL's internal handler upon SDL_Quit( )!
SDL_Quit( )
Expected parameters include:
handler
SDL_AssertionHandler
SDL_GetDefaultAssertionHandler( )
Get the default assertion handler.
This returns the function pointer that is called by default when an assertion is triggered. This is an internal function provided by SDL, that is used for assertions when SDL_SetAssertionHandler( ... ) hasn't been used to provide a different function.
Returns the default SDL_AssertionHandler that is called when an assert triggers.
SDL_GetAssertionHandler( ... )
Get the current assertion handler.
This returns the function pointer that is called when an assertion is triggered. This is either the value last passed to SDL_SetAssertionHandler( ... ), or if no application-specified function is set, is equivalent to calling SDL_GetDefaultAssertionHandler( ).
The parameter puserdata is a pointer to a void*, which will store the "userdata" pointer that was passed to SDL_SetAssertionHandler( ... ). This value will always be NULL for the default handler. If you don't care about this data, it is safe to pass a NULL pointer to this function to ignore it.
puserdata
void*
Returns the SDL_AssertionHandler that is called when an assert triggers.
SDL_GetAssertionReport( )
Get a list of all assertion failures.
This function gets all assertions triggered since the last call to SDL_ResetAssertionReport( ), or the start of the program.
SDL_ResetAssertionReport( )
The proper way to examine this data looks something like this:
my $item = SDL_GetAssertionReport(); while ($item) { printf( " ==> '%s', %s (%s:%d), triggered %u times, always ignore: %s.\n\n", $item->condition, $item->function, $item->filename, $item->linenum, $item->trigger_count, $item->always_ignore ? 'yes' : 'no' ); $item = $item->next; }
Returns a list of all failed assertions or NULL if the list is empty. This memory should not be modified or freed by the application.
Clear the list of all assertion failures.
SDL_ResetAssertionReport( );
This function will clear the list of all assertions triggered up to that point. Immediately following this call, SDL_GetAssertionReport( ) will return no items. In addition, any previously-triggered assertions will be reset to a trigger_count of zero, and their always_ignore state will be false.
trigger_count
always_ignore
Use this macro to create an assertion for debugging.
SDL_assert(1 == 0); # triggers an assertion. SDL_assert(1 == 1); # does NOT trigger an assertion
This function is enabled only when the SDL_ASSERT_LEVEL is set to 2 or 3, otherwise it is disabled.
SDL_ASSERT_LEVEL
2
3
condition
Use this function to create an assertion for release builds.
SDL_assert_release( time > -f __FILE__ );
This function is enabled by default. It can be disabled by setting the SDL_ASSERT_LEVEL to 0.
0
Use this function to create an assertion for detailed checking.
SDL_assert_paranoid( 5 == 10 );
This function is disabled by default. It is available for use only when the SDL_ASSERT_LEVEL is set to 3.
Use this function to create an assertion regardless of the current SDL_ASSERT_LEVEL.
SDL_assert_always( 5 == 10 );
A callback that fires when an SDL assertion fails.
This function should expect the following parameters:
data
userdata
SDL_SetAssertionHandler( )
You should return an assert state value indicating how to handle the failure.
Defines and Enumerations listed here may be imported from SDL2::FFI with the following tags:
:assertState
SDL_ASSERTION_RETRY
SDL_ASSERTION_BREAK
SDL_ASSERTION_ABORT
SDL_ASSERTION_IGNORE
SDL_ASSERTION_ALWAYS_IGNORE
Copyright (C) Sanko Robinson.
This library is free software; you can redistribute it and/or modify it under the terms found in the Artistic License 2. Other copyrights, terms, and conditions may apply to data transmitted through this module.
Sanko Robinson <sanko@cpan.org>
To install SDL2::FFI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm SDL2::FFI
CPAN shell
perl -MCPAN -e shell install SDL2::FFI
For more information on module installation, please visit the detailed CPAN module installation guide.