Git Product home page Git Product logo

Comments (6)

rkaminsk avatar rkaminsk commented on September 1, 2024 2

I applied the patch to the conda-forge releases. They should work just fine now.

from clingo.

rkaminsk avatar rkaminsk commented on September 1, 2024

I can confirm that programs with python scripts do not run using python 3.12 and the packages provided on conda-forge.

#script (python)
#end.

from clingo.

rkaminsk avatar rkaminsk commented on September 1, 2024

To work with python 3.12, the file libpyclingo/_clingo.c has to be regenerated with cffi 1.16.0. You could apply the following patch to fix the issue:

diff --git a/libpyclingo/_clingo.c b/libpyclingo/_clingo.c
index 36a72d3c..2d6e4cca 100644
--- a/libpyclingo/_clingo.c
+++ b/libpyclingo/_clingo.c
@@ -612,7 +612,8 @@ extern "C" {
 
    * _cffi_call_python_org, which on CPython is actually part of the
      _cffi_exports[] array, is the function pointer copied from
-     _cffi_backend.
+     _cffi_backend.  If _cffi_start_python() fails, then this is set
+     to NULL; otherwise, it should never be NULL.
 
    After initialization is complete, both are equal.  However, the
    first one remains equal to &_cffi_start_and_call_python until the
@@ -962,7 +963,7 @@ static int _cffi_initialize_python(void)
 
         if (f != NULL && f != Py_None) {
             PyFile_WriteString("\nFrom: " _CFFI_MODULE_NAME
-                               "\ncompiled with cffi version: 1.15.0"
+                               "\ncompiled with cffi version: 1.16.0"
                                "\n_cffi_backend module: ", f);
             modules = PyImport_GetModuleDict();
             mod = PyDict_GetItemString(modules, "_cffi_backend");
@@ -1020,6 +1021,15 @@ static int _cffi_carefully_make_gil(void)
        Python < 3.8 because someone might use a mixture of cffi
        embedded modules, some of which were compiled before this file
        changed.
+
+       In Python >= 3.12, this stopped working because that particular
+       tp_version_tag gets modified during interpreter startup.  It's
+       arguably a bad idea before 3.12 too, but again we can't change
+       that because someone might use a mixture of cffi embedded
+       modules, and no-one reported a bug so far.  In Python >= 3.12
+       we go instead for PyCapsuleType.tp_as_buffer, which is supposed
+       to always be NULL.  We write to it temporarily a pointer to
+       a struct full of NULLs, which is semantically the same.
     */
 
 #ifdef WITH_THREAD
@@ -1044,19 +1054,32 @@ static int _cffi_carefully_make_gil(void)
         }
     }
 # else
+#  if PY_VERSION_HEX < 0x030C0000
     int volatile *lock = (int volatile *)&PyCapsule_Type.tp_version_tag;
-    int old_value, locked_value;
+    int old_value, locked_value = -42;
     assert(!(PyCapsule_Type.tp_flags & Py_TPFLAGS_HAVE_VERSION_TAG));
+#  else
+    static struct ebp_s { PyBufferProcs buf; int mark; } empty_buffer_procs;
+    empty_buffer_procs.mark = -42;
+    PyBufferProcs *volatile *lock = (PyBufferProcs *volatile *)
+        &PyCapsule_Type.tp_as_buffer;
+    PyBufferProcs *old_value, *locked_value = &empty_buffer_procs.buf;
+#  endif
 
     while (1) {    /* spin loop */
         old_value = *lock;
-        locked_value = -42;
         if (old_value == 0) {
             if (cffi_compare_and_swap(lock, old_value, locked_value))
                 break;
         }
         else {
+#  if PY_VERSION_HEX < 0x030C0000
             assert(old_value == locked_value);
+#  else
+            /* The pointer should point to a possibly different
+               empty_buffer_procs from another C extension module */
+            assert(((struct ebp_s *)old_value)->mark == -42);
+#  endif
             /* should ideally do a spin loop instruction here, but
                hard to do it portably and doesn't really matter I
                think: PyEval_InitThreads() should be very fast, and

from clingo.

yangdinglou avatar yangdinglou commented on September 1, 2024

It works as far as I tried, thanks @rkaminsk

from clingo.

ejgroene avatar ejgroene commented on September 1, 2024

I also tried, and it does work, but it depends on old version of Python:

python >=3.9,<3.10.0a0

See https://conda-metadata-app.streamlit.app/?q=conda-forge%2Flinux-64%2Fclingo-5.7.1-py39hc10206b_1.conda. (Check the date).

I followed the instructions, but did not find a newer or better package.

from clingo.

yangdinglou avatar yangdinglou commented on September 1, 2024

@ejgroene While there are different build versions (e.g., https://conda-metadata-app.streamlit.app/?q=conda-forge%2Flinux-64%2Fclingo-5.7.1-py312h30efb56_1.conda ).

from clingo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.