Skip to content

Commit 6b46aa7

Browse files
committed
Replace g_assert with error handling
Release builds often define the compile option -DG_DISABLE_ASSERT for performance optimization. When this option is enabled, the g_assert(condition) macro is replaced by a no-op by the preprocessor. Signed-off-by: hyunil park <[email protected]>
1 parent b80c7f5 commit 6b46aa7

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

c/src/ml-api-common-tizen-feature-check.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,23 @@ static feature_info_s *feature_info = NULL;
4545
/**
4646
* @brief Internal function to initialize feature state.
4747
*/
48-
static void
48+
static int
4949
ml_tizen_initialize_feature_state (void)
5050
{
5151
int i;
5252

5353
if (feature_info == NULL) {
54-
feature_info = g_new0 (feature_info_s, 1);
55-
g_assert (feature_info);
54+
feature_info = g_try_new0 (feature_info_s, 1);
55+
if (feature_info == NULL) {
56+
_ml_loge ("Failed to allocate memory for feature_info");
57+
return ML_ERROR_OUT_OF_MEMORY;
58+
}
5659

5760
g_mutex_init (&feature_info->mutex);
5861
for (i = 0; i < ML_FEATURE_MAX; i++)
5962
feature_info->feature_state[i] = NOT_CHECKED_YET;
6063
}
64+
return ML_ERROR_NONE;
6165
}
6266

6367
/**
@@ -66,7 +70,12 @@ ml_tizen_initialize_feature_state (void)
6670
int
6771
_ml_tizen_set_feature_state (ml_feature_e ml_feature, int state)
6872
{
69-
ml_tizen_initialize_feature_state ();
73+
int status;
74+
75+
status = ml_tizen_initialize_feature_state ();
76+
if (status != ML_ERROR_NONE)
77+
return status;
78+
7079
g_mutex_lock (&feature_info->mutex);
7180

7281
/**
@@ -96,8 +105,11 @@ _ml_tizen_get_feature_enabled (ml_feature_e ml_feature)
96105
{
97106
int ret;
98107
int feature_enabled;
108+
int status;
99109

100-
ml_tizen_initialize_feature_state ();
110+
status = ml_tizen_initialize_feature_state ();
111+
if (status != ML_ERROR_NONE)
112+
return status;
101113

102114
g_mutex_lock (&feature_info->mutex);
103115
feature_enabled = feature_info->feature_state[ml_feature];

c/src/ml-api-inference-pipeline.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ construct_pipeline_internal (const char *pipeline_description,
10311031
pipeline = gst_parse_launch (description, &err);
10321032
g_free (description);
10331033

1034-
if (pipeline == NULL || err) {
1034+
if (pipeline == NULL || err || !GST_IS_PIPELINE (pipeline)) {
10351035
_ml_error_report
10361036
("ml_pipeline_construct error: gst_parse_launch cannot parse and launch the given pipeline = [%s]. The error message from gst_parse_launch is '%s'.",
10371037
pipeline_description, (err) ? err->message : "unknown reason");
@@ -1044,12 +1044,16 @@ construct_pipeline_internal (const char *pipeline_description,
10441044
goto failed;
10451045
}
10461046

1047-
g_assert (GST_IS_PIPELINE (pipeline));
10481047
pipe_h->element = pipeline;
10491048

10501049
/* bus and message callback */
10511050
pipe_h->bus = gst_element_get_bus (pipeline);
1052-
g_assert (pipe_h->bus);
1051+
if (pipe_h->bus == NULL) {
1052+
_ml_error_report
1053+
("ml_pipeline_construct error: Failed to retrieve bus from the pipeline.");
1054+
status = ML_ERROR_STREAMS_PIPE;
1055+
goto failed;
1056+
}
10531057

10541058
gst_bus_enable_sync_message_emission (pipe_h->bus);
10551059
pipe_h->signal_msg = g_signal_connect (pipe_h->bus, "sync-message",

0 commit comments

Comments
 (0)