1 //------------------------------------------------------------------------------
2 // GB_ph_free: free the A->p and A->h content of a matrix
3 //------------------------------------------------------------------------------
4 
5 // SuiteSparse:GraphBLAS, Timothy A. Davis, (c) 2017-2021, All Rights Reserved.
6 // SPDX-License-Identifier: Apache-2.0
7 
8 //------------------------------------------------------------------------------
9 
10 // Free the A->p and A->h content of a matrix.  The matrix becomes invalid, and
11 // would generate a GrB_INVALID_OBJECT error if passed to a user-callable
12 // GraphBLAS function.
13 
14 #include "GB.h"
15 
16 GB_PUBLIC   // accessed by the MATLAB tests in GraphBLAS/Test only
GB_ph_free(GrB_Matrix A)17 void GB_ph_free                 // free A->p and A->h of a matrix
18 (
19     GrB_Matrix A                // matrix with content to free
20 )
21 {
22 
23     //--------------------------------------------------------------------------
24     // check inputs
25     //--------------------------------------------------------------------------
26 
27     if (A == NULL)
28     {
29         return ;
30     }
31 
32     //--------------------------------------------------------------------------
33     // free A->p and A->h
34     //--------------------------------------------------------------------------
35 
36     // free A->p unless it is shallow
37     if (!A->p_shallow)
38     {
39         GB_FREE (&(A->p), A->p_size) ;
40     }
41     A->p = NULL ;
42     A->p_size = 0 ;
43     A->p_shallow = false ;
44 
45     // free A->h unless it is shallow
46     if (!A->h_shallow)
47     {
48         GB_FREE (&(A->h), A->h_size) ;
49     }
50     A->h = NULL ;
51     A->h_size = 0 ;
52     A->h_shallow = false ;
53 
54     A->plen = 0 ;
55     A->nvec = 0 ;
56     A->nvec_nonempty = 0 ;
57 
58     //--------------------------------------------------------------------------
59     // set the status to invalid
60     //--------------------------------------------------------------------------
61 
62     // If this matrix is used as input to a user-callable GraphBLAS function,
63     // it will generate an error: GrB_INVALID_OBJECT.
64     A->magic = GB_MAGIC2 ;
65 }
66 
67