Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26392

Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rahul03535@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'exception': 0.03; '-1)': 0.07; 'except:': 0.07; 'exception.': 0.07; 'executed': 0.07; 'only,': 0.07; 'try:': 0.07; 'used.': 0.07; 'python': 0.09; 'block.': 0.09; 'subject:()': 0.09; 'subject:module': 0.09; 'subject:setting': 0.09; 'throws': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python-list': 0.10; 'subject:error': 0.11; 'extension': 0.13; 'cases': 0.15; 'slightly': 0.15; 'value.': 0.15; 'cascading': 0.16; 'pointer,': 0.16; 'pyobject*': 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; 'tim': 0.18; 'module': 0.19; 'written': 0.20; 'supposed': 0.21; 'cc:2**0': 0.23; 'statement': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'setting': 0.26; 'core': 0.27; 'execution': 0.27; 'functions.': 0.27; 'propose': 0.27; "doesn't": 0.28; "i'm": 0.29; 'usually': 0.30; 'thursday,': 0.30; 'function': 0.30; 'error': 0.30; 'code': 0.31; 'url:python': 0.32; 'help,': 0.32; 'goes': 0.33; 'docs': 0.33; 'null': 0.33; 'anyone': 0.33; 'code:': 0.33; 'received:google.com': 0.34; 'false': 0.35; 'returning': 0.35; 'received:209.85': 0.35; 'add': 0.36; 'except': 0.36; 'but': 0.36; 'url:org': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'some': 0.38; 'url:docs': 0.38; 'where': 0.40; 'think': 0.40; 'link': 0.60; 'first': 0.61; 'free': 0.61; 'here:': 0.62; 'different': 0.63; 'success': 0.63; 'behavior': 0.64; 'august': 0.66; 'combining': 0.71; 'special': 0.73; 'saw': 0.75; '"most': 0.84; 'confusing': 0.84; 'different.': 0.84; 'indicator': 0.91; 'convinced': 0.93
Newsgroups comp.lang.python
Date Thu, 2 Aug 2012 02:50:21 -0700 (PDT)
In-Reply-To <mailman.2860.1343900238.4697.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.248.161.59; posting-account=xyzyTgoAAAB2OaRT58zhH9j7aeiDRJa3
References <fa944ed7-8101-4b2f-a49a-363eb8d05d1d@googlegroups.com> <mailman.2856.1343898392.4697.python-list@python.org> <acb579e1-b716-46d9-b732-9dca094cedac@googlegroups.com> <mailman.2860.1343900238.4697.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
X-Google-IP 122.248.161.59
MIME-Version 1.0
Subject Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString()
From rahul <rahul03535@gmail.com>
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Message-ID <mailman.2861.1343901024.4697.python-list@python.org> (permalink)
Lines 81
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343901024 news.xs4all.nl 6840 [2001:888:2000:d::a6]:60048
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26392

Show key headers only | View raw


When I use same code base for Python 3.x, then behavior is different. In this when I return false then also it throws exception but only when any other statement get executed after this 

like below code:
 ...
 ...
   b = None
   try:
     a = testModule.check(None)
   except:
     b = sys.exc_info()
then code execution doesn't come to except block.
But when I add one statement after calling check function then code execution goes into except block. 

 ...
 ...
 b = None
 try:
   a = testModule.check(None)
   print( a )
 except:
   b = sys.exc_info()


On Thursday, 2 August 2012 15:07:08 UTC+5:30, Tim Golden  wrote:
> 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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 01:57 -0700
  Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 10:06 +0100
    Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:21 -0700
    Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:21 -0700
      Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 10:37 +0100
        Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:50 -0700
          Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Tim Golden <mail@timgolden.me.uk> - 2012-08-02 11:45 +0100
          Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() Stefan Behnel <stefan_ml@behnel.de> - 2012-08-02 12:54 +0200
        Re: C extension module doesn't throw exception after setting error indicator through PyErr_SetString() rahul <rahul03535@gmail.com> - 2012-08-02 02:50 -0700

csiph-web