[tips] g_clear_pointer
因為在tracking一個bug,
所以要backport indicator-power這個package到ubuntu precise.
意外發現了glib在2.33之後支援的一個還滿好用的function:
g_clear_pointer()
簡言之以前的寫法,要把物件刪除再把指標設為NULL:
if (priv->object_path != NULL) {
g_free(priv->object_path);
priv->object_path = NULL;
}
現在只要一行就可以達成了
g_clear_pointer (&priv->object_path, g_free);當然要backport的話作法就是相反~~





沒有留言:
張貼留言