ReturnAddressUnit to provide ReturnAddress to Delphi versions not supporting it, and prevent CallerAddr warnings for Delphi versions having ReturnAddress. See https://bitbucket.org/jeroenp/wiert.me/src/8ae6cf29ffc601fde7c1182dead740adddb13fb8/Native/Delphi/Library/RTL/ReturnAddressUnit.pas
Posted by jpluimers on 2021/04/07
From a check-in a while ago, when some Delphi versions complained about CallerAddr
having been replaced by ReturnAddress
and other versions not understanding ReturnAddress
, but having CallerAddr
.
The code in the [WayBack] gist and on [WayBack] BitBucket:
ReturnAddressUnit
to provideReturnAddress
to Delphi versions not supporting it, and preventCallerAddr
warnings for Delphi versions havingReturnAddress
. See https://bitbucket.org/jeroenp/wiert.me/src/…/Native/Delphi/Library/RTL/ReturnAddressUnit.pas
Basically the code maps a variable having a variable ReturnAddress
that is a function reference returning a pointer to a function and redirects to CallerAddr
when there is no ReturnAddress
available. This is the case for anything below Delphi XE2, and avoids W1000 Symbol 'CallerAddr' is deprecated: 'Use ReturnAddress'
for Delphi XE2 and up
It is an extract from [WayBack] dunit-extension/TestCaseExtension.pas at master · fabriciocolombo/dunit-extension · GitHub.
There is more interesting code in [WayBack] GitHub – fabriciocolombo/dunit-extension: Extended DUnit TestCase provides assertions to the types Date, Enumerator, Double, and other types, and a class to help run tests with output as XML, text and GUI mode and even more in [WayBack] fabriciocolombo (Fabricio Colombo) · GitHub , which are on my list of things to play with in the future.
Some more [WayBack] commits are at [WayBack] GitHub – cesarliws/dunit-extension (more on [WayBack] Cesar Romero tomorrow).
I think the code from Fabricio is inspired by [WayBack] ZeosLib/TestFrameWork.pas at master · svn2github/ZeosLib · GitHub as it uses the same HAS_BUILTIN_RETURNADDRESS
define.
The code by Fabricio is smarter though.
Via: “Delphi” “CallerAddr” “ReturnAddress” – Google Search
–jeroen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit ReturnAddressUnit; | |
// maps CallerAdddr to ReturnAddress to CallerAddr when not available (XE2 and higher have ReturnAddress) | |
// this avoids "W1000 Symbol 'CallerAddr' is deprecated: 'Use ReturnAddress'" | |
// from https://github.com/fabriciocolombo/dunit-extension/blob/master/src/TestCaseExtension.pas | |
interface | |
{$IFDEF CONDITIONALEXPRESSIONS} | |
{$IF (NOT DEFINED(CLR)) AND (CompilerVersion >= 23.0) } | |
{$DEFINE HAS_BUILTIN_RETURNADDRESS} // Requires ReturnAddress intrinsic function(Delphi XE2) | |
{$ENDIF} | |
{$ENDIF} | |
{$IFNDEF HAS_BUILTIN_RETURNADDRESS} | |
type | |
TReturnAddressFunc = function : Pointer; | |
var | |
ReturnAddress: TReturnAddressFunc = CallerAddr; | |
{$ENDIF} | |
implementation | |
end. |
Leave a comment