Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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; 'int': 0.05; 'char': 0.07; 'fine,': 0.07; 'python': 0.07; 'null;': 0.09; 'question:': 0.09; 'this:': 0.11; 'users,': 0.14; '*args)': 0.16; '*self,': 0.16; 'above?': 0.16; 'py_none;': 0.16; 'pyobject': 0.16; 'pyobject*': 0.16; 'subject:() ': 0.16; 'skip:" 40': 0.16; 'static': 0.16; 'code': 0.22; 'module,': 0.23; 'library.': 0.25; 'received:209.85.161.46': 0.26; 'received:mail- fx0-f46.google.com': 0.26; "i'm": 0.26; 'function': 0.27; 'message-id:@mail.gmail.com': 0.28; 'received:209.85.161': 0.29; 'skip:( 20': 0.31; 'import': 0.32; 'to:addr:python-list': 0.32; 'thank': 0.32; 'sorry': 0.33; 'from:charset:iso-8859-1': 0.33; 'module': 0.33; 'uses': 0.34; 'skip:" 10': 0.34; 'else': 0.37; 'skip:o 20': 0.37; 'should': 0.37; 'received:209.85': 0.37; 'received:google.com': 0.38; 'but': 0.38; 'provider': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'received:209': 0.39; 'works': 0.40; 'header:Received:5': 0.40; 'messages': 0.40; 'skip:h 20': 0.60; 'here': 0.65 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=VHmL1VCLc4kzD8lhBslAM0dH8PRP1K1hNtYwRXW7SD0=; b=jIZgqowLktU4Q6AK0jNJixbiBg+YfNSa5SzHuEsaotqbjvaz07u6mBR+99AdfYQ1J+ iS+B5LyzhNLTlWVvd8Fr6f+daqqXWAPoHBnZWksBBg3wLqrla8u+D1VVW3FFtoIbFUQR z+OLPmIdpbCMBy00VMMGh2r4+4RAQmz4zcNLg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=E9RHVhTb2LMKR0SDWKNPg8G33+cmC1GeWzrRe+5CYzDaEVrF8eUgrgvt+IJGm8pcTN L+4jvCrCPjcFxS00UUggi6aJ5QcXSnzLUGlyR1yWhuDAMSzzp7rBv93PhYQvm/EES367 P59pbLit1e0fIvjYSoBNTmXAIz203kfJvsVHU= MIME-Version: 1.0 Date: Tue, 26 Apr 2011 11:48:15 +0200 Subject: Py_INCREF() incomprehension From: =?ISO-8859-1?Q?Ervin_Heged=FCs?= To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 57 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303811298 news.xs4all.nl 41110 [::ffff:82.94.164.166]:52579 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:4029 Hello Python users, I'm working on a Python module in C - that's a cryptographic module, which uses a 3rd-party lib from a provider (a bank). This module will encrypt and decrypt the messages for the provider web service. Here is a part of source: static PyObject* mycrypt_encrypt(PyObject *self, PyObject *args) { int cRes = 0; int OutLen = 0; char * url; char * path; if (!PyArg_ParseTuple(args, "ss", &url, &path)) { return NULL; } OutLen = strlen(url)*4; outdata=calloc(OutLen, sizeof(char)); if (!outdata) { handle_err(UER_NOMEM); return NULL; } cRes = ekiEncodeUrl (url, strlen(url)+1, outdata, &OutLen, 1, path); if (cRes == 0) { return Py_BuildValue("s", outdata); } else { handle_err(cRes); return NULL; } return Py_None; } where ekiEncodeUrl is in a 3rd-party library. I should call this function from Python like this: import mycrypt message = "PID=IEB0001&MSGT=10&TRID=000000012345678" crypted = mycrypt(mymessage, "/path/to/key"); Everything works fine, but sorry for the recurrent question: where should I use the Py_INCREF()/Py_DECREF() in code above? Thank you, cheers: a.