Re: [PATCH 1 of 5] python3.13: use sys.executable instead of removed Py_GetProgramFullPath

2024-09-04 Thread Pierre-Yves David

Series imported here

https://foss.heptapod.net/mercurial/mercurial-devel/-/merge_requests/935

I'll look at Manuel comment later

On 1/12/24 00:59, Mads Kiilerich wrote:

# HG changeset patch
# User Mads Kiilerich
# Date 1705001527 -3600
#  Thu Jan 11 20:32:07 2024 +0100
# Branch stable
# Node ID ab3021e9b0012db64e5bdc70e3f5a36324925d8c
# Parent  3f87e0d305cda6e66139a1969cd2cedd45477139
python3.13: use sys.executable instead of removed Py_GetProgramFullPath

I could not make it work with the PyConfig API from the extension. But fetching
sys.executable seems to work fine and isn't that verbose.

diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -1232,6 +1232,15 @@ static int check_python_version(void)
 * should only occur in unusual circumstances (e.g. if sys.hexversion
 * is manually set to an invalid value). */
if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) {
+   PyObject *sys = PyImport_ImportModule("sys"), *executable;
+   if (!sys) {
+   return -1;
+   }
+   executable = PyObject_GetAttrString(sys, "executable");
+   Py_DECREF(sys);
+   if (!executable) {
+   return -1;
+   }
PyErr_Format(PyExc_ImportError,
 "%s: The Mercurial extension "
 "modules were compiled with Python " PY_VERSION
@@ -1240,7 +1249,8 @@ static int check_python_version(void)
 "sys.hexversion=%ld: "
 "Python %s\n at: %s",
 versionerrortext, hexversion, Py_GetVersion(),
-Py_GetProgramFullPath());
+PyUnicode_AsUTF8(executable));
+   Py_DECREF(executable);
return -1;
}
return 0;

___
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel


--
Pierre-Yves David
___
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel


Re: [PATCH 1 of 5] python3.13: use sys.executable instead of removed Py_GetProgramFullPath

2024-02-01 Thread Manuel Jacob

On 12/01/2024 00.59, Mads Kiilerich wrote:

# HG changeset patch
# User Mads Kiilerich 
# Date 1705001527 -3600
#  Thu Jan 11 20:32:07 2024 +0100
# Branch stable
# Node ID ab3021e9b0012db64e5bdc70e3f5a36324925d8c
# Parent  3f87e0d305cda6e66139a1969cd2cedd45477139
python3.13: use sys.executable instead of removed Py_GetProgramFullPath


According to 
https://docs.python.org/3.13/c-api/init.html#c.Py_GetProgramFullPath, 
it’s only deprecated, but not removed. Do you have other information?



I could not make it work with the PyConfig API from the extension. But fetching
sys.executable seems to work fine and isn't that verbose.


I think the PyConfig struct memory is released after interpreter 
initialization, so I think PyConfig is out of question anyway.


https://docs.python.org/3.13/c-api/init.html#c.Py_GetProgramFullPath 
suggests sys.executable as the alternative, so feel to change the patch 
description to be more bold. :)



diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -1232,6 +1232,15 @@ static int check_python_version(void)
 * should only occur in unusual circumstances (e.g. if sys.hexversion
 * is manually set to an invalid value). */
if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) {
+   PyObject *sys = PyImport_ImportModule("sys"), *executable;
+   if (!sys) {
+   return -1;
+   }
+   executable = PyObject_GetAttrString(sys, "executable");


You could use PySys_GetObject().


+   Py_DECREF(sys);
+   if (!executable) {
+   return -1;
+   }
PyErr_Format(PyExc_ImportError,
 "%s: The Mercurial extension "
 "modules were compiled with Python " PY_VERSION
@@ -1240,7 +1249,8 @@ static int check_python_version(void)
 "sys.hexversion=%ld: "
 "Python %s\n at: %s",
 versionerrortext, hexversion, Py_GetVersion(),
-Py_GetProgramFullPath());
+PyUnicode_AsUTF8(executable));
+   Py_DECREF(executable);
return -1;
}
return 0;

___
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel


___
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel


[PATCH 1 of 5] python3.13: use sys.executable instead of removed Py_GetProgramFullPath

2024-01-11 Thread Mads Kiilerich
# HG changeset patch
# User Mads Kiilerich 
# Date 1705001527 -3600
#  Thu Jan 11 20:32:07 2024 +0100
# Branch stable
# Node ID ab3021e9b0012db64e5bdc70e3f5a36324925d8c
# Parent  3f87e0d305cda6e66139a1969cd2cedd45477139
python3.13: use sys.executable instead of removed Py_GetProgramFullPath

I could not make it work with the PyConfig API from the extension. But fetching
sys.executable seems to work fine and isn't that verbose.

diff --git a/mercurial/cext/parsers.c b/mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c
+++ b/mercurial/cext/parsers.c
@@ -1232,6 +1232,15 @@ static int check_python_version(void)
 * should only occur in unusual circumstances (e.g. if sys.hexversion
 * is manually set to an invalid value). */
if ((hexversion == -1) || (hexversion >> 16 != PY_VERSION_HEX >> 16)) {
+   PyObject *sys = PyImport_ImportModule("sys"), *executable;
+   if (!sys) {
+   return -1;
+   }
+   executable = PyObject_GetAttrString(sys, "executable");
+   Py_DECREF(sys);
+   if (!executable) {
+   return -1;
+   }
PyErr_Format(PyExc_ImportError,
 "%s: The Mercurial extension "
 "modules were compiled with Python " PY_VERSION
@@ -1240,7 +1249,8 @@ static int check_python_version(void)
 "sys.hexversion=%ld: "
 "Python %s\n at: %s",
 versionerrortext, hexversion, Py_GetVersion(),
-Py_GetProgramFullPath());
+PyUnicode_AsUTF8(executable));
+   Py_DECREF(executable);
return -1;
}
return 0;

___
Mercurial-devel mailing list
Mercurial-devel@lists.mercurial-scm.org
https://lists.mercurial-scm.org/mailman/listinfo/mercurial-devel