On Sunday 28 of April 2013 16:35:25 Martin Milata wrote:
+int
+sr_py_setter_bool(PyObject *self, PyObject *rhs, void *data)
+{
+ struct getset_offsets *gsoff = data;
+
I'm not sure if it is relevant, but the condintion below forces users of the API to
convert everythnig to bool before assignment:
my_list = []
sr_obj.some_bool_prop = bool(mylist)
but you can write condition like the following:
if not my_list:
+ if (!PyBool_Check(rhs))
+ {
+ PyErr_SetString(PyExc_TypeError, "Boolean required.");
+ return -1;
+ }
+
+ bool newvalue = (rhs == Py_True);
+ MEMB_T(bool, MEMB(self, gsoff->c_struct_offset), gsoff->member_offset) =
newvalue;
+
+ return 0;
+}
+ *
+ * You need to define GSOFF_PY_STRUCT to be the type of the structure
defining + * the python object, GSOFF_PY_MEMBER to be the name of its
member pointing to + * the C structure, and GSOFF_C_STRUCT to be the type
of the C structure. Use + * GSOFF_MEMBER for each member you want to
access, GSOFF_MEMBER(m) defines the + * variable gsoff_m which can be used
in the declaration of getters and + * setters.
+ *
+ * See python/py_gdb_frame.c for example usage.
+ */
+#define GSOFF_START static struct getset_offsets
I like your this patch and I see you like macros, so I would add:
#define GSOFF_MEMBER_NAME(c_memeber) gsoff_ ## c_member
GSOFF_PY_MEMBER), \ + .member_offset = offsetof(struct
GSOFF_C_STRUCT, c_member) \ + }
+#define GSOFF_END ;
+
+/*
+ * Generic getters/setters that accept a struct getset_offsets as the data
+ * argument.
+ */
+PyObject *sr_py_getter_string(PyObject *self, void *data);
+int sr_py_setter_string(PyObject *self, PyObject *rhs, void *data);
+
+#define STRINGIZE_MEMBER(c_member) #c_member
+
+#define SR_PY_STRING_PROPERTY(c_member, doc_str) \
+ {(char *)STRINGIZE_MEMBER(c_member), sr_py_getter_string, sr_py_setter_string, (char
*)doc_str, &GSOFF_MEMBER_NAME(c_member)}
etc.
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* SATYR_PY_COMMON_H */
diff --git a/python/py_gdb_frame.c b/python/py_gdb_frame.c
index b69b1f6..36b7170 100644
+GSOFF_START
+GSOFF_MEMBER(function_name),
+GSOFF_MEMBER(function_type),jk
+GSOFF_MEMBER(source_file),
+GSOFF_MEMBER(number),
+GSOFF_MEMBER(source_line),
+GSOFF_MEMBER(signal_handler_called),
+GSOFF_MEMBER(address),
+GSOFF_MEMBER(library_name)
+GSOFF_END
+
+static PyGetSetDef
+frame_getset[] =
+{
+ SR_PY_STRING_PROPERTY(function_name, "Function name (string)"),