ni / grpc-device

gRPC server providing remote access to NI device driver APIs.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

grpc-device `nidaqmx_library` has unnecessary `size` parameter for scalar attribute get/set functions

bkeryan opened this issue · comments

The generic attribute get/set functions in nidaqmx_library have a size parameter, but for many data types this is unnecessary. The underlying DAQmx API functions like DAQmxGetChanAttribute and DAQmxSetChanAttribute only require a size parameter when getting/setting arrays and getting strings.

For example, here are the channel get/set functions in nidaqmx_library.h:

  int32 GetChanAttributeBool(TaskHandle task, const char channel[], int32 attribute, bool32* value, uInt32 size);
  int32 GetChanAttributeDouble(TaskHandle task, const char channel[], int32 attribute, float64* value, uInt32 size);
  int32 GetChanAttributeDoubleArray(TaskHandle task, const char channel[], int32 attribute, float64 value[], uInt32 size);
  int32 GetChanAttributeInt32(TaskHandle task, const char channel[], int32 attribute, int32* value, uInt32 size);
  int32 GetChanAttributeString(TaskHandle task, const char channel[], int32 attribute, char value[], uInt32 size);
  int32 GetChanAttributeUInt32(TaskHandle task, const char channel[], int32 attribute, uInt32* value, uInt32 size);

  int32 SetChanAttributeBool(TaskHandle task, const char channel[], int32 attribute, bool32 value, uInt32 size);
  int32 SetChanAttributeDouble(TaskHandle task, const char channel[], int32 attribute, float64 value, uInt32 size);
  int32 SetChanAttributeDoubleArray(TaskHandle task, const char channel[], int32 attribute, const float64 value[], uInt32 size);
  int32 SetChanAttributeInt32(TaskHandle task, const char channel[], int32 attribute, int32 value, uInt32 size);
  int32 SetChanAttributeString(TaskHandle task, const char channel[], int32 attribute, const char value[], uInt32 size);
  int32 SetChanAttributeUInt32(TaskHandle task, const char channel[], int32 attribute, uInt32 value, uInt32 size);

Here are the corresponding functions in NIDAQmx.h:

int32 __CFUNC_C   DAQmxGetChanAttribute          (TaskHandle taskHandle, const char channel[], int32 attribute, void *value, ...);
--
int32 __CFUNC_C   DAQmxSetChanAttribute          (TaskHandle taskHandle, const char channel[], int32 attribute, ...);
int32 __CFUNC     DAQmxResetChanAttribute        (TaskHandle taskHandle, const char channel[], int32 attribute);

DAQmxGetChanAttribute looks up the attribute id to find the attribute's data type (bool, double, etc.). If the data type requires a size (arrays and strings), it calls va_arg to get the size parameter; otherwise, it doesn't call va_arg.
 
DAQmxSetChanAttribute also looks up the attribute id to find the attribute's data type. It calls va_arg once to get the value parameter, and then if the data type requires a size (arrays but not strings), it calls va_arg again to get the size parameter.

These are varargs functions, so passing an extra parameter is benign. I filed this bug because we're going to start using this metadata to generate nidaqmx-python's attribute get/set functions, and this is a good opportunity to fix it.

AB#2357818

Fixed in #915