coin3d / pivy

python bindings to coin3d
ISC License
53 stars 37 forks source link

Fix undefined behavior in coin.cast and soqt.cast functions #99

Closed marioalexis84 closed 1 year ago

marioalexis84 commented 1 year ago

If the macro PY_SSIZE_T_CLEAN is defined (mandatory in Python 3.10), when parsing arguments with # variants of formats (s#, y#, etc.) the type of the length argument must be Py_ssize_t. This is related to https://github.com/coin3d/pivy/pull/91. The problem is not due to what is described in #91, but to the type of the argument. The implementation proposed in #91 for the functions cast and cast_internal only fix the crash in those cases when only cast_internal is used, but cast still crash, for example. when creating the quarter widget.

To reproduce the crash:

from pivy import coin
from pivy.gui import soqt
s=coin.SoTransform()
coin.cast(s, "SoNode") --> crash
soqt.cast(s, "SoNode") --> SystemError in Python >= 3.10

But most important:

from PySide2.QtWidgets import QApplication
from pivy import quarter
app = QApplication()
q = quarter.QuarterWidget() --> crash
looooo commented 1 year ago

Thank you @marioalexis84 👍, as I do not understand a lot what is going on here, maybe @wwmayer can review this.

yopito commented 1 year ago

FYI, I've applied this patch on pivy and used it with FreeCAD 20.1: a lot more integrated tests passing now (via FreeCAD -t 0)