Get the gdb.Value for the given field within the PyObject, coping with some python 2 versus python 3 differences. Various libpython types are defined using the "PyObject_HEAD" and "PyObject_VAR_HEAD" macros. In Python 2, this these are defined so that "ob_t
(self, name)
| 185 | self._gdbval = gdbval |
| 186 | |
| 187 | def field(self, name): |
| 188 | ''' |
| 189 | Get the gdb.Value for the given field within the PyObject, coping with |
| 190 | some python 2 versus python 3 differences. |
| 191 | |
| 192 | Various libpython types are defined using the "PyObject_HEAD" and |
| 193 | "PyObject_VAR_HEAD" macros. |
| 194 | |
| 195 | In Python 2, this these are defined so that "ob_type" and (for a var |
| 196 | object) "ob_size" are fields of the type in question. |
| 197 | |
| 198 | In Python 3, this is defined as an embedded PyVarObject type thus: |
| 199 | PyVarObject ob_base; |
| 200 | so that the "ob_size" field is located insize the "ob_base" field, and |
| 201 | the "ob_type" is most easily accessed by casting back to a (PyObject*). |
| 202 | ''' |
| 203 | if self.is_null(): |
| 204 | raise NullPyObjectPtr(self) |
| 205 | |
| 206 | if name == 'ob_type': |
| 207 | pyo_ptr = self._gdbval.cast(PyObjectPtr.get_gdb_type()) |
| 208 | return pyo_ptr.dereference()[name] |
| 209 | |
| 210 | if name == 'ob_size': |
| 211 | pyo_ptr = self._gdbval.cast(PyVarObjectPtr.get_gdb_type()) |
| 212 | return pyo_ptr.dereference()[name] |
| 213 | |
| 214 | # General case: look it up inside the object: |
| 215 | return self._gdbval.dereference()[name] |
| 216 | |
| 217 | def pyop_field(self, name): |
| 218 | ''' |
no test coverage detected