Skip to content

Conversation

@alien588
Copy link
Collaborator

Conversions for:

  • Int,
  • String,
  • Bool,
  • Float,
  • Complex Numbers,
  • Range,
  • Struct,
  • Enumeration.

Copy link

@tomaz-cvetko tomaz-cvetko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good in general, it would be good to rename some conversion functions to always have consistent naming in alignment with the direction of conversion.

There is also some discussion to be had regarding sideways interface casting - maybe I need to be educated what is possible there and what is not.

@alien588 alien588 requested a review from tomaz-cvetko January 29, 2026 11:58
@alien588 alien588 self-assigned this Jan 29, 2026
Comment on lines 99 to 109
daqList_createList(&names);

daqList_pushBack(names, (daqBaseObject*) stringOpenDAQConversion("Error"));
daqList_pushBack(names, (daqBaseObject*) stringOpenDAQConversion("Ok"));
daqList_pushBack(names, (daqBaseObject*) stringOpenDAQConversion("Warning"));

daqEnumerationType* enumType = NULL;
daqEnumerationType_createEnumerationType(&enumType, stringOpenDAQConversion("DAQ_ComponentStatusTypeEnum"), names, 0);

daqTypeManager_addType(typeManager, (daqType*) enumType);
daqReleaseRef(enumType);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enum is already present in openDAQ. This is now just duplicating it. We need the struct type, since no other representative struct types exist.

* from C to openDAQ a pointer to the TypeManager is needed because
* of the way openDAQ structs are implemented.
*/
struct Coordinates openDAQCoordinatesStructConversion(daqStruct* daq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The names of the objects should be something more descriptive.

* from C to openDAQ a pointer to the TypeManager is needed because
* of the way openDAQ enumeration is implemented.
*/
enum ComponentStatusTypeEnum openDAQEnumConversion(daqEnumeration* daq)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As with the struct conversion, this is an example not an utility method. This header should have a corresponding example that calls these helper methods. The enum and struct ones should not have any helpers, there should be examples only. The examples should also include creating a struct using the structBuilderFromStruct factory (name might be slightly different).

daqString_getCharPtr(str, &cString);
return cString;
}
char* daq_fromDaqString(daqString* daq);
Copy link

@tomaz-cvetko tomaz-cvetko Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function needs a separate docstring that explains whether or not the user should call free on the returned pointer. The classic C pattern would suggest that the caller must do the following

char* p = daq_fromDaqString(string);
// ...
if (p)
  free(p);

but I think that's not the case (?). Does this function return a non-owning pointer to an internal buffer?

daqFloatObject_getValue(value, &cDouble);
return cDouble;
}
double daq_fromDaqObject(daqFloatObject* daq);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There needs to be "float" in this function name. daq_fromDaqFloatObject?

Comment on lines +23 to +26
daqList_pushBack(names, (daqBaseObject*) daq_toDaqString("x"));
daqList_pushBack(names, (daqBaseObject*) daq_toDaqString("y"));
daqList_pushBack(names, (daqBaseObject*) daq_toDaqString("z"));

Copy link

@tomaz-cvetko tomaz-cvetko Feb 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it looks good, I think this is not okay, because you don't call daqReleaseRef on the pointer resulting from daq_toDaqString. While the conversions make creation automated, these are still not smart pointers and won't release resources when going out of scope.

  1. literal "x" is "created"
  2. in daq_toDaqString a new object is assigned to the pointer with daqString_createString and the pointer is returned.
  3. The newly created object is used inside the daqList_pushBack via the pointer passed by value.
  4. [MISSING] The newly created object is never released (at the moment that's not even possible, because the only reference to it is a temporary passed directly to the pushBack function.

Important: every use of conversion function daq_toDaq____ must have a daqReleaseRef pair.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants