/** * Sets up a component for the given attribute. * * If the component of the specified ComponentID does not already exist, * a new Component object is created, set up, and assigned to the attribute's * component array. Finally, the component path is initialised using the * path argument. * * @see component_full_name * @param attribute The Attribute for which to create this component. * @param cid The ID of the component to create. * @param path Path to be passed to component_full_name. Can be NULL. * @return The new component if all is OK. If a component with the * specified ID already exists, it is returned and no new * component is created (and a warning message is printed * to STDERR). If the attribute is NULL, return is NULL * (and a warning is printed). */ Component * declare_component(Attribute *attribute, ComponentID cid, char *path) { Component *component; if (attribute == NULL) { fprintf(stderr, "attributes:declare_component(): \n" " NULL attribute passed in declaration of %s component\n", cid_name(cid)); return NULL; } else if ((component = attribute->any.components[cid]) == NULL) { component = new(Component); component->id = cid; component->corpus = attribute->any.mother; component->attribute = attribute; component->path = NULL; init_mblob(&(component->data)); /* important to do this before the call to component_full_name */ attribute->any.components[cid] = component; /* initialize component path */ (void) component_full_name(attribute, cid, path); return component; } else { fprintf(stderr, "attributes:declare_component(): Warning:\n" " Component %s of %s declared twice\n", cid_name(cid), attribute->any.name); return component; } /* notreached */ assert("Notreached point reached ..." && 0); return NULL; }
/** * Frees the memory used by a MemBlob. * * This works regardless of the method used to allocate the blob. */ void mfree(MemBlob *blob) { unsigned int map_len; assert((blob != NULL) && "You can't pass a NULL blob to mfree"); if (blob->data != NULL) { switch (blob->allocation_method) { case UNALLOCATED: Rprintf( "storage:mfree():\n" " Blob flag is UNALLOCATED, but data present -- no free\n"); break; case MMAPPED: map_len = (blob->size > 0) ? blob->size : MMAP_EMPTY_LEN; if (munmap((caddr_t)blob->data, map_len) < 0) perror("storage:munmap()"); break; case MALLOCED: free((void *)blob->data); break; case PAGED: assert("Paged memory not yet implemented" && 0); break; default: assert("Illegal memory storage class in storage:mfree()" && 0); break; } if (blob->fname != NULL) free(blob->fname); init_mblob(blob); } else if (blob->allocation_method != UNALLOCATED) Rprintf( "storage:mfree():\n" " No data, but Blob flag isn't UNALLOCATED\n"); }