gfphoenix78 commented on code in PR #1364:
URL: https://github.com/apache/cloudberry/pull/1364#discussion_r2387301906
##########
contrib/pax_storage/src/cpp/comm/cbdb_wrappers.h:
##########
@@ -194,6 +196,22 @@ struct varlena *PgDeToastDatum(struct varlena *datum);
struct varlena *PgDeToastDatumPacked(struct varlena *datum);
+static pg_attribute_always_inline struct varlena *VarlenaShortTo4B(struct
varlena *attr) {
+ Assert(attr != nullptr);
+ Assert(VARATT_IS_SHORT(attr));
+ Size data_size = VARSIZE_SHORT(attr) - VARHDRSZ_SHORT;
+ Size new_size = data_size + VARHDRSZ;
+
+ struct varlena *new_attr =
+ reinterpret_cast<struct varlena *>(std::malloc(new_size));
+
+ Assert(new_attr != nullptr);
+
+ SET_VARSIZE(new_attr, new_size);
+ std::memcpy(VARDATA(new_attr), VARDATA_SHORT(attr), data_size);
+ return new_attr;
+}
+
Review Comment:
The allocation and free are separated in the code. The value is only used
temporarily, how about returning a c++ object? When the object is out of live,
the memory is freed. The function is not necessarily defined in
cbdb_wrappers.h, because it's a wrap-function.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]