[Bf-python] Memory leak - BPY

Campbell Barton cbarton at metavr.com
Thu Apr 5 20:32:28 CEST 2007


Hi All,
ob.LocX = '1.5'

if we support we should support everywhere, at the moment its only 
supported in some places.

I dont think its good to support this, just seems messy and error prone.

1) The only reason I can imagine users would pass a string instead of a 
float to start with is if they are passing imported data, if theres a 
problem with that data its better they come across the error when 
running float() then a blender function.
2) python modules like math dont accept this.
3) its more code
4) easier to miss a decref, especialy when you return an error.

Anyone against removing PyNumber_Float in favor of accepting numbers 
only (ints,floats)?

Ken Hughes wrote:
> Campbell Barton wrote:
>> Hi, take a look at this from Ipocurve, looks like xobj and yobj need 
>> to be decrefed,
> 
> You're right, they do need a decref.
> 
>> A lot of BPythons code uses PyNumber_Float, where its not needed, 
>> aside from complicating things by taking a reference, its only bein 
>> used to check.
>>
>>
>> float f;
>> PyObject *(!pyfloat) = PyNumber_Float( pyob );
>> if (!pyfloat) .... raise error
>> f = (float)PyFloat_AsDouble( pyfloat );
>> Py_DECREF( pyfloat );
>>
>>
>> Its probably better and less problem prone  to do this.
>>
>> float f;
>> if (!PyNumber_Check(pyob)) .... raise error
>> f = (float)PyFloat_AsDouble( pyob ); /* PyFloat_ASDOUBLE works too I 
>> guess */
> 
> I started using using PyNumber_Float() as part of the goal to allow 
> users to give us anything remotely number-like as input without failing, 
> for example
> 
>   ob.LoxC = '1.5'
>   ob.LocX = True
> as opposed to
>   ob.LocX = float('1.5')
>   ob.LocX = float(True)
> 
> (I started doing this back around the discussion of PyObject_IsTrue() 
> being used).
> 
> If PyFloat_AsDouble() will take non-float objects then your way is 
> definitely better; I haven't tried it to be sure.
> 
> Ken
> _______________________________________________
> Bf-python mailing list
> Bf-python at projects.blender.org
> http://projects.blender.org/mailman/listinfo/bf-python
> 


-- 
See MetaVR Visuals Used at the Combat Studies Institute
http://www.metavr.com/casestudies/baghdadviews.html

Campbell J Barton

133 Hope Street
Geelong West, Victoria 3218 Australia

URL:    http://www.metavr.com
e-mail: cbarton at metavr.com
phone: AU (03) 5229 0241



More information about the Bf-python mailing list