We got a bug report where someone was iterating over the modules and
wanted to verify that the module name was empty and noticed it didn't
trigger.
```
for module in target.module_iter():
if module.file is None or module.file == "":
# Do something
```
My initial hypothesis was that we were somehow skipping modules, but
upon further investigation, it was the string comparison that was the
culprit. The reporter (reasonably) expected the `file` property to
return a string, but in reality it returns a SBFileSpec.
This could be avoided by explicitly comparing with an empty FileSpec,
but that seems needlessly tedious.
```
for module in target.module_iter():
if module.file is None or module.file == lldb.SBFileSpec(""):
# Do something
```
Instead, add support for comparing a SBFileSpec against a string.
rdar://174166420
29 lines
1.2 KiB
OpenEdge ABL
29 lines
1.2 KiB
OpenEdge ABL
STRING_EXTENSION_OUTSIDE(SBFileSpec)
|
|
|
|
%extend lldb::SBFileSpec {
|
|
#ifdef SWIGPYTHON
|
|
%pythoncode %{
|
|
# operator== is a free function, which swig does not handle, so we inject
|
|
# our own equality operator here
|
|
def __eq__(self, other):
|
|
if isinstance(other, str):
|
|
other = SBFileSpec(other)
|
|
if not isinstance(other, SBFileSpec):
|
|
return NotImplemented
|
|
return not self.__ne__(other)
|
|
|
|
def __ne__(self, other):
|
|
if isinstance(other, str):
|
|
other = SBFileSpec(other)
|
|
if not isinstance(other, SBFileSpec):
|
|
return NotImplemented
|
|
return _lldb.SBFileSpec___ne__(self, other)
|
|
|
|
fullpath = property(str, None, doc='''A read only property that returns the fullpath as a python string.''')
|
|
basename = property(GetFilename, None, doc='''A read only property that returns the path basename as a python string.''')
|
|
dirname = property(GetDirectory, None, doc='''A read only property that returns the path directory name as a python string.''')
|
|
exists = property(Exists, None, doc='''A read only property that returns a boolean value that indicates if the file exists.''')
|
|
%}
|
|
#endif
|
|
}
|