[Bf-python] CurNurb/IpoCurve/BezTriple hackery

Stephen Swaney sswaney at centurytel.net
Sat Jun 18 21:13:58 CEST 2005


On Sat, Jun 18, 2005 at 10:57:42AM -0700, Ken Hughes wrote:
> 
> No argument here; they're not good code.  But in
> Python I would expect this to throw an exception.
> 
> 
> >You can do the same thing is C by allocating an array and
> >setting another pointer to it.  If you then realloc the
> >array, the held pointer is probably not valid.
> 
> Yes, but C isn't OO; it easy for a programmer to do things which
> will corrupt memory.   Python should be better than that.

You can do the same thing in C++, but let's not go there!

Your python examples work because each element is an actual
python object that can exist on its own.  
example:

a = [1,2,3]
b = a[2]   # b is 3
a = ['a', 'b']
print b    # still gives 3

The heart of our problem is that a BezTriple is not a
separate and unique blender datablock like Camera, or IpoCurve
that exists by itself.  BezTriple is a dynamically allocated
part of a Nurb struct.

One way to get around this problem is to change the bpy BezTriple
implementation so that it holds a pointer to the Nurb that contains
our BezTriple and an index to the specific array element we want.
This way, a BezTriple becomes, in a sense, a convenience function for a
particular array element. Also, trying to access a deleted point can at
least throw an execption.

Note 1: You can argue this is just pushing the problem one level up
since Nurbs are not separate datablocks either, but merely elements in
a dynamically allocated list.  So it is still possible to hose things.

Note 2:  When we do Blender3 and have actual python data
structures instead of wrapping C data, this thread can come to an end!

Theorem 1:  Any programming language with sufficent expressive power
to accomplish useful tasks can also hurt you.  A table saw with
insufficent power to cut of your own finger is of little use.
-- 
Stephen Swaney			
sswaney at centurytel.net




More information about the Bf-python mailing list