Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73251
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-06-12 21:39 -0700 |
| Message-ID | <2c227aa6-bdf2-4c99-851a-564d7ce56159@googlegroups.com> (permalink) |
| Subject | C-API proper initialization and deallocation of subclasses |
| From | ptb <petertbrady@gmail.com> |
Hello all, I decided to play around with the C-API and have gotten stuck. I went through the Shoddy example (https://docs.python.org/3/extending/newtypes.html#subclassing-other-types) in the docs and tried to extend it by adding a method which creates and returns a shoddy instance. I dug around to find ways to allocate and initialize my shoddy instance and that seems to work well. However, I get segfaults when I try to delete my instance. The code is in the gist: https://gist.github.com/pbrady/f2daf50761e458bbe44a The magic happens in the make_a_shoddy function. Here's a sample session (Python 3.4.1) >>> from shoddy import make_a_shoddy() >>> shd = make_a_shoddy() tup build shd allocated list style allocation successful Py_SIZE(list) : 5 Py_SIZE(shoddy) : 5 >>> type(shd) <class 'shoddy.Shoddy'> >>> shd[:] [1, 2, 3, 4, 5] >>> shd.increment() 1 >>> shd.increment() 2 >>> del shd Segmentation fault (core dumped) This happens even if I don't set the destructor. Any ideas on what I am doing wrong? Thanks, Peter.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
C-API proper initialization and deallocation of subclasses ptb <petertbrady@gmail.com> - 2014-06-12 21:39 -0700 Re: C-API proper initialization and deallocation of subclasses ptb <petertbrady@gmail.com> - 2014-06-13 14:18 -0700
csiph-web