Path: csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '-1)': 0.07; 'exception.': 0.07; 'only,': 0.07; 'used.': 0.07; 'subject:()': 0.09; 'subject:module': 0.09; 'subject:setting': 0.09; 'subject:error': 0.11; 'extension': 0.13; 'cases': 0.15; 'slightly': 0.15; 'value.': 0.15; 'cascading': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'message-id:@timgolden.me.uk': 0.16; 'pointer,': 0.16; 'pyobject*': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'subject: \n ': 0.16; 'subject:exception': 0.16; 'subject:through': 0.16; 'tjg': 0.16; 'uncommon': 0.16; 'wording': 0.16; 'wrote:': 0.17; 'integer': 0.17; 'pointer': 0.17; 'module': 0.19; 'written': 0.20; 'supposed': 0.21; "i've": 0.23; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'setting': 0.26; 'core': 0.27; 'functions.': 0.27; 'propose': 0.27; "doesn't": 0.28; "i'm": 0.29; 'usually': 0.30; 'function': 0.30; 'error': 0.30; 'url:python': 0.32; 'help,': 0.32; 'docs': 0.33; 'null': 0.33; 'received:192.168.100': 0.33; 'anyone': 0.33; 'to:addr :python-list': 0.33; 'returning': 0.35; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'subject:: ': 0.38; 'some': 0.38; 'url:docs': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'where': 0.40; 'received:192.168': 0.40; 'think': 0.40; 'link': 0.60; 'first': 0.61; 'free': 0.61; 'here:': 0.62; 'different': 0.63; 'success': 0.63; 'combining': 0.71; 'from:addr:mail': 0.71; 'special': 0.73; 'saw': 0.75; '"most': 0.84; 'confusing': 0.84; 'indicator': 0.91; 'convinced': 0.93 Date: Thu, 02 Aug 2012 10:37:08 +0100 From: Tim Golden User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 29 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1343900238 news.xs4all.nl 6930 [2001:888:2000:d::a6]:57004 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:26390 On 02/08/2012 10:21, rahul wrote: > > Hi TJG, > > The above link also doesn't strictly said that return value should be > NULL only, it only said that usually NULL pointer used. No where I > saw that it is nessasory t > > At http://docs.python.org/c-api/exceptions.html. it is written that > "Most functions also return an error indicator, usually NULL if they > are supposed to return a pointer, or -1 if they return an integer > (exception: the PyArg_*() functions return 1 for success and 0 for > failure)." this also told that usually NULL is used but we can change > the return error indicator to any value. As like PyArg_*() used 0 for > error value. The docs you quote are very slightly confusing because they're combining the standard practice (return NULL), the uncommon alternative (return -1) and a few special cases present in the core functions. In short, any function you expose in an extension module will be returning a PyObject* and should return NULL if it is setting or cascading an exception. I'm not convinced that the docs need altering here: this is the first time I've come across anyone who was confused. But if you think some different wording might help, feel free to propose something. TJG