Skip to content

Commit bad107d

Browse files
Merge pull request #3 from chuoru/master
Replace csc_set_data with OSQPCscMatrix_new
2 parents 466ba28 + 34b4465 commit bad107d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

include/OsqpEigen/Compat.hpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -49,31 +49,22 @@ inline OSQPCscMatrix* spalloc(OSQPInt m,
4949
OSQPInt n,
5050
OSQPInt nzmax)
5151
{
52-
OSQPCscMatrix* M = static_cast<OSQPCscMatrix*>(calloc(1, sizeof(OSQPCscMatrix))); /* allocate the OSQPCscMatrix struct */
53-
if (!M)
54-
{
55-
return static_cast<OSQPCscMatrix*>(OSQP_NULL);
56-
}
57-
5852
OSQPInt* M_p = static_cast<OSQPInt*>(calloc(n + 1, sizeof(OSQPInt)));
5953
if (!M_p)
6054
{
61-
free(M);
6255
return static_cast<OSQPCscMatrix*>(OSQP_NULL);
6356
}
6457

6558
OSQPInt* M_i = static_cast<OSQPInt*>(calloc(nzmax, sizeof(OSQPInt)));
6659
if (!M_i)
6760
{
68-
free(M);
6961
free(M_p);
7062
return static_cast<OSQPCscMatrix*>(OSQP_NULL);
7163
}
7264

7365
OSQPFloat* M_x = static_cast<OSQPFloat*>(calloc(nzmax, sizeof(OSQPFloat)));
7466
if (!M_x)
7567
{
76-
free(M);
7768
free(M_p);
7869
free(M_i);
7970
return static_cast<OSQPCscMatrix*>(OSQP_NULL);
@@ -86,7 +77,14 @@ inline OSQPCscMatrix* spalloc(OSQPInt m,
8677
M_nnz = nzmax;
8778
}
8879

89-
csc_set_data(M, m, n, M_nnz, M_x, M_i, M_p);
80+
OSQPCscMatrix* M = OSQPCscMatrix_new(m, n, M_nnz, M_x, M_i, M_p);
81+
if (!M)
82+
{
83+
free(M_p);
84+
free(M_i);
85+
free(M_x);
86+
return static_cast<OSQPCscMatrix*>(OSQP_NULL);
87+
}
9088

9189
return M;
9290
}

0 commit comments

Comments
 (0)