/*-------------------------------------------------------------------------*/ struct_t * struct_new (struct_type_t *pSType) /* Create a new empty struct instance for struct type <pSType> * and return it. * Return NULL when out of memory. * * The returned struct will have one reference. */ { struct_t *pStruct; size_t size; #ifdef DEBUG if (pSType == NULL) fatal("NULL typeobject pointer passed to struct_new().\n"); #endif size = STRUCT_MEMSIZE_FROM_TYPE(pSType); pStruct = xalloc(size); if (pStruct != NULL) { unsigned short num; svalue_t *svp; pStruct->ref = 1; pStruct->type = ref_struct_type(pSType); if (current_object) pStruct->user = current_object->user; else pStruct->user = &default_wizlist_entry; for (num = pSType->num_members, svp = pStruct->member ; num-- > 0 ; svp++) { put_number(svp, 0); } num_struct++; size_struct += size; pStruct->user->struct_total += size; } return pStruct; } /* struct_new() */
/*-------------------------------------------------------------------------*/ lpctype_t * get_struct_type (struct_type_t* def) /* Create an lpctype_t around <def>, check for already * existing definitions. */ { lpctype_t *type = def->lpctype; if (type != NULL) return ref_lpctype(type); def->lpctype = type = lpctype_new(); type->t_class = TCLASS_STRUCT; type->t_struct = ref_struct_type(def); return type; } /* get_struct_type() */