Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 01b73d4

Browse filesBrowse files
committed
PyErr_SetString should be called with utf8 encoded strings
1 parent 311860e commit 01b73d4
Copy full SHA for 01b73d4

13 files changed

+56
-59
lines changed

‎Demos/Demo07/Unit1.dfm

Copy file name to clipboardExpand all lines: Demos/Demo07/Unit1.dfm
-3
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ object Form1: TForm1
1313
Font.Name = 'MS Sans Serif'
1414
Font.Pitch = fpVariable
1515
Font.Style = []
16-
OldCreateOrder = True
17-
PixelsPerInch = 96
1816
TextHeight = 13
1917
object Splitter1: TSplitter
2018
Left = 0
@@ -23,7 +21,6 @@ object Form1: TForm1
2321
Height = 3
2422
Cursor = crVSplit
2523
Align = alTop
26-
ExplicitWidth = 536
2724
end
2825
object Memo1: TMemo
2926
Left = 0

‎Demos/Demo07/Unit1.pas

Copy file name to clipboardExpand all lines: Demos/Demo07/Unit1.pas
+4-4
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function PyPoint_getattr(obj : PPyObject; key : PAnsiChar) : PPyObject; cdecl;
205205
// Else check for a method
206206
Result := PyObject_GenericGetAttr(obj, PyUnicodeFromString(key));
207207
if not Assigned(Result) then
208-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Unknown attribute "%s"',[key]))));
208+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
209209
end;
210210
end;
211211
end;
@@ -226,7 +226,7 @@ function PyPoint_setattrfunc(obj : PPyObject; key : PAnsiChar; value : PPyObjec
226226
Result := 0;
227227
end
228228
else
229-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Attribute "%s" needs an integer',[key]))));
229+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Attribute "%s" needs an integer',[key]))));
230230
// Check for attribute y
231231
end else if key = 'y' then begin
232232
if PyLong_Check(value) then
@@ -235,9 +235,9 @@ function PyPoint_setattrfunc(obj : PPyObject; key : PAnsiChar; value : PPyObjec
235235
Result := 0;
236236
end
237237
else
238-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Attribute "%s" needs an integer',[key]))));
238+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Attribute "%s" needs an integer',[key]))));
239239
end else
240-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Unknown attribute "%s"',[key]))));
240+
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(Utf8Encode(Format('Unknown attribute "%s"',[key]))));
241241
end;
242242
end;
243243

‎Source/PythonAction.pas

Copy file name to clipboardExpand all lines: Source/PythonAction.pas
+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface
1717

1818
uses
1919
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
20-
ActnList, PythonEngine;
20+
Actions, ActnList, PythonEngine;
2121

2222
type
2323
TPythonAction = class(TAction)
@@ -114,21 +114,21 @@ function TPythonAction.HandlesTarget(Target: TObject): Boolean;
114114

115115
procedure TPythonAction.InitializeAction;
116116
var
117-
docString: string;
117+
docString: string;
118118
begin
119119
if not (csDesigning in ComponentState) and Assigned(PythonModule) then
120120
begin
121121
fClearname := 'Clear' + Name;
122122
docString := 'Claer all events of "' + Owner.Name + '.' + Name + '" action';
123-
PythonModule.AddDelphiMethod(PChar(fClearname), PythonClear, PChar(docString));
123+
PythonModule.AddDelphiMethod(PAnsiChar(fClearname), PythonClear, PAnsiChar(docString));
124124

125125
fRegistername := 'Register' + Name;
126126
docString := 'Register an event againt the "' + Owner.Name + '.' + Name + '" action';
127-
PythonModule.AddDelphiMethod(PChar(fRegistername), PythonRegister, PChar(docString));
127+
PythonModule.AddDelphiMethod(PAnsiChar(fRegistername), PythonRegister, PAnsiChar(docString));
128128

129129
fUnregistername := 'Unregister' + Name;
130130
docString := 'Unregister an event againt the "' + Owner.Name + '.' + Name + '" action';
131-
PythonModule.AddDelphiMethod(PChar(fUnregistername), PythonUnregister, PChar(docString));
131+
PythonModule.AddDelphiMethod(PAnsiChar(fUnregistername), PythonUnregister, PAnsiChar(docString));
132132
end;
133133
end;
134134

@@ -152,7 +152,7 @@ function TPythonAction.PythonRegister(pself, args: PPyObject): PPyObject;
152152
( not PyFunction_Check(func)) then
153153
begin
154154
s := fRegistername + '(function)';
155-
PyErr_SetString(PyExc_TypeError^,PChar(s));
155+
PyErr_SetString(PyExc_TypeError^, PAnsiChar(Utf8Encode(s)));
156156
end
157157
else
158158
with RegisteredMethods do
@@ -174,7 +174,7 @@ function TPythonAction.PythonUnregister(pself, args: PPyObject): PPyObject;
174174
(RegisteredMethods.IndexOf(func) = -1) then
175175
begin
176176
s := fUnregistername + '(function)';
177-
PyErr_SetString(PyExc_TypeError^,PChar(s));
177+
PyErr_SetString(PyExc_TypeError^, PAnsiChar(Utf8Encode(s)));
178178
end
179179
else
180180
with RegisteredMethods do

‎Source/PythonEngine.pas

Copy file name to clipboardExpand all lines: Source/PythonEngine.pas
+7-7
Original file line numberDiff line numberDiff line change
@@ -2419,8 +2419,8 @@ TError = class(TCollectionItem)
24192419
destructor Destroy; override;
24202420
procedure Assign(Source: TPersistent); override;
24212421
procedure BuildError( const ModuleName : AnsiString );
2422-
procedure RaiseError( const msg : AnsiString );
2423-
procedure RaiseErrorObj( const msg : AnsiString; obj : PPyObject );
2422+
procedure RaiseError(const msg : AnsiString);
2423+
procedure RaiseErrorObj(const msg : AnsiString; obj : PPyObject);
24242424
function Owner : TErrors;
24252425
property Error : PPyObject read FError write FError;
24262426
published
@@ -7183,14 +7183,14 @@ procedure TError.BuildError( const ModuleName : AnsiString );
71837183
raise Exception.CreateFmt( 'Could not create error "%s"', [Name] );
71847184
end;
71857185

7186-
procedure TError.RaiseError( const msg : AnsiString );
7186+
procedure TError.RaiseError(const msg : AnsiString);
71877187
begin
71887188
Owner.Owner.CheckEngine;
71897189
with Owner.Owner.Engine do
7190-
PyErr_SetString( Error, PAnsiChar(msg) );
7190+
PyErr_SetString(Error, PAnsiChar(EncodeString(msg)));
71917191
end;
71927192

7193-
procedure TError.RaiseErrorObj( const msg : AnsiString; obj : PPyObject );
7193+
procedure TError.RaiseErrorObj(const msg : AnsiString; obj : PPyObject);
71947194
var
71957195
args, res, str : PPyObject;
71967196
i : Integer;
@@ -7698,8 +7698,8 @@ function TPyObject.SetAttr(key : PAnsiChar; value : PPyObject) : Integer;
76987698
with GetPythonEngine do
76997699
begin
77007700
Result := -1;
7701-
PyErr_SetString (PyExc_AttributeError^,
7702-
PAnsiChar(AnsiString(Format('Unknown attribute "%s"',[key]))));
7701+
PyErr_SetString(PyExc_AttributeError^,
7702+
PAnsiChar(EncodeString(Format('Unknown attribute "%s"',[key]))));
77037703
end;
77047704
end;
77057705

‎Source/WrapDelphiClasses.pas

Copy file name to clipboardExpand all lines: Source/WrapDelphiClasses.pas
+7-7
Original file line numberDiff line numberDiff line change
@@ -1221,13 +1221,13 @@ function TPyDelphiComponent.MpSubscript(obj: PPyObject): PPyObject;
12211221
else
12221222
begin
12231223
Result := nil;
1224-
PyErr_SetString (PyExc_KeyError^, PAnsiChar(AnsiString(_name)));
1224+
PyErr_SetString(PyExc_KeyError^, PAnsiChar(EncodeString(_name)));
12251225
end;
12261226
end
12271227
else
12281228
begin
12291229
Result := nil;
1230-
PyErr_SetString (PyExc_KeyError^, 'Key must be a string');
1230+
PyErr_SetString(PyExc_KeyError^, 'Key must be a string');
12311231
end;
12321232
end;
12331233
end;
@@ -1329,7 +1329,7 @@ function TStringsAccess.SetItem(AIndex: Integer; AValue: PPyObject): Boolean;
13291329
else
13301330
begin
13311331
Result := False;
1332-
PyErr_SetString (PyExc_AttributeError^, 'You can only assign strings to TStrings items');
1332+
PyErr_SetString(PyExc_AttributeError^, 'You can only assign strings to TStrings items');
13331333
end;
13341334
end
13351335
end;
@@ -1393,7 +1393,7 @@ function TStringsObjectsAccess.SetItem(AIndex: Integer; AValue: PPyObject): Bool
13931393
else
13941394
begin
13951395
Result := False;
1396-
PyErr_SetString (PyExc_AttributeError^, 'You can only assign Delphi wrappers to Objects items');
1396+
PyErr_SetString(PyExc_AttributeError^, 'You can only assign Delphi wrappers to Objects items');
13971397
end;
13981398
end
13991399
end;
@@ -1617,11 +1617,11 @@ function TPyDelphiStrings.MpSubscript(obj: PPyObject): PPyObject;
16171617
else
16181618
Result := GetPythonEngine.ReturnNone;
16191619
end else with GetPythonEngine do begin
1620-
PyErr_SetString (PyExc_KeyError^, PAnsiChar(AnsiString(S)));
1620+
PyErr_SetString(PyExc_KeyError^, PAnsiChar(EncodeString(S)));
16211621
Result := nil;
16221622
end;
16231623
end else with GetPythonEngine do begin
1624-
PyErr_SetString (PyExc_KeyError^, '<Empty String>');
1624+
PyErr_SetString(PyExc_KeyError^, '<Empty String>');
16251625
Result := nil;
16261626
end;
16271627
end;
@@ -2445,7 +2445,7 @@ TResourceStreamClass = class of TResourceStream;
24452445
except
24462446
on E: Exception do
24472447
with GetPythonEngine do
2448-
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(AnsiString(E.Message)));
2448+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(EncodeString(E.Message)));
24492449
end;
24502450

24512451
//Maybe it was created on the next attempt...

‎Source/WrapDelphiTypes.pas

Copy file name to clipboardExpand all lines: Source/WrapDelphiTypes.pas
+6-6
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ function CheckPointAttribute(AAttribute : PPyObject; const AAttributeName : stri
229229
begin
230230
Result := False;
231231
with GetPythonEngine do
232-
PyErr_SetString (PyExc_AttributeError^,
233-
PAnsiChar(AnsiString(Format('%s receives only Point objects', [AAttributeName]))));
232+
PyErr_SetString(PyExc_AttributeError^,
233+
PAnsiChar(EncodeString(Format('%s receives only Point objects', [AAttributeName]))));
234234
end;
235235
end;
236236
end;
@@ -248,8 +248,8 @@ function CheckRectAttribute(AAttribute : PPyObject; const AAttributeName : strin
248248
begin
249249
Result := False;
250250
with GetPythonEngine do
251-
PyErr_SetString (PyExc_AttributeError^,
252-
PAnsiChar(AnsiString(Format('%s receives only Rect objects', [AAttributeName]))));
251+
PyErr_SetString(PyExc_AttributeError^,
252+
PAnsiChar(EncodeString(Format('%s receives only Rect objects', [AAttributeName]))));
253253
end;
254254
end;
255255
end;
@@ -267,8 +267,8 @@ function CheckSizeAttribute(AAttribute : PPyObject; const AAttributeName : strin
267267
begin
268268
Result := False;
269269
with GetPythonEngine do
270-
PyErr_SetString (PyExc_AttributeError^,
271-
PAnsiChar(AnsiString(Format('%s receives only Size objects', [AAttributeName]))));
270+
PyErr_SetString(PyExc_AttributeError^,
271+
PAnsiChar(EncodeString(Format('%s receives only Size objects', [AAttributeName]))));
272272
end;
273273
end;
274274
end;

‎Source/WrapFireDAC.pas

Copy file name to clipboardExpand all lines: Source/WrapFireDAC.pas
+10-10
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ function TPyDBField.CheckField : Boolean;
597597
if not Assigned(DelphiObject) then begin
598598
Result := False;
599599
with GetPythonEngine do
600-
PyErr_SetString (PyExc_RuntimeError^, PAnsiChar('No field defined !') );
600+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar('No field defined !') );
601601
end
602602
else
603603
Result := True;
@@ -978,7 +978,7 @@ function TPyDBDataset.Do_Fields( args : PPyObject ): PPyObject;
978978
Result := PyDelphiWrapper.Wrap(l_oDataset.Fields[idx])
979979
else begin
980980
Result := nil;
981-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Value out of range : %d', [idx]))));
981+
PyErr_SetString(PyExc_AttributeError^, PAnsiChar(EncodeString(Format('Value out of range : %d', [idx]))));
982982
end;
983983
end
984984
else
@@ -1011,7 +1011,7 @@ function TPyDBDataset.Do_FieldByName( args : PPyObject ) : PPyObject;
10111011
Result := PyDelphiWrapper.Wrap(fld)
10121012
else begin
10131013
Result := nil;
1014-
PyErr_SetString (PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Unknown field "%s"', [String(s)]))) );
1014+
PyErr_SetString(PyExc_AttributeError^, PAnsiChar(AnsiString(Format('Unknown field "%s"', [String(s)]))) );
10151015
end;
10161016
end
10171017
else
@@ -1191,7 +1191,7 @@ function TPyDBDataset.Do_Locate( args : PPyObject ) : PPyObject;
11911191
try
11921192
if PyArg_ParseTuple( args, 'sOO:DBDataset.Locate',@keyFields, @keyValues, @options ) <> 0 then begin
11931193
if PySequence_Check(options) = 0 then
1194-
PyErr_SetString (PyExc_AttributeError^, 'Third argument of Locate must be a sequence.')
1194+
PyErr_SetString(PyExc_AttributeError^, 'Third argument of Locate must be a sequence.')
11951195
else begin
11961196
// Prepare the locate options
11971197
ListToSet( options, @opt, sizeof(opt) );
@@ -1391,14 +1391,14 @@ function TPyDBTable.CheckActiveDBTable(aMustOpen: Boolean): Boolean;
13911391
if not aMustOpen then begin
13921392
Result := False;
13931393
with GetPythonEngine do
1394-
PyErr_SetString (PyExc_RuntimeError^, PAnsiChar('DBTable is open!') );
1394+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar('DBTable is open!') );
13951395
end;
13961396
end
13971397
else begin
13981398
if aMustOpen then begin
13991399
Result := False;
14001400
with GetPythonEngine do
1401-
PyErr_SetString (PyExc_RuntimeError^, PAnsiChar('DBTable is not open!') );
1401+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar('DBTable is not open!') );
14021402
end;
14031403
end;
14041404
end;
@@ -1838,10 +1838,10 @@ function TPyDBTable.Do_SetRange( args : PPyObject ) : PPyObject;
18381838
if l_oTable.Active and
18391839
(PyArg_ParseTuple( args, 'OO:FDTable.SetRange',@l_oPyStartValues, @l_oPyEndValues ) <> 0) then begin
18401840
if PySequence_Check(l_oPyStartValues) = 0 then begin
1841-
PyErr_SetString (PyExc_AttributeError^, 'First argument of SetRange must be a sequence.');
1841+
PyErr_SetString(PyExc_AttributeError^, 'First argument of SetRange must be a sequence.');
18421842
end
18431843
else if PySequence_Check(l_oPyEndValues) = 0 then begin
1844-
PyErr_SetString (PyExc_AttributeError^, 'Second argument of SetRange must be a sequence.');
1844+
PyErr_SetString(PyExc_AttributeError^, 'Second argument of SetRange must be a sequence.');
18451845
end
18461846
else begin
18471847
l_oTable.SetRangeStart;
@@ -1952,14 +1952,14 @@ function TPyDBQuery.CheckActiveDBQuery(aMustOpen: Boolean): Boolean;
19521952
if not aMustOpen then begin
19531953
Result := False;
19541954
with GetPythonEngine do
1955-
PyErr_SetString (PyExc_RuntimeError^, PAnsiChar('DBQuery is open!') );
1955+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar('DBQuery is open!') );
19561956
end;
19571957
end
19581958
else begin
19591959
if aMustOpen then begin
19601960
Result := False;
19611961
with GetPythonEngine do
1962-
PyErr_SetString (PyExc_RuntimeError^, PAnsiChar('DBQuery is not open!') );
1962+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar('DBQuery is not open!') );
19631963
end;
19641964
end;
19651965
end;

‎Source/fmx/WrapFmxForms.pas

Copy file name to clipboardExpand all lines: Source/fmx/WrapFmxForms.pas
+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ function TPyDelphiCommonCustomForm.LoadProps_Wrapper(
466466
except
467467
on E: Exception do
468468
with GetPythonEngine do
469-
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(AnsiString(E.Message)));
469+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(Utf8Encode(E.Message)));
470470
end;
471471
Result := nil;
472472
end;

‎Source/fmx/WrapFmxTypes.pas

Copy file name to clipboardExpand all lines: Source/fmx/WrapFmxTypes.pas
+4-4
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ function CheckPointFAttribute(AAttribute : PPyObject; const AAttributeName : str
505505
Result := False;
506506
with GetPythonEngine do
507507
PyErr_SetString (PyExc_AttributeError^,
508-
PAnsiChar(AnsiString(Format('%s receives only PointF objects', [AAttributeName]))));
508+
PAnsiChar(Utf8Encode(Format('%s receives only PointF objects', [AAttributeName]))));
509509
end;
510510
end;
511511
end;
@@ -524,7 +524,7 @@ function CheckSizeFAttribute(AAttribute : PPyObject; const AAttributeName : stri
524524
Result := False;
525525
with GetPythonEngine do
526526
PyErr_SetString (PyExc_AttributeError^,
527-
PAnsiChar(AnsiString(Format('%s receives only SizeF objects', [AAttributeName]))));
527+
PAnsiChar(Utf8Encode(Format('%s receives only SizeF objects', [AAttributeName]))));
528528
end;
529529
end;
530530
end;
@@ -543,7 +543,7 @@ function CheckRectFAttribute(AAttribute: PPyObject; const AAttributeName: string
543543
Result := False;
544544
with GetPythonEngine do
545545
PyErr_SetString (PyExc_AttributeError^,
546-
PAnsiChar(AnsiString(Format('%s receives only RectF objects', [AAttributeName]))));
546+
PAnsiChar(Utf8Encode(Format('%s receives only RectF objects', [AAttributeName]))));
547547
end;
548548
end;
549549
end;
@@ -562,7 +562,7 @@ function CheckTouchAttribute(AAttribute: PPyObject; const AAttributeName: string
562562
Result := False;
563563
with GetPythonEngine do
564564
PyErr_SetString (PyExc_AttributeError^,
565-
PAnsiChar(AnsiString(Format('%s receives only Touch objects', [AAttributeName]))));
565+
PAnsiChar(Utf8Encode(Format('%s receives only Touch objects', [AAttributeName]))));
566566
end;
567567
end;
568568
end;

‎Source/vcl/WrapVclForms.pas

Copy file name to clipboardExpand all lines: Source/vcl/WrapVclForms.pas
+1-1
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ function TPyDelphiCustomForm.LoadProps_Wrapper(args: PPyObject): PPyObject;
572572
except
573573
on E: Exception do
574574
with GetPythonEngine() do
575-
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(AnsiString(E.Message)));
575+
PyErr_SetString(PyExc_RuntimeError^, PAnsiChar(EncodeString(E.Message)));
576576
end;
577577
Result := nil;
578578
end;

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.