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

array double comp_array(int i) [:] {
  void *handle, *fptr;
  array double retval[i];

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

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

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

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

  return retval;
}
