• Embedded python is not 100% stable

    From Guenther Sohler@21:1/5 to All on Thu Apr 13 09:40:39 2023
    Hi Python LIst,

    I have been working on adding embedded python into OpenSCAD (
    www.openscad.org)
    for some time already. For that i coded/added an additional Python Type
    Object
    which means to hold openscad geometric data.

    It works quite well but unfortunately its not 100% stable and i have been heavily checking
    all the functions which are referenced in the PyType Object and tried to
    match
    them with the documentation which i found in the python web site but now i
    am stuck
    and i cant progress any further
    I am specially interested why the program constantly crashes when i
    activate the lines 14 and 15
    in pyopenscad.cc.
    I have attached the two most relevant files and I would be happy if anybody interested
    could tell me, if there is an obvious bug popping into your eyes.
    If anybody is interested to see the complete picture, all source code is available checked in
    in github @

    https://github.com/gsohler/openscad.git branch "libfive"
    Thank you for reading. Any spotted bug found will make me happy

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Dieter Maurer@21:1/5 to Guenther Sohler on Thu Apr 13 16:21:36 2023
    Guenther Sohler wrote at 2023-4-13 09:40 +0200:
    ...
    I have been working on adding embedded python into OpenSCAD ( >www.openscad.org)
    for some time already. For that i coded/added an additional Python Type >Object
    which means to hold openscad geometric data.

    It works quite well but unfortunately its not 100% stable and i have been >heavily checking
    all the functions which are referenced in the PyType Object and tried to >match
    them with the documentation which i found in the python web site

    The Python C/C++ interface is complex: it is easy to make
    mistakes which may lead to crashes.

    Often, `cython` (--> PyPI) can help you to define extension types
    in a much safer way. Maybe, you check its documentation?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From aapost@21:1/5 to Guenther Sohler on Thu Apr 13 13:54:25 2023
    On 4/13/23 03:40, Guenther Sohler wrote:


    Attachments are stripped, so they weren't included.

    Glancing at the branch and the 2 lines you mentioned.

    You have a comment with a link for python 2.3 documentation.
    Yet you have python 3.10 code included elsewhere (and openscad itself
    requires the modern spec C++17, so I assume your aim is at current versions)

    https://docs.python.org/3.10/extending/newtypes.html
    is the equivalent doc for that.

    I am not experienced in defining PyType objects in C, but notice
    syntactical discrepancies, missing "static" on dealloc, use of
    typecasted malloc rather than PyType_GenericAlloc() https://docs.python.org/3.10/c-api/typeobj.html#c.PyTypeObject.tp_alloc

    Without digging in deeper and learning more I can't say for certain
    whether or not those are issues, but intuitively I assume they would be
    and that the implementation needs to more closely mirror the syntactical
    flow implementations of modern working examples..

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)