/* Copyright (c) 2001-2009 by SoftIntegration, Inc. All Rights Reserved */
#include <dlfcn.h>
#include <array.h>
#include "ret_comp_arr.h"

array double ret_comp_arr()[ARRAY_DIM] {
  void *handle, *fptr;
  array double retval[ARRAY_DIM];

  handle = dlopen("libhello.dl", RTLD_LAZY);
  if(handle == NULL) {
     printf("Error: %s(): dlopen(): %s\n", __func__, dlerror());
     return retval;
  }

  fptr = dlsym(handle, "ret_comp_arr_chdl");
  if(fptr == NULL)  {
     printf("Error: %s(): dlsym(): %s\n", __func__, dlerror());
     return retval;
  }

  /* pass the address of the first element of retval
     to the C space */
  dlrunfun(fptr, NULL, NULL, &retval[0]);

  if(dlclose(handle)!=0) {
     printf("Error: %s(): dlclose(): %s\n", __func__, dlerror());
     return retval;
  }

  return retval;
}
