+/* Test what type of parent we have. Three possibilities: another
+ interval, a buffer or string object, or NULL_INTERVAL. */
+#define INTERVAL_HAS_PARENT(i) ((i)->up_obj == 0 && (i)->up.interval != 0)
+#define INTERVAL_HAS_OBJECT(i) ((i)->up_obj)
+
+/* Set/get parent of an interval.
+
+ The choice of macros is dependent on the type needed. Don't add
+ casts to get around this, it will break some development work in
+ progress. */
+#define SET_INTERVAL_PARENT(i,p) \
+ (eassert (!INT_LISPLIKE (p)), (i)->up_obj = 0, (i)->up.interval = (p))
+#define SET_INTERVAL_OBJECT(i,o) \
+ (eassert (BUFFERP (o) || STRINGP (o)), (i)->up_obj = 1, (i)->up.obj = (o))
+#define INTERVAL_PARENT(i) \
+ (eassert ((i) != 0 && (i)->up_obj == 0),(i)->up.interval)
+#define GET_INTERVAL_OBJECT(d,s) (eassert((s)->up_obj == 1), (d) = (s)->up.obj)
+
+/* Make the parent of D be whatever the parent of S is, regardless of
+ type. This is used when balancing an interval tree. */
+#define COPY_INTERVAL_PARENT(d,s) \
+ ((d)->up = (s)->up, (d)->up_obj = (s)->up_obj)
+
+/* Get the parent interval, if any, otherwise a null pointer. Useful
+ for walking up to the root in a "for" loop; use this to get the
+ "next" value, and test the result to see if it's NULL_INTERVAL. */
+#define INTERVAL_PARENT_OR_NULL(i) \
+ (INTERVAL_HAS_PARENT (i) ? INTERVAL_PARENT (i) : 0)
+
+/* Abort if interval I's size is negative. */
+#define CHECK_TOTAL_LENGTH(i) \
+ if ((int) (i)->total_length < 0) abort (); else
+