In some cases, the documentation already had this right.
* to know what C or S actually are.
*/
* to know what C or S actually are.
*/
-void *sod_convert(const SodClass *cls, const void *p)
+void *sod_convert(const SodClass *cls, const void *obj)
- const struct sod_instance *inst = p;
+ const struct sod_instance *inst = obj;
const struct sod_vtable *vt = inst->_vt;
const SodClass *realcls = vt->_class;
const struct sod_chain *chain = find_chain(realcls, cls);
const struct sod_vtable *vt = inst->_vt;
const SodClass *realcls = vt->_class;
const struct sod_chain *chain = find_chain(realcls, cls);
- if (!chain)
- return (0);
- return ((char *)p - vt->_base + chain->off_ichain);
+ if (!chain) return (0);
+ return ((char *)obj - vt->_base + chain->off_ichain);
}
/*----- That's all, folks -------------------------------------------------*/
}
/*----- That's all, folks -------------------------------------------------*/
/* --- @SOD_XCHAIN@ --- *
*
* Arguments: @chead@ = nickname of target chain's head
/* --- @SOD_XCHAIN@ --- *
*
* Arguments: @chead@ = nickname of target chain's head
- * @p@ = pointer to an instance chain
+ * @obj@ = pointer to an instance chain
*
* Returns: Pointer to target chain, as a @char *@.
*
*
* Returns: Pointer to target chain, as a @char *@.
*
* the automatically-generated upcast macros more palatable.
*/
* the automatically-generated upcast macros more palatable.
*/
-#define SOD_XCHAIN(chead, p) ((char *)(p) + (p)->_vt->_off_##chead)
+#define SOD_XCHAIN(chead, obj) ((char *)(obj) + (obj)->_vt->_off_##chead)
/* --- @SOD_OFFSETDIFF@ --- *
*
/* --- @SOD_OFFSETDIFF@ --- *
*
*
* Arguments: @cls@ = name of a class
* @chead@ = nickname of chain head of @cls@
*
* Arguments: @cls@ = name of a class
* @chead@ = nickname of chain head of @cls@
- * @p@ = pointer to the @chead@ ichain of an (exact) instance of
- * @cls@
+ * @obj@ = pointer to the @chead@ ichain of an (exact) instance
+ * of @cls@
*
* Returns: A pointer to the instance's base, cast as a pointer to the
* ilayout structure.
*
* Returns: A pointer to the instance's base, cast as a pointer to the
* ilayout structure.
* necessary to use it safely.
*/
* necessary to use it safely.
*/
-#define SOD_ILAYOUT(cls, chead, p) \
+#define SOD_ILAYOUT(cls, chead, obj) \
((struct cls##__ilayout *) \
((struct cls##__ilayout *) \
- ((char *)(p) - offsetof(struct cls##__ilayout, chead)))
+ ((char *)(obj) - offsetof(struct cls##__ilayout, chead)))
+
+/*----- Utility macros ----------------------------------------------------*/
+
+/* --- @SOD_CLASSOF@ --- *
+ *
+ * Arguments: @p@ = pointer to an instance chain
+ *
+ * Returns: A pointer to the instance's class, as a const SodClass.
+ */
+
+#define SOD_CLASSOF(obj) ((const SodClass *)(obj)->_vt->_class)
/* --- @SOD_INSTBASE@ --- *
*
/* --- @SOD_INSTBASE@ --- *
*
- * Arguments: @p@ = pointer to an instance (i.e., the address of one of its
- * instance chains)
+ * Arguments: @obj@ = pointer to an instance (i.e., the address of one of
+ * its instance chains)
- * Returns: The base address of @p@'s instance layout.
+ * Returns: The base address of @obj@'s instance layout, as a @void *@.
*
* Use: Finds the base address of an instance. If you know the
* dynamic class of the object then @SOD_ILAYOUT@ is faster. If
*
* Use: Finds the base address of an instance. If you know the
* dynamic class of the object then @SOD_ILAYOUT@ is faster. If
* zeroizing the instance structure.
*/
* zeroizing the instance structure.
*/
-#define SOD_INSTBASE(p) ((void *)((char *)(p) - (p)->_vt->_base))
-
-/*----- Utility macros ----------------------------------------------------*/
+#define SOD_INSTBASE(obj) ((void *)((char *)(obj) - (obj)->_vt->_base))
-/* --- @SOD_CLASSOF@ --- *
+/* --- @SOD_CONVERT@ --- *
- * Arguments: @p@ = pointer to an instance chain
+ * Arguments: @cls@ = a class type name
+ * @const void *obj@ = a pointer to an instance
- * Returns: A pointer to the instance's class, as a const SodClass.
+ * Returns: Pointer to appropriate instance ichain, or null if the
+ * instance isn't of the specified class.
+ *
+ * Use: This is a simple wrapper around the @sod_convert@, which
+ * you should see for full details. It accepts a class type
+ * name rather than a pointer to a class object, and arranges to
+ * return a pointer of the correct type.
-#define SOD_CLASSOF(p) ((const SodClass *)(p)->_vt->_class)
+#define SOD_CONVERT(cls, obj) ((cls *)sod_convert(cls##__class, (obj)))
/*----- Functions provided ------------------------------------------------*/
/*----- Functions provided ------------------------------------------------*/
* to know what either C or S actually are.
*/
* to know what either C or S actually are.
*/
-extern void *sod_convert(const SodClass */*cls*/, const void */*p*/);
+extern void *sod_convert(const SodClass */*cls*/, const void */*obj*/);
/*----- That's all, folks -------------------------------------------------*/
/*----- That's all, folks -------------------------------------------------*/