[Python-bugs-list] [ python-Bugs-485153 ] Erroneous Fail of PyEval_CallObject
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 28 Nov 2001 03:25:27 -0800
Bugs item #485153, was opened at 2001-11-24 11:46
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=485153&group_id=5470
Category: Documentation
Group: Python 2.1.1
Status: Open
Resolution: None
Priority: 5
Submitted By: Cl. Schmidt (clemm)
Assigned to: Fred L. Drake, Jr. (fdrake)
Summary: Erroneous Fail of PyEval_CallObject
Initial Comment:
If embedding python v2.1.1 in a Windows MFC project,
it shows the following behaviour:
When a call to e.g. PyArgParseTuple had failed,
a subsequent call to PyEval_CallObject fails. The
parameters of the both calls are completely
independent and have nothing to do with each other.
Trying to retrieve the error text of the failed
PyEval_CallObject returns the error of the
PyArgParseTuple, namely
"new style getargs format but argument list is not a
tuple".
If the first (erroneous) call to PyArgParseTuple is
commented, the PyEval_CallObject works without any
problem.
The attached code snippet documents the error.
No attempts have been made to reproduce the behaviour
in other environments.
----------------------------------------------------------------------
>Comment By: Cl. Schmidt (clemm)
Date: 2001-11-28 03:25
Message:
Logged In: YES
user_id=382038
Maybe I violated a python coding rule. In my case, I am
embedding python
in a windows C++ program. I am having neither a console
window nor a caller to the method
where the error occurred. Thus, raising an exception would
not have made any sense.
It is not correct to state that I ignore the error, because
there is a return value from the function which is
of course retrieved.
It is at least disturbing when after having e.g. forgotten
to clear an error,
three subsequent calls to the C API succeed (as in my
case), and suddenly one fails, reporting something
completely irrelevant to that error. This behaviour is
different in other cases. In another, very similar
scenario, the call to PyEval_CallObject succeeded.
I agree that it is a documentation issue. The doc should
state something like this:
"If you do not raise an exception to python and do not call
PyErr_Clear, the results are unpredictable."
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-11-27 13:14
Message:
Logged In: YES
user_id=31435
Changed to Documentation and reassigned to Fred: Fred, I
don't think we ever spell out that C API errors must be
passed on or explicitly cleared (before calling another C
API function). The Exceptions section of the C API manual
does not spell this out. It's possible <wink> that
the "Intermezzo: Errors and Exceptions" section of the
Extending and Embedding manual is clear enough -- your call.
----------------------------------------------------------------------
Comment By: Tim Peters (tim_one)
Date: 2001-11-27 12:47
Message:
Logged In: YES
user_id=31435
I don't understand what "the bug" is here: if you get an
error return from a Python C API function, and you intend
to ignore the error, you must call PyErr_Clear() before
calling another Python C API function. You're not doing
that.
The attachment isn't executable as-is, so I can't say
whether that fixes your particular problem -- but it's
never legitimate to ignore an error in C API coding (you
must either pass it on to your caller or explicitly clear
it).
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=485153&group_id=5470