Skip to contentSkip to conversation

bindings: python: replace PyModule_AddObjectRef() with PyModule_AddObjectRef()

PATCH In review Bartosz Golaszewski 3 participants 5 messages Oct 9, 2023 – Oct 10, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 bindings: python: replace PyModule_AddObjectRef() with PyModule_AddObjectRef()

From: Bartosz Golaszewski <[email protected]>

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims to depend on python v3.9. Replace it with an older variant that steals the reference to the added object on success.

---
 bindings/python/gpiod/ext/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/ext/module.c +2 -2
index 25c252a..b456190 100644
@@ -178,9 +178,9 @@ PyMODINIT_FUNC PyInit__ext(void)
 		return NULL;
 	}
 
-	ret = PyModule_AddObjectRef(module, "__all__", all);
-	Py_DECREF(all);
+	ret = PyModule_AddObject(module, "__all__", all);
 	if (ret) {
+		Py_DECREF(all);
 		Py_DECREF(module);
 		return NULL;
 	}
Signature · 1 line
2.39.2
#1 lore raw
Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims to depend on python v3.9. Replace it with an older variant that steals the reference to the added object on success.

Ah, fixing this makes much more sense than bumping the dependent version, thank you, I will update my patch.

Quoted 26 lines
---
 bindings/python/gpiod/ext/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/ext/module.c +2 -3
index 25c252a..b456190 100644
@@ -178,9 +178,9 @@ PyMODINIT_FUNC PyInit__ext(void)
                return NULL;
        }
 
-       ret = PyModule_AddObjectRef(module, "__all__", all);
-       Py_DECREF(all);
+       ret = PyModule_AddObject(module, "__all__", all);
        if (ret) {
+               Py_DECREF(all);
                Py_DECREF(module);
                return NULL;
        }
--

2.39.2

#2 lore raw
Quoted 12 lines · Phil Howard
Quoted 6 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims to depend on python v3.9. Replace it with an older variant that steals the reference to the added object on success.

Ah, fixing this makes much more sense than bumping the dependent version, thank you, I will update my patch.

And of course the commit message was supposed to read: "bindings:
python: replace PyModule_AddObjectRef() with PyModule_AddObject()".

I'll fix it when applying.

Bart

Quoted 26 lines
Quoted 26 lines
---
 bindings/python/gpiod/ext/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/ext/module.c +2 -3
index 25c252a..b456190 100644
@@ -178,9 +178,9 @@ PyMODINIT_FUNC PyInit__ext(void)
                return NULL;
        }
 
-       ret = PyModule_AddObjectRef(module, "__all__", all);
-       Py_DECREF(all);
+       ret = PyModule_AddObject(module, "__all__", all);
        if (ret) {
+               Py_DECREF(all);
                Py_DECREF(module);
                return NULL;
        }
--

2.39.2

#3 lore raw
Quoted 9 lines · Bartosz Golaszewski
Quoted 7 lines · Phil Howard
Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims to depend on python v3.9. Replace it with an older variant that steals the

I've done some digging and it looks like "PyModule_AddType" [1] helper function is what's
anchoring the library to Python 3.9 (in the stable ABI as of 3.10) rather than 3.8.

Is that correct? If so I'll update my patch to reflect the use of PyModule_AddType.

The raw Python part of the library is compatible back to 3.7 (EOL), 3.8 EOL is this time next year so going < 3.9 is probably not worth the effort.

1. https://github.com/python/cpython/blob/43a6e4fa4934fcc0cbd83f7f3dc1b23a5f79f24b/Python/modsupport.c#L686-L703

Quoted 39 lines
Quoted 5 lines
Quoted 1 line

reference to the added object on success.

Ah, fixing this makes much more sense than bumping the dependent version, thank you, I will update my patch.

And of course the commit message was supposed to read: "bindings:
python: replace PyModule_AddObjectRef() with PyModule_AddObject()".

I'll fix it when applying.

Bart

Quoted 26 lines
Quoted 26 lines
---
 bindings/python/gpiod/ext/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/ext/module.c +2 -3
index 25c252a..b456190 100644
@@ -178,9 +178,9 @@ PyMODINIT_FUNC PyInit__ext(void)
                return NULL;
        }
 
-       ret = PyModule_AddObjectRef(module, "__all__", all);
-       Py_DECREF(all);
+       ret = PyModule_AddObject(module, "__all__", all);
        if (ret) {
+               Py_DECREF(all);
                Py_DECREF(module);
                return NULL;
        }
--

2.39.2

#4 lore raw
Quoted 17 lines · Phil Howard
Quoted 9 lines · Bartosz Golaszewski
Quoted 7 lines · Phil Howard
Quoted 5 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

PyModule_AddObjectRef() was added in cpython v3.10 while libgpiod claims to depend on python v3.9. Replace it with an older variant that steals the

I've done some digging and it looks like "PyModule_AddType" [1] helper function is what's
anchoring the library to Python 3.9 (in the stable ABI as of 3.10) rather than 3.8.

Quoted 6 lines

Is that correct? If so I'll update my patch to reflect the use of PyModule_AddType.

The raw Python part of the library is compatible back to 3.7 (EOL), 3.8 EOL is this time next year so going < 3.9 is probably not worth the effort.

Agreed, and most distros ship >=v3.9 anyway.

Bart

Quoted 41 lines

1. https://github.com/python/cpython/blob/43a6e4fa4934fcc0cbd83f7f3dc1b23a5f79f24b/Python/modsupport.c#L686-L703

Quoted 39 lines
Quoted 5 lines
Quoted 1 line

reference to the added object on success.

Ah, fixing this makes much more sense than bumping the dependent version, thank you, I will update my patch.

And of course the commit message was supposed to read: "bindings:
python: replace PyModule_AddObjectRef() with PyModule_AddObject()".

I'll fix it when applying.

Bart

Quoted 26 lines
Quoted 26 lines
---
 bindings/python/gpiod/ext/module.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/ext/module.c +2 -3
index 25c252a..b456190 100644
@@ -178,9 +178,9 @@ PyMODINIT_FUNC PyInit__ext(void)
                return NULL;
        }
 
-       ret = PyModule_AddObjectRef(module, "__all__", all);
-       Py_DECREF(all);
+       ret = PyModule_AddObject(module, "__all__", all);
        if (ret) {
+               Py_DECREF(all);
                Py_DECREF(module);
                return NULL;
        }
--

2.39.2