Skip to content

Commit 70bc12a

Browse files
committed
Fix reference counting error in demos 6 and 7.
1 parent 01b73d4 commit 70bc12a

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Demos/Demo06/Unit1.dfm

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ object Form1: TForm1
1010
Font.Height = -11
1111
Font.Name = 'MS Sans Serif'
1212
Font.Style = []
13-
OldCreateOrder = True
14-
PixelsPerInch = 96
1513
TextHeight = 13
1614
object Splitter1: TSplitter
1715
Left = 0
@@ -20,7 +18,6 @@ object Form1: TForm1
2018
Height = 3
2119
Cursor = crVSplit
2220
Align = alTop
23-
ExplicitWidth = 536
2421
end
2522
object Memo1: TMemo
2623
Left = 0

Demos/Demo06/Unit1.pas

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ procedure PyPoint_dealloc(obj : PPyObject); cdecl;
151151
// object.value
152152
// object.method(args)
153153
function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
154+
var
155+
Py_Key: PPyObject;
154156
begin
155157
with GetPythonEngine, PPyPoint(obj)^ do
156158
begin
@@ -163,9 +165,14 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
163165
else
164166
begin
165167
// Else check for a method
166-
Result := PyObject_GenericGetAttr(obj, PyUnicodeFromString(key));
167-
if not Assigned(Result) then
168-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
168+
Py_Key := PyUnicodeFromString(key);
169+
try
170+
Result := PyObject_GenericGetAttr(obj, Py_key);
171+
if not Assigned(Result) then
172+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
173+
finally
174+
Py_DECREF(Py_Key);
175+
end;
169176
end;
170177
end;
171178
end;

Demos/Demo07/Unit1.pas

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ procedure PyPoint_dealloc(obj : PPyObject); cdecl;
191191
// object.value
192192
// object.method(args)
193193
function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
194+
var
195+
Py_Key: PPyObject;
194196
begin
195197
with GetPythonEngine, PPyPoint(obj)^ do
196198
begin
@@ -203,9 +205,14 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
203205
else
204206
begin
205207
// Else check for a method
206-
Result := PyObject_GenericGetAttr(obj, PyUnicodeFromString(key));
207-
if not Assigned(Result) then
208-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
208+
Py_Key := PyUnicodeFromString(key);
209+
try
210+
Result := PyObject_GenericGetAttr(obj, Py_Key);
211+
if not Assigned(Result) then
212+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
213+
finally
214+
Py_DECREF(Py_Key);
215+
end;
209216
end;
210217
end;
211218
end;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy