[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: how to pass array from dll into IDL?
Nigel,
Make sure you supply a free_cb function in your example.
The line:
array = IDL_ImportArray(1, dims, IDL_TYP_BYTE, data, NULL, NULL);
should read something like:
array = IDL_ImportArray(1, dims, IDL_TYP_BYTE, data,
(IDL_ARRAY_FREE_CB)free, NULL);
to avoid a memory leak in your example.
FWIW.
>
> data.c:
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <unistd.h>
> #include <errno.h>
>
> #include "export.h"
>
> #define DATALEN 250
>
> IDL_VPTR get_data(int argc, IDL_VPTR argv[], char *argk)
> {
>
> IDL_VPTR array;
> IDL_LONG dims[IDL_MAX_ARRAY_DIM];
>
> IDL_VPTR result;
>
> unsigned char *data;
> int i;
>
> /*
> * get the data
> */
> data = malloc(DATALEN);
> if ( data == NULL )
> IDL_MESSAGE( IDL_M_NAMED_GENERIC, IDL_MSG_RET, strerror(errno));
>
> for ( i = 0; i < DATALEN; i++ )
> data[i] = i + 1;
>
> /*
> * create the return data array
> */
> dims[0] = DATALEN;
>
> array = IDL_ImportArray(1, dims, IDL_TYP_BYTE, data, NULL, NULL);
>
> return array;
> }
>
> int IDL_Load(void) {
>
> static IDL_SYSFUN_DEF function_addr[] = {
> { get_data, "GET_DATA", 0, 0, 0},
> };
>
> return IDL_AddSystemRoutine(function_addr, TRUE, 1);
> }
>
> data.dlm:
>
> MODULE data
> DESCRIPTION Create a simple data array.
> VERSION 1.0
> SOURCE Nigel Wade, Leicester University.
> BUILD_DATE July 6, 2001
> FUNCTION get_data 0 0
--
rjf.
Randy Frank | ASCI Visualization
Lawrence Livermore National Laboratory | rjfrank@llnl.gov
B451 Room 2039 L-561 | Voice: (925) 423-9399
Livermore, CA 94550 | Fax: (925) 423-8704