FYI this is a completely hypothetical situation here. I am not doing
any developing in the Python/C API, and may never do so. But I'm
experimenting with different levels of architecture, mainly just to
see how things work. Right now the situation is, suppose I have some
function I want to call from Python, but in the end I want to
implement it in basically raw C. One approach I thought of was, okay,
I'll Pyrex a really simple function, compile it and go into the c
file, then write most of what I need from there. My main thought about
reference counting:

Python objects seem to need heavy babysitting in terms of reference
counting, especially if you look at some Pyrex autogen code. But it
seems like the C compiler will keep track of reference counts for C
types. Just supposing (again, completely hypothetical) I decide to
write something in the P/C API completely without Pyrex or SageX, but
I want a Python function or two to get called at the top, and I want C
to do the rest. My impression is that I need to keep track of
reference counts for PyObjs but not C variables. Is this true? I have
never had to worry about reference counting when writing pure C, so
why do PyObjects need that extra help?

On Feb 21, 10:57 am, Robert Bradshaw <[EMAIL PROTECTED]>
wrote:
> I'll jump in and answer you questions.
>
> On Feb 21, 2007, at 10:18 AM, Robert Miller wrote:
>
> > David,
>
> > I was wondering if you could help get me started here. I've been
> > reading the Python/C API, and I've been browsing both sides of a lot
> > of Pyrex: for argument's sake, let's say the Complex double matrices.
> > First, I'm wondering how they're cdef-ing classes that they're then
> > calling from Python.
>
> cdef has two uses. The first is to declare a class as an extension
> type (so it can contain cdef'd property and functions), and the
> second is to declare a property/function as a c type. Cdef'd
> extension types are accessible from python, just not their cdef'd
> properties/functions.
>
> > Also, what do .so files in site-packages have to
> > do with specific classes in the repository?
>
> > (
> > sage:
> > sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense??
> > Type:           type
> > Base Class:     <type 'type'>
> > String Form:    <type
> > 'sage.matrix.matrix_complex_double_dense.Matrix_complex_double_dense'>
> > Namespace:      Interactive
> > File:
> > /Volumes/DATA/sage/local/lib/python2.5/site-packages/sage/matrix/
> > matrix_complex_double_dense.so
> > )
>
> Each .pyx file has an associated shared object library containing all
> the classes/methods/etc. needed.
>
>
>
> > I have some questions also about reference counting, but let's
> > start here.....
>
> You shouldn't have to worry about it too much. Basically, if you
> malloc something manually, you have to worry about freeing it. If you
> call the C/Python API directly (which you probably won't need to do),
> you have to worry if the returned PyObject* is a borrowed or new
> copy. But otherwise pyrex will take care of it all for you.
>
>
>
> > --
> > Robert L. Miller
> >http://www.robertlmiller.com/


--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://sage.scipy.org/sage/ and http://modular.math.washington.edu/sage/
-~----------~----~----~----~------~----~------~--~---

Reply via email to