Re: Py_INCREF() incomprehension

2011-05-02 Thread Stefan Behnel
Hegedüs, Ervin, 02.05.2011 08:41: Thomas, I guess this is the point where yo should start printf programing. oh', already done :) FWIW, Cython 0.14+ has special support for gdb now, so, in addition to print and printf debugging, you can also use gdb to explore the state of your application

Re: Py_INCREF() incomprehension

2011-05-01 Thread Hegedüs , Ervin
hello, Thomas, Gregory, thank you for your ansrwers, > I guess this is the point where yo should start printf programing. oh', already done :) > * What happens during module initialization? successfully initialized, > * What happens n the functions? > * Where does the stuff fail? > * What a

Re: Py_INCREF() incomprehension

2011-05-01 Thread Thomas Rachel
Am 01.05.2011 22:00, schrieb Hegedüs Ervin: My module contains just 4 functions (in C), which translate 3rd party lib to Python. The name would be _mycrypt.so example. I wrapped it a pure Python module, its name is mycrypt.py. Then, I've import pure Python module in a main program, like this:

Re: Py_INCREF() incomprehension

2011-05-01 Thread Gregory Ewing
Hegedüs Ervin wrote: I've put it a Py_INCREF() after every PyModule_AddObject(), eg.: PyModule_AddObject(o, "error", cibcrypt_error_nokey); Py_INCREF(cibcrypt_error_nokey); That looks correct, because PyModule_AddObject is documented as stealing a reference to the object. By the way,

Re: Py_INCREF() incomprehension

2011-05-01 Thread Hegedüs Ervin
hello, On Wed, Apr 27, 2011 at 11:58:18AM +0200, Thomas Rachel wrote: > Am 26.04.2011 20:44, schrieb Hegedüs Ervin: > > >and (maybe) final question: :) > > > >I defined many exceptions: > > > >static PyObject *cibcrypt_error_nokey; > >static PyObject *cibcrypt_error_nofile; > >static PyObject *ci

Re: Py_INCREF() incomprehension

2011-04-27 Thread Thomas Rachel
Am 26.04.2011 20:44, schrieb Hegedüs Ervin: and (maybe) final question: :) I defined many exceptions: static PyObject *cibcrypt_error_nokey; static PyObject *cibcrypt_error_nofile; static PyObject *cibcrypt_error_badpad; ... void handle_err(int errcode) { switch(errcode) { case

Re: Py_INCREF() incomprehension

2011-04-26 Thread Hegedüs Ervin
Hello, > >But, when I don't read input arguments (there isn't > >PyArg_ParseTuple), there isn't exception. > > > >How Python handle the number of arguments? > > From what you tell it: with PyArg_ParseTuple(). (see > http://docs.python.org/c-api/arg.html for this). > > You give a format string (i

Re: Py_INCREF() incomprehension

2011-04-26 Thread Thomas Rachel
Am 26.04.2011 19:28, schrieb Hegedüs Ervin: Another question: here is an another part ot my code: static PyObject* mycrypt_decrypt(PyObject *self, PyObject *args) { if (!PyArg_ParseTuple(args, "ss",&data,&path)) { return NULL; } ... } When I call this function from Python

Re: Py_INCREF() incomprehension

2011-04-26 Thread Hegedüs Ervin
Dear Thomas, thank you again, > The ownership rules say that the input parameter belongs to the > caller who holds it at least until we return. (We just "borrow" it.) > So no action needed. ok, its' clear, I understand, > >>* Py_BuildValue() > > This function "transfers ownership", as it is n

Re: Py_INCREF() incomprehension

2011-04-26 Thread Thomas Rachel
Am 26.04.2011 16:03, schrieb Hegedüs Ervin: I've read API doc (which you've included in another mail), but that's not clear for me. :( No probem, I'll go in detail, now as I have read it again. (I didn't want to help from memory, as it is some time ago I worked with it, and didn't have time

Re: Py_INCREF() incomprehension

2011-04-26 Thread Hegedüs Ervin
Hello, thanks for the answer, > >Everything works fine, but sorry for the recurrent question: where > >should I use the Py_INCREF()/Py_DECREF() in code above? > > That depends on the functions which are called. It should be given > in the API description. The same counts for the incoming paramet

Re: Py_INCREF() incomprehension

2011-04-26 Thread Thomas Rachel
Am 26.04.2011 11:48, schrieb Ervin Hegedüs: Everything works fine, but sorry for the recurrent question: where should I use the Py_INCREF()/Py_DECREF() in code above? That depends on the functions which are called. It should be given in the API description. The same counts for the incoming pa

Re: Py_INCREF() incomprehension

2011-04-26 Thread Thomas Rachel
Am 26.04.2011 14:21, schrieb Thomas Rachel: Especially look at the concepts called "borrowed reference" vs. "owned reference". http://docs.python.org/extending/extending.html#reference-counting-in-python will be quite helpful. Thomas -- http://mail.python.org/mailman/listinfo/python-list

Re: Py_INCREF() incomprehension

2011-04-26 Thread Hegedüs Ervin
hello, sorry for the typo, these are many "cibcrypt" reference, this is the real name of my module - I just replaced it somewhere to "mycrypt" - and somewhere I forgot... :( > ... > static PyObject *cibcrypt_error_badparm; > ... > > void handle_err(int errcode) { > switch(errcode) { > ...

Re: Py_INCREF() incomprehension

2011-04-26 Thread Hegedüs Ervin
Hello, thanks for the reply, > >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)) { > > Use the "s#" format instead to get

Re: Py_INCREF() incomprehension

2011-04-26 Thread Stefan Behnel
Ervin Hegedüs, 26.04.2011 11:48: 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 PyObje

Py_INCREF() incomprehension

2011-04-26 Thread Ervin Hegedüs
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,