Type improvements#5
Conversation
| serialized_dict = {TYPE: BRIDGED, VALUE: data._bridge_handle} | ||
| elif isinstance(data, type(None)): | ||
| serialized_dict = {TYPE: NONE} | ||
| elif hasattr(data, "typeName"): |
There was a problem hiding this comment.
typeName is only a Jython thing, this won't work for other environments
| try: | ||
| # For objects this has not just the class, but the full module path | ||
| # e.g. "ghidra.program.database.ProgramDB" for currentProgram instead of just "ProgramDB" | ||
| _type = type(self.local_obj).typeName |
There was a problem hiding this comment.
As mentioned, only true for Jython. I think it might make more sense for your usecase to explicitly query for the typeName object in your code, instead of embedding it here.
| return {HANDLE: self.handle, TYPE: _type, ATTRS: self.attrs, REPR: repr(self.local_obj)} | ||
|
|
||
| if hasattr(self.local_obj, "typeName"): | ||
| _name = self.local_obj.typeName |
There was a problem hiding this comment.
Why add _name, what do you get that's different from _type?
There was a problem hiding this comment.
For a Class like ghidra.GhidraApplicationLayout _type will be something like JavaClass and __name__ is GhidraApplicationLayout. But I need the ghidra.GhidraApplicationLayout which is in .typeName for a Class object
|
Ok, seems like this doesn't work as I thought overall. What would solve my problem is maybe some way to register functions for attributes that retrieve the attribute on object creation so I don't have to waste bridge traversals when I expect that I will need this for many objects/classes anyway and it is just a string. Batch Get somewhat alleviates this, but I think the cost of adding a few strings for every object creation is basically zero, while having to traverse the bridge later (even for a batch call) is around 10-20ms of latency. I think if it is really just one batch call per object introspection it is acceptable, but this would also require that accessing |
e1231a9 to
a1317b6
Compare
a298e1b to
0658bd4
Compare
Extracted from #4