Skip to content

Commit c8b5d8e

Browse files
Augment qvi_new_rc(). (#88)
Trying to get away from fussy boilerplate code. Signed-off-by: Samuel K. Gutierrez <[email protected]>
1 parent a2906fe commit c8b5d8e

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/qvi-hwpool.cc

+1-7
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,7 @@ int
130130
qvi_hwpool_new(
131131
qvi_hwpool_t **rpool
132132
) {
133-
qvi_hwpool_t *irpool = qvi_new qvi_hwpool_t();
134-
int rc = qvi_new_rc(irpool);
135-
if (rc != QV_SUCCESS) {
136-
qvi_hwpool_free(&irpool);
137-
}
138-
*rpool = irpool;
139-
return rc;
133+
return qvi_new_rc(rpool);
140134
}
141135

142136
int

src/qvi-utils.h

+12-6
Original file line numberDiff line numberDiff line change
@@ -53,17 +53,23 @@ qvi_construct_rc(
5353
}
5454

5555
/**
56-
* Similar to qvi_construct_rc(), but is used also to check the value returned
57-
* by qvi_new.
56+
* Constructs a new object of a given type. *t will be valid if successful,
57+
* nullptr otherwise. Returns QV_SUCCESS if successful.
5858
*/
5959
template <class T>
6060
int
6161
qvi_new_rc(
62-
const T *const t
62+
T **t
6363
) {
64-
// qvi_new must have returned nullptr.
65-
if (!t) return QV_ERR_OOR;
66-
return t->qvim_rc;
64+
T *it = qvi_new T();
65+
if (!it) return QV_ERR_OOR;
66+
67+
const int rc = qvi_construct_rc(*it);
68+
if (rc != QV_SUCCESS) {
69+
qvi_delete(&it);
70+
}
71+
*t = it;
72+
return rc;
6773
}
6874

6975
#endif

0 commit comments

Comments
 (0)