[C++-sig] Re: C arrays solution
Niall Douglas
s_sourceforge at nedprod.com
Tue Oct 14 03:01:22 CEST 2003
On 13 Oct 2003 at 19:12, David Abrahams wrote:
> > boost::python::class_<FXObjectList,
> > boost::noncopyable>("FXObjectList")
> > .def("getData", MakeCArray(&FXObjectList::getData,
> > &FXObjectList::getDataLen))
> >
> > And bam!, in one fell swoop the problem is solved.
>
> I'm not sure I know exactly what problem you're solving (what do you
> expect to be able to do with the result of this getData call?) but
> your use of a global pointer to hold the result is terribly unsafe...
> not to mention the fact that your code leaks CArray objects like a
> sieve.
Again, all artifacts of proof of concept code. The hard part for me
was the compile-time programming.
I should add that in all the code I've written in the last three
years, I've had a total of I think eight memory leaks ever (according
to valgrind and MSVC's debug CRT memory leak facilities). And that's
over 50,000 lines now, probably more.
> If you're satisfied with that, I guess I'm satisfied. Otherwise,
> perhaps you'd like to post a little more detail about how you want to
> be able to *use* this code from Python? I think people here,
> especially Raoul, should be able to make some suggestions which would
> solve the problem in a more principled way.
>>> from TestCArrays import *
>>> a=MyList()
>>> b=a.getData()
>>> print len(b)
4
>>> print b[0:4]
['Niall', 'is', 'a', 'teapot']
>>> b[1]="is not"
>>> print b[0:4]
['Niall', 'is not', 'a', 'teapot']
The key here is that MyList knows nothing of python and offers no
more than a C array of pointers, something which up until now was
hard to wrap without lots of munge code.
Cheers,
Niall
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 208 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20031014/b6d9b42c/attachment.pgp>
More information about the Cplusplus-sig
mailing list