[Bf-python] Memory leak - BPY
Campbell Barton
cbarton at metavr.com
Fri Apr 6 09:26:02 CEST 2007
Hey Ken,
I dont see how PyObject_IsTrue relates to PyNumber_Float or PyNumber_Int?
With my additions to the python API Iv been using PyFloat_AsDouble and
PyNumber_Check seem to work with floats and ints.
see - boxPack_FromPyObject
I should do some testing to see exactly what it will and wont accept,
(the py docs dont help - http://www.python.org/doc/api/floatObjects.html)
- Cam
Ken Hughes wrote:
> 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
>>>
>>
>>
>
>
--
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