diff options
author | Christoph Reiter <creiter@src.gnome.org> | 2016-09-03 20:02:13 +0200 |
---|---|---|
committer | Christoph Reiter <creiter@src.gnome.org> | 2016-09-03 23:24:38 +0200 |
commit | 7ccc164b6da6d87c0a200ea50314d213470a1f18 (patch) | |
tree | d61bb691ece9c5a0c5b3b172dd871b2b6478f93d | |
parent | f4d858c069f06e7060a0bb067c29f5bffb7869ee (diff) | |
download | pygobject-7ccc164b6da6d87c0a200ea50314d213470a1f18.tar.gz |
Handle nullable filename parameters
Make _pygi_marshal_from_py_filename handle None input
values. This allows one to pass None to parameters
annotated as nullable filenames.
This fixes a test suite error in test_spawn_async_with_pipes
triggered by an annotation change in glib.
https://bugzilla.gnome.org/show_bug.cgi?id=770821
-rw-r--r-- | gi/pygi-basictype.c | 5 | ||||
-rw-r--r-- | tests/gimarshallingtestsextra.c | 22 | ||||
-rw-r--r-- | tests/gimarshallingtestsextra.h | 3 | ||||
-rw-r--r-- | tests/test_gi.py | 4 |
4 files changed, 34 insertions, 0 deletions
diff --git a/gi/pygi-basictype.c b/gi/pygi-basictype.c index b6515c31..4a5e1121 100644 --- a/gi/pygi-basictype.c +++ b/gi/pygi-basictype.c @@ -255,6 +255,11 @@ _pygi_marshal_from_py_filename (PyObject *py_arg, GError *error = NULL; PyObject *tmp = NULL; + if (py_arg == Py_None) { + arg->v_pointer = NULL; + return TRUE; + } + if (PyUnicode_Check (py_arg)) { tmp = PyUnicode_AsUTF8String (py_arg); if (!tmp) diff --git a/tests/gimarshallingtestsextra.c b/tests/gimarshallingtestsextra.c index 56b0113a..85a9fba0 100644 --- a/tests/gimarshallingtestsextra.c +++ b/tests/gimarshallingtestsextra.c @@ -68,3 +68,25 @@ gi_marshalling_tests_ghashtable_enum_none_return (void) return hash_table; } + +/** + * gi_marshalling_tests_filename_copy: + * @path_in: (type filename) (nullable) + * + * Returns: (type filename) (nullable) + */ +gchar * +gi_marshalling_tests_filename_copy (gchar *path_in) +{ + return g_strdup (path_in); +} + +/** + * gi_marshalling_tests_filename_exists: + * @path: (type filename) + */ +gboolean +gi_marshalling_tests_filename_exists (gchar *path) +{ + return g_file_test (path, G_FILE_TEST_EXISTS); +} diff --git a/tests/gimarshallingtestsextra.h b/tests/gimarshallingtestsextra.h index ae6be1b3..51a65f29 100644 --- a/tests/gimarshallingtestsextra.h +++ b/tests/gimarshallingtestsextra.h @@ -33,4 +33,7 @@ void gi_marshalling_tests_compare_two_gerrors_in_gvalue (GValue *v, GValue *v1); void gi_marshalling_tests_ghashtable_enum_none_in (GHashTable *hash_table); GHashTable * gi_marshalling_tests_ghashtable_enum_none_return (void); +gchar * gi_marshalling_tests_filename_copy (gchar *path_in); +gboolean gi_marshalling_tests_filename_exists (gchar *path); + #endif /* EXTRA_TESTS */ diff --git a/tests/test_gi.py b/tests/test_gi.py index d246a014..d0c72b64 100644 --- a/tests/test_gi.py +++ b/tests/test_gi.py @@ -710,6 +710,10 @@ class TestFilename(unittest.TestCase): self.assertEqual(result, True) self.assertEqual(contents, b'hello world!\n\x01\x02') + def test_filename_in_nullable(self): + self.assertTrue(GIMarshallingTests.filename_copy(None) is None) + self.assertRaises(TypeError, GIMarshallingTests.filename_exists, None) + def test_filename_out(self): self.assertRaises(GLib.GError, GLib.Dir.make_tmp, 'test') |