On Sunday, September 9, 2012 2:54:27 AM UTC+4, ZyX wrote:
> > No one's undefying PY_SSIZE_T_CLEAN in Python.h. Why? =)
> 
> >
> 
> > There are two different functions one for int length and the other for 
> > Py_ssize_t. We define PY_SSIZE_T_CLEAN and that would work with implicit 
> > linking (through linker flags, -lpython), because preprocessor 
> > conditionally replaces one for the other in modsupport.h, but we need to 
> > handle that ourselves with explicit linking, namely dlsym 
> > _PyArg_ParseTuple_SizeT instead of PyArg_ParseTuple from libpython.so.
> 
> 
> 
> Yes. But you must do this or your patch just adds a bunch of conditions
> 
> 
> 
>     #if 0 /* Originally #ifndef PY_SSIZE_T_CLEAN */
> 
>     /* Import int function variants */
> 
>     #else
> 
>     /* Import Py_ssize_t function variants */
> 
>     #endif
> 
> . Don’t you think having “#if 0”-like conditions is strange? You should 
> undefine PY_SSIZE_T_CLEAN based on some conditions, remove one of the 
> branches or replace “#ifndef” with what makes more sense.

ZyX, 

You are right, we should define PY_SSIZE_T_CLEAN for Python >= 2.5. Updated my 
patch. Thanks!

Maxim

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
diff -r 1052677493be src/if_python.c
--- a/src/if_python.c	Wed Sep 05 19:17:42 2012 +0200
+++ b/src/if_python.c	Sun Sep 09 13:37:16 2012 +0400
@@ -44,8 +44,6 @@
 # undef _XOPEN_SOURCE	/* pyconfig.h defines it as well. */
 #endif
 
-#define PY_SSIZE_T_CLEAN
-
 #include <Python.h>
 #if defined(MACOS) && !defined(MACOS_X_UNIX)
 # include "macglue.h"
@@ -54,6 +52,10 @@
 #undef main /* Defined in python.h - aargh */
 #undef HAVE_FCNTL_H /* Clash with os_win32.h */
 
+#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000
+# define PY_SSIZE_T_CLEAN
+#endif
+
 static void init_structs(void);
 
 #define PyBytes_FromString PyString_FromString
@@ -358,8 +360,15 @@
     PYTHON_PROC *ptr;
 } python_funcname_table[] =
 {
+#ifndef PY_SSIZE_T_CLEAN
     {"PyArg_Parse", (PYTHON_PROC*)&dll_PyArg_Parse},
     {"PyArg_ParseTuple", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
+    {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue},
+#else
+    {"_PyArg_Parse_SizeT", (PYTHON_PROC*)&dll_PyArg_Parse},
+    {"_PyArg_ParseTuple_SizeT", (PYTHON_PROC*)&dll_PyArg_ParseTuple},
+    {"_Py_BuildValue_SizeT", (PYTHON_PROC*)&dll_Py_BuildValue},
+#endif
     {"PyMem_Free", (PYTHON_PROC*)&dll_PyMem_Free},
     {"PyMem_Malloc", (PYTHON_PROC*)&dll_PyMem_Malloc},
     {"PyDict_SetItemString", (PYTHON_PROC*)&dll_PyDict_SetItemString},
@@ -422,7 +431,6 @@
     {"PySys_SetArgv", (PYTHON_PROC*)&dll_PySys_SetArgv},
     {"PyType_Type", (PYTHON_PROC*)&dll_PyType_Type},
     {"PyType_Ready", (PYTHON_PROC*)&dll_PyType_Ready},
-    {"Py_BuildValue", (PYTHON_PROC*)&dll_Py_BuildValue},
     {"Py_FindMethod", (PYTHON_PROC*)&dll_Py_FindMethod},
 # if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000 \
 	&& SIZEOF_SIZE_T != SIZEOF_INT
diff -r 1052677493be src/if_python3.c
--- a/src/if_python3.c	Wed Sep 05 19:17:42 2012 +0200
+++ b/src/if_python3.c	Sun Sep 09 13:37:16 2012 +0400
@@ -42,8 +42,6 @@
 # undef _DEBUG
 #endif
 
-#define PY_SSIZE_T_CLEAN
-
 #ifdef F_BLANK
 # undef F_BLANK
 #endif
@@ -66,6 +64,10 @@
 #undef main /* Defined in python.h - aargh */
 #undef HAVE_FCNTL_H /* Clash with os_win32.h */
 
+#if defined(PY_VERSION_HEX) && PY_VERSION_HEX >= 0x02050000
+# define PY_SSIZE_T_CLEAN
+#endif
+
 static void init_structs(void);
 
 /* The "surrogateescape" error handler is new in Python 3.1 */
@@ -328,7 +330,13 @@
     {"PySys_SetArgv", (PYTHON_PROC*)&py3_PySys_SetArgv},
     {"Py_SetPythonHome", (PYTHON_PROC*)&py3_Py_SetPythonHome},
     {"Py_Initialize", (PYTHON_PROC*)&py3_Py_Initialize},
+#ifndef PY_SSIZE_T_CLEAN
     {"PyArg_ParseTuple", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
+    {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue},
+#else
+    {"_PyArg_ParseTuple_SizeT", (PYTHON_PROC*)&py3_PyArg_ParseTuple},
+    {"_Py_BuildValue_SizeT", (PYTHON_PROC*)&py3_Py_BuildValue},
+#endif
     {"PyMem_Free", (PYTHON_PROC*)&py3_PyMem_Free},
     {"PyMem_Malloc", (PYTHON_PROC*)&py3_PyMem_Malloc},
     {"PyList_New", (PYTHON_PROC*)&py3_PyList_New},
@@ -364,7 +372,6 @@
     {"PyObject_GetIter", (PYTHON_PROC*)&py3_PyObject_GetIter},
     {"PyLong_FromLong", (PYTHON_PROC*)&py3_PyLong_FromLong},
     {"PyDict_New", (PYTHON_PROC*)&py3_PyDict_New},
-    {"Py_BuildValue", (PYTHON_PROC*)&py3_Py_BuildValue},
     {"PyType_Ready", (PYTHON_PROC*)&py3_PyType_Ready},
     {"PyDict_SetItemString", (PYTHON_PROC*)&py3_PyDict_SetItemString},
     {"PyLong_AsLong", (PYTHON_PROC*)&py3_PyLong_AsLong},

Raspunde prin e-mail lui