void gnm_validation_unref (GnmValidation const *val) { GnmValidation *v = (GnmValidation *)val; g_return_if_fail (v != NULL); v->ref_count--; if (v->ref_count < 1) { int i; if (v->title != NULL) { go_string_unref (v->title); v->title = NULL; } if (v->msg != NULL) { go_string_unref (v->msg); v->msg = NULL; } for (i = 0 ; i < 2 ; i++) dependent_managed_set_expr (&v->deps[i], NULL); g_free (v); } }
void validation_unref (GnmValidation const *val) { GnmValidation *v = (GnmValidation *)val; g_return_if_fail (v != NULL); v->ref_count--; if (v->ref_count < 1) { int i; if (v->title != NULL) { go_string_unref (v->title); v->title = NULL; } if (v->msg != NULL) { go_string_unref (v->msg); v->msg = NULL; } for (i = 0 ; i < 2 ; i++) if (v->texpr[i] != NULL) { gnm_expr_top_unref (v->texpr[i]); v->texpr[i] = NULL; } g_free (v); } }
void expr_name_unref (GnmNamedExpr *nexpr) { g_return_if_fail (nexpr != NULL); if (nexpr->ref_count-- > 1) return; if (gnm_debug_flag ("names")) g_printerr ("Finalizing name %s\n", nexpr->name->str); g_return_if_fail (nexpr->scope == NULL); if (nexpr->name) { go_string_unref (nexpr->name); nexpr->name = NULL; } if (nexpr->texpr != NULL) expr_name_set_expr (nexpr, NULL); if (nexpr->dependents != NULL) { g_hash_table_destroy (nexpr->dependents); nexpr->dependents = NULL; } nexpr->pos.wb = NULL; nexpr->pos.sheet = NULL; g_free (nexpr); }
static void gnm_data_cache_source_finalize (GObject *obj) { GnmDataCacheSource *src = (GnmDataCacheSource *)obj; go_string_unref (src->src_name); (parent_klass->finalize) (obj); }
void gnm_data_cache_source_set_name (GnmDataCacheSource *src, char const *name) { GOString *new_val; g_return_if_fail (IS_GNM_DATA_CACHE_SOURCE (src)); new_val = go_string_new (name); go_string_unref (src->src_name); src->src_name = new_val; }
/** * expr_name_set_name : * @nexpr : the named expression * @new_name : the new name of the expression * * returns: TRUE on error. */ gboolean expr_name_set_name (GnmNamedExpr *nexpr, const char *new_name) { const char *old_name; GHashTable *h; g_return_val_if_fail (nexpr != NULL, TRUE); g_return_val_if_fail (nexpr->scope == NULL || new_name, TRUE); old_name = nexpr->name->str; if (go_str_compare (new_name, old_name) == 0) return FALSE; #if 0 g_printerr ("Renaming %s to %s\n", old_name, new_name); #endif h = nexpr->scope ? (nexpr->is_placeholder ? nexpr->scope->placeholders : nexpr->scope->names) : NULL; if (h) { if (new_name && (g_hash_table_lookup (nexpr->scope->placeholders, new_name) || g_hash_table_lookup (nexpr->scope->names, new_name))) { /* The only error not to be blamed on the programmer is already-in-use. */ return TRUE; } g_hash_table_steal (h, old_name); } go_string_unref (nexpr->name); nexpr->name = go_string_new (new_name); if (h) g_hash_table_insert (h, (gpointer)nexpr->name->str, nexpr); return FALSE; }
/** * expr_name_add: * @pp: * @name: * @texpr: if texpr == NULL then create a placeholder with value #NAME? * @error_msg: * @link_to_container: * * Absorbs the reference to @texpr. * If @error_msg is non NULL it may hold a pointer to a translated descriptive * string. NOTE : caller is responsible for freeing the error message. * * The reference semantics of the new expression are * 1) new names with @link_to_container TRUE are referenced by the container. * The caller DOES NOT OWN a reference to the result, and needs to add their * own. * 2) if @link_to_container is FALSE the caller DOES OWN a reference, and * can free the result by unrefing the name. **/ GnmNamedExpr * expr_name_add (GnmParsePos const *pp, char const *name, GnmExprTop const *texpr, char **error_msg, gboolean link_to_container, GnmNamedExpr *stub) { GnmNamedExpr *nexpr = NULL; GnmNamedExprCollection *scope = NULL; g_return_val_if_fail (pp != NULL, NULL); g_return_val_if_fail (pp->sheet != NULL || pp->wb != NULL, NULL); g_return_val_if_fail (name != NULL, NULL); g_return_val_if_fail (stub == NULL || stub->is_placeholder, NULL); if (texpr != NULL && expr_name_check_for_loop (name, texpr)) { gnm_expr_top_unref (texpr); if (error_msg) *error_msg = g_strdup_printf (_("'%s' has a circular reference"), name); return NULL; } scope = (pp->sheet != NULL) ? pp->sheet->names : pp->wb->names; /* see if there was a place holder */ nexpr = g_hash_table_lookup (scope->placeholders, name); if (nexpr != NULL) { if (texpr == NULL) { /* there was already a placeholder for this */ expr_name_ref (nexpr); return nexpr; } /* convert the placeholder into a real name */ g_hash_table_steal (scope->placeholders, name); nexpr->is_placeholder = FALSE; } else { nexpr = g_hash_table_lookup (scope->names, name); /* If this is a permanent name, we may be adding it */ /* on opening of a file, although */ /* the name is already in place. */ if (nexpr != NULL) { if (nexpr->is_permanent) link_to_container = FALSE; else { if (error_msg != NULL) *error_msg = (pp->sheet != NULL) ? g_strdup_printf (_("'%s' is already defined in sheet"), name) : g_strdup_printf (_("'%s' is already defined in workbook"), name); gnm_expr_top_unref (texpr); return NULL; } } } if (error_msg) *error_msg = NULL; if (nexpr == NULL) { if (stub != NULL) { nexpr = stub; stub->is_placeholder = FALSE; go_string_unref (stub->name); stub->name = go_string_new (name); } else { nexpr = expr_name_new (name); nexpr->is_placeholder = (texpr == NULL); } } parse_pos_init (&nexpr->pos, pp->wb, pp->sheet, pp->eval.col, pp->eval.row); if (texpr == NULL) texpr = gnm_expr_top_new_constant (value_new_error_NAME (NULL)); expr_name_set_expr (nexpr, texpr); if (link_to_container) gnm_named_expr_collection_insert (scope, nexpr); return nexpr; }