dwg_add_object (Dwg_Data *restrict dwg)
{
  Dwg_Object *restrict obj;
  BITCODE_BL num = dwg->num_objects;
  int realloced = 0;
  if (!num)
    dwg->object = calloc (REFS_PER_REALLOC, sizeof (Dwg_Object));
  else if (num % REFS_PER_REALLOC == 0)
    {
      Dwg_Object *restrict old = dwg->object;
      dwg->object = realloc (dwg->object,
                             (num + REFS_PER_REALLOC) * sizeof (Dwg_Object));
      realloced = old != dwg->object;
    }
  if (!dwg->object)
    return DWG_ERR_OUTOFMEM;

  obj = &dwg->object[num];
  memset (obj, 0, sizeof (Dwg_Object));
  obj->index = num;
  dwg->num_objects++;
  obj->parent = dwg;
  return realloced ? -1 : 0;
}
dwg_add_object (Dwg_Data *restrict dwg)
{
  Dwg_Object *restrict obj;
  BITCODE_BL num = dwg->num_objects;
  int realloced = 0;
  if (!num)
    dwg->object = calloc (REFS_PER_REALLOC, sizeof (Dwg_Object));
  else if (num % REFS_PER_REALLOC == 0)
    {
      Dwg_Object *restrict old = dwg->object;
      dwg->object = realloc (dwg->object,
                             (num + REFS_PER_REALLOC) * sizeof (Dwg_Object));
      realloced = old != dwg->object;
    }
  if (!dwg->object)
    return DWG_ERR_OUTOFMEM;

  obj = &dwg->object[num];
  memset (obj, 0, sizeof (Dwg_Object));
  obj->index = num;
  dwg->num_objects++;
  obj->parent = dwg;
  return realloced ? -1 : 0;
}