Skip to content

Commit

Permalink
Add remove_pointer_arg test support contiguous
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Dec 5, 2024
1 parent fde8cfd commit 117e03c
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
1 change: 1 addition & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ list(APPEND tests
optional_string
long_subroutine_name
output_kind
remove_pointer_arg
)

foreach(test ${tests})
Expand Down
3 changes: 2 additions & 1 deletion examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ EXAMPLES = arrayderivedtypes \
long_subroutine_name \
kind_map_default \
intent_out_size \
output_kind
output_kind \
remove_pointer_arg

PYTHON = python

Expand Down
38 changes: 38 additions & 0 deletions examples/remove_pointer_arg/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#=======================================================================
# define the compiler names
#=======================================================================

CC = gcc
F90 = gfortran
PYTHON = python
CFLAGS = -fPIC
F90FLAGS = -fPIC
PY_MOD = pywrapper
F90_SRC = main.f90
OBJ = $(F90_SRC:.f90=.o)
F90WRAP_SRC = $(addprefix f90wrap_,${F90_SRC})
WRAPFLAGS = -v
F2PYFLAGS = --build-dir build
F90WRAP = f90wrap
F2PY = f2py-f90wrap
.PHONY: all clean

all: test

clean:
rm -rf *.mod *.smod *.o f90wrap*.f90 ${PY_MOD}.py _${PY_MOD}*.so __pycache__/ .f2py_f2cmap build ${PY_MOD}/

main.o: ${F90_SRC}
${F90} ${F90FLAGS} -c $< -o $@

%.o: %.f90
${F90} ${F90FLAGS} -c $< -o $@

${F90WRAP_SRC}: ${OBJ}
${F90WRAP} -m ${PY_MOD} ${WRAPFLAGS} ${F90_SRC}

f2py: ${F90WRAP_SRC}
CFLAGS="${CFLAGS}" ${F2PY} -c -m _${PY_MOD} ${F2PYFLAGS} f90wrap_*.f90 *.o

test: f2py
${PYTHON} tests.py
6 changes: 6 additions & 0 deletions examples/remove_pointer_arg/Makefile.meson
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
include ../make.meson.inc

NAME := pywrapper

test: build
$(PYTHON) tests.py
27 changes: 27 additions & 0 deletions examples/remove_pointer_arg/main.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
program main

end program

module m_test

implicit none
public

contains

function to_be_ignored_1() result(ptr)
real,pointer :: ptr(:,:)
ptr => null()
end function to_be_ignored_1

function to_be_ignored_2() result(ptr)
real,pointer,contiguous :: ptr(:,:)
ptr => null()
end function to_be_ignored_2

function not_to_be_ignored() result(out_int)
integer :: out_int
out_int = 1
end function not_to_be_ignored

end module m_test
19 changes: 19 additions & 0 deletions examples/remove_pointer_arg/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest

from pywrapper import m_test

class TestReturnArray(unittest.TestCase):

def not_ignored(self):
_ = m_test.not_to_be_ignored()

def ignored_1(self):
with self.assertRaises(AttributeError):
_ = m_test.to_be_ignored_1()

def ignored_2(self):
with self.assertRaises(AttributeError):
_ = m_test.to_be_ignored_2()

if __name__ == '__main__':
unittest.main()
4 changes: 2 additions & 2 deletions f90wrap/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
program = re.compile('^program', re.IGNORECASE)
program_end = re.compile('^end\s*program|end$', re.IGNORECASE)

attribs = r'allocatable|pointer|save|dimension *\(.*?\)|parameter|target|public|private|extends *\(.*?\)' # jrk33 added target
attribs = r'allocatable|pointer|save|contiguous|dimension *\(.*?\)|parameter|target|public|private|extends *\(.*?\)' # jrk33 added target

type_re = re.compile(r'^type((,\s*(' + attribs + r')\s*)*)(::)?\s*(?!\()', re.IGNORECASE)
type_end = re.compile('^end\s*type|end$', re.IGNORECASE)
Expand All @@ -76,7 +76,7 @@

prefixes = r'elemental|impure|module|non_recursive|pure|recursive'
types = r'double precision|(real\s*(\(.*?\))?)|(complex\s*(\(.*?\))?)|(integer\s*(\(.*?\))?)|(logical)|(character\s*(\(.*?\))?)|(type\s*\().*?(\))|(class\s*\().*?(\))'
a_attribs = r'allocatable|pointer|save|dimension\(.*?\)|intent\(.*?\)|optional|target|public|private'
a_attribs = r'allocatable|pointer|save|dimension\(.*?\)|intent\(.*?\)|optional|target|public|private|contiguous'

types_re = re.compile(types, re.IGNORECASE)

Expand Down

0 comments on commit 117e03c

Please sign in to comment.