[Bf-python] Memory leak - BPY

Ken Hughes khughes at pacific.edu
Thu Apr 5 21:49:10 CEST 2007


For anyone interested, this is the thread (and the thread split, so 
you'll need to read a couple of e-mails to see the whole discussion) 
that prompted me to start using PyNumber_Float() or PyNumber_Int():

http://projects.blender.org/pipermail/bf-python/2005-December/003429.html

I have no strong feeling regarding how we decide to handle this 
(PyNumber_Float() vs PyNumber_Check()), as long as it's consistent 
throughout the API.  I think we (i.e., collectively or via benevolent 
BPy dictators) just need to decide what's the proper way to handle this 
and put in the mythical "BPy Developer's Guide" (seriously, we should 
put together a wiki page with development rules just so we can keep 
track of things).

Ken

Campbell Barton wrote:
> 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
>>
> 
> 


-- 
Prof Ken Hughes
Electrical and Computer Engr
University of the Pacific



More information about the Bf-python mailing list