question about C extensions

Ralph Butler rbutler at mtsu.edu
Sat Mar 24 19:51:34 EDT 2007


Hi:
I have a question about extending python with C.  I have read the docs 
and done some googling, but come up short on this particular (small) 
problem.  I want to write a c extension to int.  In particular, I want 
to grab the memory for the int from an alternative heap.  I am confused 
about 2 things:  (1) Do I need to call the __init__ function for int 
itself, and if so, how do I do that?  (2)  Do I supply my own tp_alloc 
function to retrieve the memory for my new elements, and if so, what 
should it look like?  (Assume for the moment that I simply plan to do a 
malloc.)

I have attached code that does most of the work and has my initials 
(RMB) at a couple of the pieces of code I think I may need.

Any pointers to fairly specific examples would be appreciated.  I have 
found non-specific examples a bit confusing.

Thanks.
--ralph

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: setup.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20070324/ccdbf59e/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: t1.py
URL: <http://mail.python.org/pipermail/python-list/attachments/20070324/ccdbf59e/attachment-0001.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: intext.c
URL: <http://mail.python.org/pipermail/python-list/attachments/20070324/ccdbf59e/attachment.c>


More information about the Python-list mailing list