[sv-cc] DPI: dynamic array cannot be passed for DPI open array output arg

From: Andrzej Litwiniuk <Andrzej.Litwiniuk@synopsys.com>
Date: Thu Mar 18 2004 - 15:47:59 PST

SV-CC team,

Please find below an errata to the LRM.

Regards,
Andrzej

-------------------------------------------------

1. Request

Please add the following remark at the very end of section 4.8, after
the sentence "An import DPI function that accepts a one-dimensional array
can be passed a dynamic array of a compatible type and of any size if
formal is unsized, and of the same size if formal is sized." :

However, a dynamic array cannot be passed as an argument if formal is an unsized output.

2. Rationale

The concept of DPI open arrays assumes that an array already exists and its
reference is passed to import DPI function. DPI function does not create
a new array, it solely reads or writes (or both) array elements.

Input/output/inout specifiers actually do apply to array elements rather than
to an array per se. Array is assumed to exist already and input/output/inout
mode specifies only whether array elements may be read, written or both.

Consider a dynamic array as an actual argument for an open array formal
argument of DPI function.
What will be the size of an array? Who will create it: caller or callee?

When a dynamic array is used as the actual argument for a formal output argument
of a function or task, the current size of that dynamic array is irrelevant and
the array may be empty since it will be replaced with a new value.
The size of the formal argument specifies the size of a dynamic array object
to be created/assigned to the actual argument.
Thus it is the callee who determines the size of a dynamic array.

On the other hand, in case of open array argument of import DPI function,
the caller determines the size of an open array, see 27.5.1 Argument passing:
"The unsized ranges of open arrays are determined at a call site"

Hence, if a dynamic array is passed as an actual argument for an open array
output arg, both a caller and a callee expect that it will be the other side who
would provide an array object (allocated space, address, size).

In other words, the size of a dynamic array to be manipulated inside DPI
function (as an output arg) is uknown and the array may not even exist.
Hence the proposed restriction for output arguments.

-------------------------------------------------
Received on Thu Mar 18 15:48:04 2004

This archive was generated by hypermail 2.1.8 : Thu Mar 18 2004 - 15:48:07 PST