freelanceprogrammers.org Forum Index » Delphi

PythjonType.AddMethod - limitation of 10 methods


View user's profile Post To page top
larsen_roar Posted: Fri Aug 12, 2005 6:53 pm


Joined: 12 Aug 2005

Posts: 7
PythjonType.AddMethod - limitation of 10 methods
I`m working on an implementation based on the Demo26 but the app crashes when I add more
than 10 methods to my TPyObject derived object.
 
I reproduce the same in Demo26, the belove (silly) modified code, adding some dummy
methods causes a python.dll access violation when executing the script (`Execute` button)
and I have more than 10 registered methods (10 or less works fine).
 
I see that the PYT_METHOD_BUFFER_INCREASE is set to 10 (used in TMethodsContainer.ReallocMethods)
 
class procedure TPyPoint.RegisterMethods( PythonType : TPythonType );begin  inherited;  with PythonType do    begin      AddMethod( `OffsetBy`, @TPyPoint.DoOffsetBy, `Point.OffsetBy( dx, dy )` );      AddMethod( `RaiseError`, @TPyPoint.DoRaiseError, `Point.RaiseError()` );      AddMethod( `OffsetBy0`, @TPyPoint.DoOffsetBy, `Point.OffsetBy0( dx, dy )` );      AddMethod( `OffsetBy1`, @TPyPoint.DoOffsetBy, `Point.OffsetBy1( dx, dy )` );      AddMethod( `OffsetBy2`, @TPyPoint.DoOffsetBy, `Point.OffsetBy2( dx, dy )` );      AddMethod( `OffsetBy3`, @TPyPoint.DoOffsetBy, `Point.OffsetBy3( dx, dy )` );      AddMethod( `OffsetBy4`, @TPyPoint.DoOffsetBy, `Point.OffsetBy4( dx, dy )` );      AddMethod( `OffsetBy5`, @TPyPoint.DoOffsetBy, `Point.OffsetBy5( dx, dy )` );      AddMethod( `OffsetBy6`, @TPyPoint.DoOffsetBy, `Point.OffsetBy6( dx, dy )` );      AddMethod( `OffsetBy7`, @TPyPoint.DoOffsetBy, `Point.OffsetBy7( dx, dy )` );      AddMethod( `OffsetBy8`, @TPyPoint.DoOffsetBy, `Point.OffsetBy8( dx, dy )` );//      AddMethod( `OffsetB9`, @TPyPoint.DoOffsetBy, `Point.OffsetBy9( dx, dy )` );    end;end;
 
My current environment : Delphi 6, Python 2.3, P4D 3.27
 
Is this a bug or any limitation ?
Roar--------------------------------------------------------------------------------------TORDIVEL ASLade Alle 65 C, N-7041 Trondheim, NorwayTel : +47 7350 9220 Fax : + 47 2315 8701E-mail : roar@... Web : http://www.tordivel.no--------------------------------------------------------------------------------------...... THE VISION SOFTWARE HOUSE--------------------------------------------------------------------------------------
Reply with quote
Send private message
View user's profile Post To page top
morgan_martinet Posted: Sat Aug 13, 2005 7:27 am


Joined: 29 Apr 2005

Posts: 103
PythjonType.AddMethod - limitation of 10 methods
Hi Roar,
 
Thanks for reporting this bug. The problem
only occurs when you make a type that can be subclassed (tpfBaseType option).
This is because the object type is setup
prior to registering the methods and thus will use the pointer to the initial
buffer of methods (10 methods) and as soon as you exceed the buffer size, it
gets reallocated but the new pointer is not reassigned to the type definition,
and thus we keep a dangling pointer!
This will be fixed in the next release,
but in the mean time here’s the workaround:
 
class procedure TPyPoint.RegisterMethods( PythonType : TPythonType );
begin
  inherited;
  with PythonType do
    begin
      AddMethod( `OffsetBy`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy( dx, dy )` );
      AddMethod( `RaiseError`, @TPyPoint.DoRaiseError,
`Point.RaiseError()` );
      AddMethod( `OffsetBy0`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy0( dx, dy )` );
      AddMethod( `OffsetBy1`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy1( dx, dy )` );
      AddMethod( `OffsetBy2`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy2( dx, dy )` );
      AddMethod( `OffsetBy3`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy3( dx, dy )` );
      AddMethod( `OffsetBy4`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy4( dx, dy )` );
      AddMethod( `OffsetBy5`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy5( dx, dy )` );
      AddMethod( `OffsetBy6`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy6( dx, dy )` );
      AddMethod( `OffsetBy7`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy7( dx, dy )` );
      AddMethod( `OffsetBy8`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy8( dx, dy )` );
      AddMethod( `OffsetB9`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy9( dx, dy )` );
     
PythonType.TheTypePtr.tp_methods := PythonType.MethodsData;
    end;
end;
 
Note that you must to the same if you use
getsets and/or members.
 





From: pythonfordelphi@yahoogroups.com [mailto:pythonfordelphi@yahoogroups.com] On Behalf Of Roar Larsen
Sent: August 12, 2005 9:53 AM
To: pythonfordelphi@yahoogroups.com
Subject: [pythonfordelphi]
PythjonType.AddMethod - limitation of 10 methods

 

I`m working on an implementation based on the Demo26 but the app
crashes when I add more


than 10 methods to my TPyObject derived object.


 


I reproduce the same in Demo26, the belove (silly) modified code,
adding some dummy


methods causes a python.dll access violation
when executing the script (`Execute` button)


and I have more than 10 registered methods (10 or less works fine).


 


I see that the PYT_METHOD_BUFFER_INCREASE is set to 10 (used in
TMethodsContainer.ReallocMethods)


 


class procedure TPyPoint.RegisterMethods( PythonType : TPythonType );
begin
  inherited;
  with PythonType do
    begin
      AddMethod( `OffsetBy`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy( dx, dy )` );
      AddMethod( `RaiseError`, @TPyPoint.DoRaiseError,
`Point.RaiseError()` );
      AddMethod( `OffsetBy0`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy0( dx, dy )` );
      AddMethod( `OffsetBy1`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy1( dx, dy )` );
      AddMethod( `OffsetBy2`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy2( dx, dy )` );
      AddMethod( `OffsetBy3`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy3( dx, dy )` );
      AddMethod( `OffsetBy4`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy4( dx, dy )` );
      AddMethod( `OffsetBy5`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy5( dx, dy )` );
      AddMethod( `OffsetBy6`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy6( dx, dy )` );
      AddMethod( `OffsetBy7`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy7( dx, dy )` );
      AddMethod( `OffsetBy8`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy8( dx, dy )` );
//      AddMethod( `OffsetB9`, @TPyPoint.DoOffsetBy,
`Point.OffsetBy9( dx, dy )` );
    end;
end;


 


My current environment : Delphi 6,
Python 2.3, P4D 3.27


 


Is this a bug or any limitation ?



Roar
--------------------------------------------------------------------------------------
TORDIVEL AS
Lade Alle 65 C, N-7041 Trondheim,
Norway
Tel : +47 7350 9220 Fax : + 47 2315 8701
E-mail : roar@... Web : http://www.tordivel.no
--------------------------------------------------------------------------------------
...... THE VISION SOFTWARE HOUSE
--------------------------------------------------------------------------------------
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help