diff --git a/examples/issue41_abstract_classes/Makefile b/examples/issue41_abstract_classes/Makefile index 7dbee99c..ab57882d 100644 --- a/examples/issue41_abstract_classes/Makefile +++ b/examples/issue41_abstract_classes/Makefile @@ -2,20 +2,25 @@ FC = gfortran FCFLAGS = -fPIC PYTHON = python -%.o : %.f90 - ${FC} ${FCFLAGS} -c $< -o $@ +all: wrapper test_abstract_classes.x + +test: wrapper + $(PYTHON) run.py -all: myclass_base.o myclass_impl.o myclass_factory.o +test_abstract_classes.x: main.f90 myclass_base.o myclass_impl.o myclass_factory.o + $(FC) $(FCFLAGS) -o $@ $^ + +wrapper: myclass_base.o myclass_impl.o myclass_factory.o f90wrap -m itest -P myclass_impl.f90 myclass_factory.f90 -v f2py-f90wrap --build-dir . -c -m _itest \ f90wrap_myclass_impl.f90 f90wrap_myclass_factory.f90 \ myclass_base.o myclass_impl.o myclass_factory.o -test: all - $(PYTHON) run.py +%.o : %.f90 + $(FC) $(FCFLAGS) -c $< -o $@ clean: - rm -f *.o f90wrap*.f90 *.so *.mod + rm -f *.o f90wrap*.f90 *.so *.mod *.x rm -rf src.*/ rm -rf itest/ -rm -rf src.*/ .f2py_f2cmap .libs/ __pycache__/ diff --git a/examples/issue41_abstract_classes/main.f90 b/examples/issue41_abstract_classes/main.f90 new file mode 100644 index 00000000..1a35cab5 --- /dev/null +++ b/examples/issue41_abstract_classes/main.f90 @@ -0,0 +1,24 @@ +program main + use myclass_factory, only: create_myclass + use myclass_impl, only: myclass_impl_t + implicit none + + print *, "Start" + + call test() + + print *, "Done" + +contains + +subroutine test + real :: x + class(myclass_impl_t), allocatable :: myobject + + myobject = create_myclass("impl") + call myobject%get_value(x) + + print *, "Value: ", x +end subroutine test + +end program main diff --git a/examples/issue41_abstract_classes/myclass_impl.f90 b/examples/issue41_abstract_classes/myclass_impl.f90 index 43cf4c2a..a7cab804 100644 --- a/examples/issue41_abstract_classes/myclass_impl.f90 +++ b/examples/issue41_abstract_classes/myclass_impl.f90 @@ -6,6 +6,7 @@ module myclass_impl type, extends(myclass_t) :: myclass_impl_t contains procedure :: get_value => get_value_impl + final :: myclass_impl_finalise end type myclass_impl_t contains @@ -17,4 +18,10 @@ subroutine get_value_impl(self, value) value = 1.0 end subroutine get_value_impl +subroutine myclass_impl_finalise(self) + type(myclass_impl_t), intent(inout) :: self + + print *, "Finalizing myclass_impl_t" +end subroutine myclass_impl_finalise + end module myclass_impl diff --git a/examples/issue41_abstract_classes/run.py b/examples/issue41_abstract_classes/run.py index 195ad8a0..2f9dfcb9 100644 --- a/examples/issue41_abstract_classes/run.py +++ b/examples/issue41_abstract_classes/run.py @@ -5,4 +5,6 @@ TOL = 1.0e-14 obj = itest.myclass_factory.create_myclass("impl") -assert(abs(obj.get_value()-REF)