Skip to content

Commit abb2180

Browse files
committed
Changed wrapper to match Joce's changes in Wrapper
- Wrapper updated to use new[] instead of malloc - Comment added to top of ScintillaWrapperGenerated.cpp - Casts changed to const_cast
1 parent 6664235 commit abb2180

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

PythonScript/src/CreateWrapper.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ def constString(v, out):
9797

9898
def retString(v, out):
9999
out.write("\tint resultLength = callScintilla(" + symbolName(v) + ");\n")
100-
out.write("\tchar *result = (char *)malloc(resultLength + 1);\n")
100+
out.write("\tchar *result = new char[resultLength + 1];\n")
101101
out.write("\tcallScintilla(" + symbolName(v) + ", resultLength + 1, reinterpret_cast<LPARAM>(result));\n")
102102
out.write("\tresult[resultLength] = '\\0';\n")
103-
out.write("\tstr o = str((const char *)result);\n")
104-
out.write("\tfree(result);\n")
103+
out.write("\tstr o = str(const_cast<const char *>(result));\n")
104+
out.write("\tdelete [] result;\n")
105105
out.write("\treturn o;\n")
106106

107107
def getLineBody(v, out):
@@ -113,11 +113,11 @@ def getLineBody(v, out):
113113
out.write("\telse\n")
114114
out.write("\t{\n")
115115
out.write("\t\tint resultLength = callScintilla(" + symbolName(v) + ", line);\n")
116-
out.write("\t\tchar *result = (char *)malloc(resultLength + 1);\n")
116+
out.write("\t\tchar *result = new char[resultLength + 1];\n")
117117
out.write("\t\tcallScintilla(" + symbolName(v) + ", line, reinterpret_cast<LPARAM>(result));\n")
118118
out.write("\t\tresult[resultLength] = '\\0';\n")
119119
out.write("\t\tstr o = str((const char *)result);\n")
120-
out.write("\t\tfree(result);\n")
120+
out.write("\t\tdelete [] result;\n")
121121
out.write("\t\treturn o;\n")
122122
out.write("\t}\n")
123123

@@ -134,7 +134,7 @@ def retStringNoLength(v, out):
134134

135135
out.write(");\n")
136136

137-
out.write("\tchar *result = (char *)malloc(resultLength + 1);\n")
137+
out.write("\tchar *result = new char[resultLength + 1];\n")
138138
out.write("\tcallScintilla(" + symbolName(v) + ", ")
139139

140140
if v["Param1Type"] or v["Param2Type"]:
@@ -148,8 +148,8 @@ def retStringNoLength(v, out):
148148

149149
out.write(", reinterpret_cast<LPARAM>(result));\n")
150150
out.write("\tresult[resultLength] = '\\0';\n")
151-
out.write("\tstr o = str((const char *)result);\n")
152-
out.write("\tfree(result);\n")
151+
out.write("\tstr o = str(const_cast<const char *>(result));\n")
152+
out.write("\tdelete [] result;\n")
153153
out.write("\treturn o;\n")
154154

155155
def findTextBody(v, out):
@@ -202,7 +202,7 @@ def getStyledTextBody(v, out):
202202
out.write("\tresult[end-start] = '\\0';\n")
203203
out.write('\tstr resultStr(const_cast<const char*>(result));\n')
204204
out.write('\tdelete src.lpstrText;\n')
205-
out.write('\tdelete result;\n')
205+
out.write('\tdelete [] result;\n')
206206
out.write('\treturn make_tuple(resultStr, styles);\n')
207207

208208

@@ -322,9 +322,12 @@ def getPythonSignature(v):
322322

323323
def writeCppFile(f,out):
324324
out.write('#include "stdafx.h"\n')
325-
out.write('#include "ScintillaWrapper.h"\n')
326325
out.write('#include "Scintilla.h"\n')
326+
out.write('#include "ScintillaCells.h"\n')
327+
out.write('#include "ScintillaWrapper.h"\n')
328+
327329
out.write('\n\n')
330+
out.write('/* THIS FILE IS AUTO-GENERATED. Edit CreateWrapper.py to change it */\n\n')
328331

329332
for name in f.order:
330333
v = f.features[name]

PythonScript/src/ScintillaWrapperGenerated.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "stdafx.h"
2-
32
#include "Scintilla.h"
43
#include "ScintillaCells.h"
54
#include "ScintillaWrapper.h"
65

6+
7+
/* THIS FILE IS AUTO-GENERATED. Edit CreateWrapper.py to change it */
8+
79
/** Add text to the document at current position.
810
*/
911
int ScintillaWrapper::AddText(boost::python::object text)
@@ -224,7 +226,7 @@ boost::python::str ScintillaWrapper::GetCurLine()
224226
char *result = new char[resultLength + 1];
225227
callScintilla(SCI_GETCURLINE, resultLength + 1, reinterpret_cast<LPARAM>(result));
226228
result[resultLength] = '\0';
227-
str o = str((const char *)result);
229+
str o = str(const_cast<const char *>(result));
228230
delete [] result;
229231
return o;
230232
}
@@ -574,7 +576,7 @@ boost::python::str ScintillaWrapper::StyleGetFont()
574576
char *result = new char[resultLength + 1];
575577
callScintilla(SCI_STYLEGETFONT, 0, reinterpret_cast<LPARAM>(result));
576578
result[resultLength] = '\0';
577-
str o = str((const char *)result);
579+
str o = str(const_cast<const char *>(result));
578580
delete [] result;
579581
return o;
580582
}
@@ -1435,7 +1437,7 @@ boost::python::str ScintillaWrapper::GetSelText()
14351437
char *result = new char[resultLength + 1];
14361438
callScintilla(SCI_GETSELTEXT, 0, reinterpret_cast<LPARAM>(result));
14371439
result[resultLength] = '\0';
1438-
str o = str((const char *)result);
1440+
str o = str(const_cast<const char *>(result));
14391441
delete [] result;
14401442
return o;
14411443
}
@@ -1603,7 +1605,7 @@ boost::python::str ScintillaWrapper::GetText()
16031605
char *result = new char[resultLength + 1];
16041606
callScintilla(SCI_GETTEXT, resultLength + 1, reinterpret_cast<LPARAM>(result));
16051607
result[resultLength] = '\0';
1606-
str o = str((const char *)result);
1608+
str o = str(const_cast<const char *>(result));
16071609
delete [] result;
16081610
return o;
16091611
}
@@ -2194,7 +2196,7 @@ boost::python::str ScintillaWrapper::GetTag()
21942196
char *result = new char[resultLength + 1];
21952197
callScintilla(SCI_GETTAG, 0, reinterpret_cast<LPARAM>(result));
21962198
result[resultLength] = '\0';
2197-
str o = str((const char *)result);
2199+
str o = str(const_cast<const char *>(result));
21982200
delete [] result;
21992201
return o;
22002202
}
@@ -3353,7 +3355,7 @@ boost::python::str ScintillaWrapper::AutoCGetCurrentText()
33533355
char *result = new char[resultLength + 1];
33543356
callScintilla(SCI_AUTOCGETCURRENTTEXT, 0, reinterpret_cast<LPARAM>(result));
33553357
result[resultLength] = '\0';
3356-
str o = str((const char *)result);
3358+
str o = str(const_cast<const char *>(result));
33573359
delete [] result;
33583360
return o;
33593361
}
@@ -3374,7 +3376,7 @@ boost::python::str ScintillaWrapper::TargetAsUTF8()
33743376
char *result = new char[resultLength + 1];
33753377
callScintilla(SCI_TARGETASUTF8, 0, reinterpret_cast<LPARAM>(result));
33763378
result[resultLength] = '\0';
3377-
str o = str((const char *)result);
3379+
str o = str(const_cast<const char *>(result));
33783380
delete [] result;
33793381
return o;
33803382
}
@@ -3397,7 +3399,7 @@ boost::python::str ScintillaWrapper::EncodedFromUTF8()
33973399
char *result = new char[resultLength + 1];
33983400
callScintilla(SCI_ENCODEDFROMUTF8, 0, reinterpret_cast<LPARAM>(result));
33993401
result[resultLength] = '\0';
3400-
str o = str((const char *)result);
3402+
str o = str(const_cast<const char *>(result));
34013403
delete [] result;
34023404
return o;
34033405
}
@@ -3657,7 +3659,7 @@ boost::python::str ScintillaWrapper::MarginGetText(int line)
36573659
char *result = new char[resultLength + 1];
36583660
callScintilla(SCI_MARGINGETTEXT, line, reinterpret_cast<LPARAM>(result));
36593661
result[resultLength] = '\0';
3660-
str o = str((const char *)result);
3662+
str o = str(const_cast<const char *>(result));
36613663
delete [] result;
36623664
return o;
36633665
}
@@ -3691,7 +3693,7 @@ boost::python::str ScintillaWrapper::MarginGetStyles(int line)
36913693
char *result = new char[resultLength + 1];
36923694
callScintilla(SCI_MARGINGETSTYLES, line, reinterpret_cast<LPARAM>(result));
36933695
result[resultLength] = '\0';
3694-
str o = str((const char *)result);
3696+
str o = str(const_cast<const char *>(result));
36953697
delete [] result;
36963698
return o;
36973699
}
@@ -3732,7 +3734,7 @@ boost::python::str ScintillaWrapper::AnnotationGetText(int line)
37323734
char *result = new char[resultLength + 1];
37333735
callScintilla(SCI_ANNOTATIONGETTEXT, line, reinterpret_cast<LPARAM>(result));
37343736
result[resultLength] = '\0';
3735-
str o = str((const char *)result);
3737+
str o = str(const_cast<const char *>(result));
37363738
delete [] result;
37373739
return o;
37383740
}
@@ -3766,7 +3768,7 @@ boost::python::str ScintillaWrapper::AnnotationGetStyles(int line)
37663768
char *result = new char[resultLength + 1];
37673769
callScintilla(SCI_ANNOTATIONGETSTYLES, line, reinterpret_cast<LPARAM>(result));
37683770
result[resultLength] = '\0';
3769-
str o = str((const char *)result);
3771+
str o = str(const_cast<const char *>(result));
37703772
delete [] result;
37713773
return o;
37723774
}
@@ -4242,7 +4244,7 @@ boost::python::str ScintillaWrapper::GetProperty()
42424244
char *result = new char[resultLength + 1];
42434245
callScintilla(SCI_GETPROPERTY, 0, reinterpret_cast<LPARAM>(result));
42444246
result[resultLength] = '\0';
4245-
str o = str((const char *)result);
4247+
str o = str(const_cast<const char *>(result));
42464248
delete [] result;
42474249
return o;
42484250
}
@@ -4256,7 +4258,7 @@ boost::python::str ScintillaWrapper::GetPropertyExpanded()
42564258
char *result = new char[resultLength + 1];
42574259
callScintilla(SCI_GETPROPERTYEXPANDED, 0, reinterpret_cast<LPARAM>(result));
42584260
result[resultLength] = '\0';
4259-
str o = str((const char *)result);
4261+
str o = str(const_cast<const char *>(result));
42604262
delete [] result;
42614263
return o;
42624264
}
@@ -4285,7 +4287,7 @@ boost::python::str ScintillaWrapper::GetLexerLanguage()
42854287
char *result = new char[resultLength + 1];
42864288
callScintilla(SCI_GETLEXERLANGUAGE, 0, reinterpret_cast<LPARAM>(result));
42874289
result[resultLength] = '\0';
4288-
str o = str((const char *)result);
4290+
str o = str(const_cast<const char *>(result));
42894291
delete [] result;
42904292
return o;
42914293
}
@@ -4305,7 +4307,7 @@ boost::python::str ScintillaWrapper::PropertyNames()
43054307
char *result = new char[resultLength + 1];
43064308
callScintilla(SCI_PROPERTYNAMES, 0, reinterpret_cast<LPARAM>(result));
43074309
result[resultLength] = '\0';
4308-
str o = str((const char *)result);
4310+
str o = str(const_cast<const char *>(result));
43094311
delete [] result;
43104312
return o;
43114313
}
@@ -4325,7 +4327,7 @@ boost::python::str ScintillaWrapper::DescribeProperty()
43254327
char *result = new char[resultLength + 1];
43264328
callScintilla(SCI_DESCRIBEPROPERTY, 0, reinterpret_cast<LPARAM>(result));
43274329
result[resultLength] = '\0';
4328-
str o = str((const char *)result);
4330+
str o = str(const_cast<const char *>(result));
43294331
delete [] result;
43304332
return o;
43314333
}
@@ -4338,7 +4340,7 @@ boost::python::str ScintillaWrapper::DescribeKeyWordSets()
43384340
char *result = new char[resultLength + 1];
43394341
callScintilla(SCI_DESCRIBEKEYWORDSETS, 0, reinterpret_cast<LPARAM>(result));
43404342
result[resultLength] = '\0';
4341-
str o = str((const char *)result);
4343+
str o = str(const_cast<const char *>(result));
43424344
delete [] result;
43434345
return o;
43444346
}

0 commit comments

Comments
 (0)