(*eohptr->eoh_methods->flatten_into) (eohptr, result, allocated_size);
}
-/*
- * Does the Datum represent a writable expanded object?
- */
-bool
-DatumIsReadWriteExpandedObject(Datum d, bool isnull, int16 typlen)
-{
- /* Reject if it's NULL or not a varlena type */
- if (isnull || typlen != -1)
- return false;
-
- /* Reject if not a read-write expanded-object pointer */
- if (!VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
- return false;
-
- return true;
-}
-
/*
* If the Datum represents a R/W expanded object, change it to R/O.
* Otherwise return the original Datum.
+ *
+ * Caller must ensure that the datum is a non-null varlena value. Typically
+ * this is invoked via MakeExpandedObjectReadOnly(), which checks that.
*/
Datum
-MakeExpandedObjectReadOnly(Datum d, bool isnull, int16 typlen)
+MakeExpandedObjectReadOnlyInternal(Datum d)
{
ExpandedObjectHeader *eohptr;
- /* Nothing to do if it's NULL or not a varlena type */
- if (isnull || typlen != -1)
- return d;
-
/* Nothing to do if not a read-write expanded-object pointer */
if (!VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
return d;
#define EOHPGetRWDatum(eohptr) PointerGetDatum((eohptr)->eoh_rw_ptr)
#define EOHPGetRODatum(eohptr) PointerGetDatum((eohptr)->eoh_ro_ptr)
+/* Does the Datum represent a writable expanded object? */
+#define DatumIsReadWriteExpandedObject(d, isnull, typlen) \
+ (((isnull) || (typlen) != -1) ? false : \
+ VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(d)))
+
+#define MakeExpandedObjectReadOnly(d, isnull, typlen) \
+ (((isnull) || (typlen) != -1) ? (d) : \
+ MakeExpandedObjectReadOnlyInternal(d))
+
extern ExpandedObjectHeader *DatumGetEOHP(Datum d);
extern void EOH_init_header(ExpandedObjectHeader *eohptr,
const ExpandedObjectMethods *methods,
extern Size EOH_get_flat_size(ExpandedObjectHeader *eohptr);
extern void EOH_flatten_into(ExpandedObjectHeader *eohptr,
void *result, Size allocated_size);
-extern bool DatumIsReadWriteExpandedObject(Datum d, bool isnull, int16 typlen);
-extern Datum MakeExpandedObjectReadOnly(Datum d, bool isnull, int16 typlen);
+extern Datum MakeExpandedObjectReadOnlyInternal(Datum d);
extern Datum TransferExpandedObject(Datum d, MemoryContext new_parent);
extern void DeleteExpandedObject(Datum d);