Repository: jameskermode/f90wrap (language: python)

Issue:
Optional out string
Calling a wrapped routine with an optional string array produces a segfault with numpy version >= 1.24.0 when called without the argument.
I belive the problems is that the C generated code trys to acces data from Py_None object.
This PR adds a check in the C generated code from f2py_f90wrap.py script.
It also add some related tests on various way to manipulate strings.



Discussion / hints:
Thank you, this looks good and since you have already added a new test I will go ahead and merge directly.

Fix patch:
diff --git a/examples/Makefile b/examples/Makefile
index 7b5072e6..a792a91e 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -21,7 +21,8 @@ EXAMPLES = arrayderivedtypes \
 	type_bn \
 	docstring \
 	type_check \
-	derivedtypes_procedure
+	derivedtypes_procedure \
+	optional_string
 
 PYTHON = python
 
diff --git a/pyproject.toml b/pyproject.toml
index c100ed0c..9fedc543 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -9,7 +9,7 @@ description = "Fortran to Python interface generator with derived type support"
 authors = [{name = "James Kermode", email = "james.kermode@gmail.com"}]
 python-requires = ">=3.6"
 urls = {Homepage = "https://github.com/jameskermode/f90wrap"}
-dependencies = ["numpy>=1.13"]
+dependencies = ["numpy>=1.13", "packaging"]
 dynamic = ["version"]
 
 [project.readme]


Test patch:
diff --git a/examples/optional_string/test.py b/examples/optional_string/test.py
index eb117056..07e95083 100644
--- a/examples/optional_string/test.py
+++ b/examples/optional_string/test.py
@@ -16,9 +16,9 @@ def test_string_in_3(self):
         m_string_test.string_in(np.string_('yo'))
 
     def test_string_to_string(self):
-        in_string = b'yo'
+        in_string = 'yo'
         out_string = m_string_test.string_to_string(in_string)
-        self.assertEqual(in_string, out_string)
+        self.assertEqual(in_string, out_string.decode("utf-8").strip())
 
     @unittest.skipIf(version.parse(np.version.version) < version.parse("1.24.0") , "This test is known to fail on numpy version older than 1.24.0")
     def test_string_to_string_array(self):
@@ -30,7 +30,7 @@ def test_string_to_string_array(self):
 
     def test_string_out(self):
         out_string = m_string_test.string_out()
-        self.assertEqual(out_string, b"output string")
+        self.assertEqual(out_string.decode("utf-8").strip(), "output string")
 
     @unittest.skipIf(version.parse(np.version.version) < version.parse("1.23.5") , "This test is known to fail on numpy version older than 1.23.5")
     def test_string_out_optional(self):