Github user cwelton commented on a diff in the pull request:
https://github.com/apache/incubator-madlib/pull/10#discussion_r49820902
--- Diff: methods/array_ops/src/pg_gp/array_ops.c ---
@@ -824,6 +836,25 @@ array_fill(PG_FUNCTION_ARGS){
}
/*
+ * This function apply cos function to each element.
+ */
+PG_FUNCTION_INFO_V1(array_cos);
+Datum
+array_cos(PG_FUNCTION_ARGS){
+ if (PG_ARGISNULL(0)) { PG_RETURN_NULL(); }
+
+ ArrayType *v1 = PG_GETARG_ARRAYTYPE_P(0);
+ Oid element_type = ARR_ELEMTYPE(v1);
+ Datum v2 = float8_datum_cast(0, element_type);
+
+ ArrayType *res = General_Array_to_Array(v1, v2, element_cos);
+
+ PG_FREE_IF_COPY(v1, 0);
--- End diff --
In answer to your question, you can think of the parameter that is being
received as a union between (toastid, text_pointer). If you receive a pointer
then you do not get a copy, if you get a toastid then the GET_ARRAY_TYPE
function will detoast it and return a pointer to you. In neither case do you
"get a copy" of a pointer that was passed as input, which is what led to the
initial confusion here - "free_if_copy" is a misleading name for the macro.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---