Skip to content

Commit d57f820

Browse files
committed
Don't generate conversion code for wxLists if not requested to.
1 parent b1d721b commit d57f820

File tree

2 files changed

+32
-31
lines changed

2 files changed

+32
-31
lines changed

cffi/wrapper_lib/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
CppWrapper, WrapperType, VirtualMethod, VirtualMethodStub,
33
VirtualDispatcher, register_cpp_classname, obj_from_ptr, get_ptr,
44
forget_ptr, take_ownership, give_ownership, keep_reference, MappedBase,
5+
is_alive,
56
instancecheck, convert_to_type, init_wrapper, hassubclass, CastData)
67
from multimethod import (
78
MMTypeCheckMeta, MMTypeError, MMInternalError, check_arg_type,

etgtools/tweaker_tools.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -940,37 +940,6 @@ class {ListClass}_iterator {{
940940
"sequence.index(x): x not in sequence");
941941
}}
942942
return idx;""".format(**locals())))
943-
c.addItem(extractors.CppMethodDef_cffi(
944-
'_new', isStatic=True,
945-
pyArgs=extractors.ArgsString('(WL_Object elements)'),
946-
pyBody="""\
947-
wrapper_lib.check_args_types(
948-
({0}._pyobject_mapping_, elements, "elements"))
949-
950-
keepalive = []
951-
ptrs = []
952-
for item in elements:
953-
if not isinstance(item, {1}):
954-
item = {1}._pyobject_mapping_.convert(item)
955-
keepalive.append(item)
956-
ptrs.append(wrapper_lib.get_ptr(item))
957-
958-
ptr = call(len(ptrs), ffi.new('void*[]', ptrs))
959-
return wrapper_lib.obj_from_ptr(ptr, {0}, True)
960-
""".format(ListClass_pyName, ItemClass_pyName),
961-
cReturnType='void *',
962-
cArgsString='(size_t count, void **elements)',
963-
# Don't send data to the constructor! This calls virtual methods,
964-
# which are not yet defined in the base C++ class... wx is broken.
965-
cBody='''
966-
{ListClass} *list = new {ListClass};
967-
list->DeleteContents(true); // tell the list to take ownership of the items
968-
for (Py_ssize_t i = 0; i < count; i++) {{
969-
list->Append(new {ItemClass}(*({ItemClass}*)elements[i]));
970-
}}
971-
return list;
972-
'''.format(**locals()),
973-
))
974943
# TODO: add support for index(value, [start, [stop]])
975944
c.addPyMethod(
976945
'__repr__', '(self)',
@@ -1034,6 +1003,37 @@ class {ListClass}_iterator {{
10341003
*sipCppPtr = list;
10351004
return SIP_TEMPORARY;
10361005
'''.format(**locals())
1006+
c.addItem(extractors.CppMethodDef_cffi(
1007+
'_new', isStatic=True,
1008+
pyArgs=extractors.ArgsString('(WL_Object elements)'),
1009+
pyBody="""\
1010+
wrapper_lib.check_args_types(
1011+
({0}._pyobject_mapping_, elements, "elements"))
1012+
1013+
keepalive = []
1014+
ptrs = []
1015+
for item in elements:
1016+
if not isinstance(item, {1}):
1017+
item = {1}._pyobject_mapping_.convert(item)
1018+
keepalive.append(item)
1019+
ptrs.append(wrapper_lib.get_ptr(item))
1020+
1021+
ptr = call(len(ptrs), ffi.new('void*[]', ptrs))
1022+
return wrapper_lib.obj_from_ptr(ptr, {0}, True)
1023+
""".format(ListClass_pyName, ItemClass_pyName),
1024+
cReturnType='void *',
1025+
cArgsString='(size_t count, void **elements)',
1026+
# Don't send data to the constructor! This calls virtual methods,
1027+
# which are not yet defined in the base C++ class... wx is broken.
1028+
cBody='''
1029+
{ListClass} *list = new {ListClass};
1030+
list->DeleteContents(true); // tell the list to take ownership of the items
1031+
for (Py_ssize_t i = 0; i < count; i++) {{
1032+
list->Append(new {ItemClass}(*({ItemClass}*)elements[i]));
1033+
}}
1034+
return list;
1035+
'''.format(**locals()),
1036+
))
10371037

10381038
c.instanceCheck_cffi = """\
10391039
if (not isinstance(py_obj, collections.Sequence) or

0 commit comments

Comments
 (0)