A library for tracking references to shared resources such as memory.
Find us on…
_________ __
/ _____/ _____ _____ ________/ |_
\_____ \ / \\__ \\_ __ \ __\
/ \ Y Y \/ __ \| | \/| |
/_______ /__|_| (____ /__| |__|
\/ \/ \/
__________ .__ __
\______ \____ |__| _____/ |_ ___________ ______
| ___/ _ \| |/ \ __\/ __ \_ __ \/ ___/
| | ( <_> ) | | \ | \ ___/| | \/\___ \
|____| \____/|__|___| /__| \___ >__| /____ >
\/ \/ \/
\/
The Smart-Pointers library tracks references to program resources and automates the freeing of those resources if and only if the reference count drops to zero. Most commonly, the reference is a pointer and the resource is memory. In that context, Smart-Pointers help to prevent memory leaks and dangling pointers, which commonly causes programs to crash due to memory limitations or segmentation faults, respectively.
To use Smart-Pointers, define a non-abstract derived type that
sp_smart_pointer_t
type,free
deferred binding, andstart_count
procedure inside object constructors.You can then use intrinsic assignments to copy instances of a sp_smart_pointer_t
child type, resulting in a shallow copy with the advantage that the target
will be finalized only when it becomes safe to do so.
See the example folder for a demonstration of the use of Smart-Pointers.
For more background on the design philosophy and the internal mechanics of Smart Pointers, see Rouson et al. (see 1, 2, 3). This repository's code originated from refactoring the code in those publications to use more up-to-date coding conventions. For example, this repository separates interface bodies into modules and procedure definitions into submodules. This repository also uses more descriptive nomenclature for the types and procedures.
This repository also adds
1. A Fortran Package Manager build system,
2. Tests based on the Sourcery library's unit-testing utility,
3. Documentation generated by [ford
] and deployed to the web via GitHub Actions, and
4. Quality control via continuous integration testing using GitHub Actions.
Correct execution of the Smart-Pointers library depends critically on comprehensive compiler support for type finalization. The unit test suite verifies the relevant compiler standard-conformance, including a test for each scenario in which the the Fortran 2023 standard requires that an object be finalized. The following compilers pass all Smart-Pointers tests:
Compiler | Test failures | Version tested |
---|---|---|
GCC gfortran :trophy: |
0 | 13.1.0 |
LLVM flang :trophy: |
0 | 19.0.0 git commit 325f5123 |
NAG nagfor :trophy: |
0 | 7.1 Build 7113 |
The following compilers pass most smart pointers tests:
Compiler | Test failures | Version tested |
---|---|---|
Cray ftn |
4 | 17.0.0 |
IBM xlf2008_r |
1 | 17.1.0 on AIX |
Intel ifort |
1 | 2021.7.0 Build 20220726_000000 |
Intel ifx |
1 | 2024.0.0 Build 20231017 |
NVIDIA nvfortran |
2 | 22.7-0 |
The following compiler fails to build Smart-Pointers due to an internal compiler error (ICE):
Compiler | Test failures | Version tested |
---|---|---|
AMD flang |
N.A. (see Note) | 13.0.0 (AOCC_3.2.0-Build#128 2021_11_12) |
See the test suite README.md for more details on each compiler's test results.
On Linux, macOS, or Windows Subsystem for Linux, download, build, and test with the following shell commands:
git clone https://github.com/sourceryinstitute/smart-pointer
cd smart-pointer
followed by one of the commands below corresponding to your compiler choice.
The following compilers pass all Smart-Pointers tests.
gfortran
fpm test
flang
fpm test --compiler flang-new
nagfor
fpm test --compiler nagfor --flag -fpp
The following compilers pass most Smart-Pointers tests.
Building with fpm
using the CCE ftn
compiler wrapper requires an additional
wrapper to identify the wrapped compiler. Place a file named crayftn.sh
at the
front of your PATH
environment variable containing the following contents:
1 2 3 |
|
Then test with the following command
fpm test --compiler crayftn.sh
fpm test --archiver ar --compiler xlf2008_r --flag -DXLF
ifort
fpm test --compiler ifort
ifx
fpm test --compiler ifx
where the latter requires fpm
0.10.0 or later.
nvfortran
fpm test --compiler nvfortran --flag -Mpreprocess
The following compiler cannot build the Smart-Pointers library.
flang
fpm test --compiler flang --flag -cpp
See the Smart-Pointers GitHub Pages site for HTML documentation generated with [ford
].
See the doc/ subdirectory for a PlantUML script that generates the Unified Modeling Language (UML)
class diagram below of the three derived types in Smart-Pointers.