[Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification (original) (raw)
M.-A. Lemburg mal at egenix.com
Mon Feb 13 23🔞23 CET 2006
- Previous message: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification
- Next message: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Tim Peters wrote:
[Jeremy]
I added some const to several API functions that take char* but typically called by passing string literals. [Tim] If he had stuck to that, we wouldn't be having this discussion :-) (that is, nobody passes string literals to PyArgParseTupleAndKeywords's kws argument). [Jeremy] They are passing arrays of string literals. In my mind, that was a nearly equivalent use case. I believe the C++ compiler complains about passing an array of string literals to char**. It's the consequences: nobody complains about tacking "const" on to a former honest-to-God "char *" argument that was in fact not modified, because that's not only helpful for C++ programmers, it's harmless for all programmers. For example, nobody could sanely object (and nobody did :-)) to adding const to the attribute-name argument in PyObjectSetAttrString(). Sticking to that creates no new problems for anyone, so that's as far as I ever went.
Well, it broke my C extensions... I now have this in my code:
/* The keyword array changed to const char* in Python 2.5 */ #if PY_VERSION_HEX >= 0x02050000
define Py_KEYWORDS_STRING_TYPE const char
#else
define Py_KEYWORDS_STRING_TYPE char
#endif ... static Py_KEYWORDS_STRING_TYPE *kwslist[] = {"yada", NULL}; ... if (!PyArg_ParseTupleAndKeywords(args,kws,format,kwslist,&a1)) goto onError;
The crux is that code which should be portable across Python versions won't work otherwise: you either get Python 2.5 xor Python 2.x (for x < 5) compatibility.
Not too happy about it, but then compared to the ssize_t changes and the relative imports PEP, this one is an easy one to handle.
-- Marc-Andre Lemburg eGenix.com
Professional Python Services directly from the Source (#1, Feb 13 2006)
Python/Zope Consulting and Support ... http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ... http://python.egenix.com/
::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::
- Previous message: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification
- Next message: [Python-Dev] Baffled by PyArg_ParseTupleAndKeywords modification
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]