Github user iyerr3 commented on a diff in the pull request:

    https://github.com/apache/incubator-madlib/pull/10#discussion_r49807227
  
    --- 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 --
    
    So during the detoast, PG_GETARG_ARRAYTYPE_P does not create a copy? I was 
under the impression that we have to free that pointer since a copy is always 
created. All array ops functions in MADlib perform that free, based on similar 
functions in pg source code. 
    If that's wrong then we'll have to make a pretty big change in our 
array_ops. 
    
    Snippet from /src/backend/utils/adt/arrayfuncs.c: 
    ```
    Datum
    array_eq(PG_FUNCTION_ARGS)
    {
        ArrayType  *array1 = PG_GETARG_ARRAYTYPE_P(0);
        ArrayType  *array2 = PG_GETARG_ARRAYTYPE_P(1);
        Oid                     collation = PG_GET_COLLATION();
        int                     ndims1 = ARR_NDIM(array1);
        int                     ndims2 = ARR_NDIM(array2);
        int                *dims1 = ARR_DIMS(array1);
        int                *dims2 = ARR_DIMS(array2);
    ...
    ...
    ...
        /* Avoid leaking memory when handed toasted input. */
        PG_FREE_IF_COPY(array1, 0);
        PG_FREE_IF_COPY(array2, 1);
    
        PG_RETURN_BOOL(result);
    }
    ```


---
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 infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to