Skip to content

StreamRead appears to have misconfigured parameters #693

@negentropicdev

Description

@negentropicdev

VIREO_FUNCTION_SIGNATURE4(StreamRead, FileHandle, TypedArrayCoreRef, Int32, Int32)
{
FileHandle handle = _Param(0);
TypedArrayCoreRef array = _Param(1);
Int32 numElts = _Param(2);
Int32 bytesToRead = 0;
if (numElts == -1) {
struct stat fileInfo;
fstat(handle, &fileInfo);
bytesToRead = (Int32) fileInfo.st_size;
// TODO(fileio) is rounding correct here?
// Only read full elements from the file
numElts = bytesToRead / array->ElementType()->TopAQSize();
}
if (array->Resize1DOrEmpty(numElts)) {
// Final count is determined by how big the array ended up.
bytesToRead = array->AQBlockLength(array->Length());
#ifdef VIREO_POSIX_FILEIO
ssize_t bytesRead = POSIX_NAME(read)(handle, array->RawBegin(), bytesToRead);
#else
#error platform not supported
#endif
if (bytesRead < 0) {
_Param(3) = (Int32) bytesRead; // TODO(fileio) error processing
array->Resize1D(0);
} else if (bytesToRead != bytesRead) {
// size the array to the number of full elements read.
array->Resize1D((IntIndex) (bytesRead / array->ElementType()->TopAQSize()) );
}
}
return _NextInstruction();
}

StreamRead has parameters: FileHandle, Output String, Num Elements, Return Status (Based on my interpretation of their usage in the method), however on line 438 NumElements is configured as an output.

I'd like to propose to swap parameters 2 and 3 and change the prototype definition to:
p(i(FileHandle)i(Int32)o(String)o(Int32))

As it's currently:
p(i(FileHandle)o(String)o(Int32)o(Int32))

I didn't see any tests referring to StreamRead so I presume it's likely not in use.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions