[ python-Bugs-980925 ] Possible contradiction in "extending" and PyArg_ParseTuple()

SourceForge.net noreply at sourceforge.net
Sun Jun 27 20:33:04 EDT 2004


Bugs item #980925, was opened at 2004-06-27 20:02
Message generated for change (Comment added) made by tim_one
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=980925&group_id=5470

Category: Documentation
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Brett Cannon (bcannon)
Assigned to: Nobody/Anonymous (nobody)
Summary: Possible contradiction in "extending" and PyArg_ParseTuple()

Initial Comment:
In section 1.3 of the "extending" tutorial (http://www.python.org/
dev/doc/devel/ext/backToExample.html), in the discussion of the 
use of PyArg_ParseTuple() for a string argument, it says that "in 
Standard C, the variable ... should properly be declared as "const 
char *" ".  But if you look at any example code (such as in section 
1.7, which covers parsing arguments; http://www.python.org/dev/
doc/devel/ext/parseTuple.html) and the docs for 
PyArg_ParseTuple() (found at http://www.python.org/dev/doc/
devel/api/arg-parsing.html) just use ``char *`` as the type for the 
argument for a string.

Which is correct?  I suspect that it is not required but more correct 
to have the variables declared ``const char *`` since you are not 
supposed to play with the string that is being pointed to (which is 
probably why the Unicode arguments in the docs for 
PyArg_ParseTuple() say it is ``const char *`` instead of just 
``char *``).  If this is true I will change the docs and the tutorial 
to use ``const char *``.  But if it isn't, I will rip out the line saying 
that you should ``const char *`` since this is a contradiction at the 
moment of recommended practice.

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2004-06-27 20:33

Message:
Logged In: YES 
user_id=31435

Most of Python, and its docs, were written before C89 
("Standard C") was required.  const is used sporadically as a 
result, mostly just in newer code and docs.

Changing examples to use const char * should be fine, as 
that is best C practice.  Just make sure the examples still 
work <wink -- but sticking "const" in has a way of 
propagating; e.g., once you have a const char *, you can't 
pass it directly to a function taking a (non-const) char * 
argument anymore>.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=980925&group_id=5470



More information about the Python-bugs-list mailing list