dwg_get_layers (const Dwg_Data *dwg)
{
  unsigned int i;
  unsigned int num_layers = dwg_get_layer_count (dwg);
  Dwg_Object_LAYER_CONTROL *_ctrl;
  Dwg_Object_LAYER **layers;
  Dwg_Object *ctrl;

  assert (dwg);
  ctrl = dwg_get_first_object (dwg, DWG_TYPE_LAYER_CONTROL);
  if (!ctrl || !ctrl->tio.object || !ctrl->tio.object->tio.LAYER_CONTROL)
    return NULL;
  _ctrl = ctrl->tio.object->tio.LAYER_CONTROL;
  assert (_ctrl);
  layers = (Dwg_Object_LAYER **)calloc (num_layers, sizeof (Dwg_Object_LAYER *));
  for (i = 0; i < num_layers; i++)
    {
      Dwg_Object *obj = dwg_ref_object (dwg, _ctrl->entries[i]);
      if (obj && obj->fixedtype == DWG_TYPE_LAYER)
        layers[i] = obj->tio.object->tio.LAYER;
    }
  return layers;
}
dwg_get_layers (const Dwg_Data *dwg)
{
  unsigned int i;
  unsigned int num_layers = dwg_get_layer_count (dwg);
  Dwg_Object_LAYER_CONTROL *_ctrl;
  Dwg_Object_LAYER **layers;
  Dwg_Object *ctrl;

  assert (dwg);
  ctrl = dwg_get_first_object (dwg, DWG_TYPE_LAYER_CONTROL);
  if (!ctrl || !ctrl->tio.object || !ctrl->tio.object->tio.LAYER_CONTROL)
    return NULL;
  _ctrl = ctrl->tio.object->tio.LAYER_CONTROL;
  assert (_ctrl);
  layers = (Dwg_Object_LAYER **)calloc (num_layers, sizeof (Dwg_Object_LAYER *));
  for (i = 0; i < num_layers; i++)
    {
      Dwg_Object *obj = dwg_ref_object (dwg, _ctrl->entries[i]);
      if (obj && obj->fixedtype == DWG_TYPE_LAYER)
        layers[i] = obj->tio.object->tio.LAYER;
    }
  return layers;
}