New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove variable arguments from C-API #435
Comments
Comment by andreas.junghanns on 6 Jun 2018 09:37 UTC Who should we make life easier: Exporters or importers? |
Comment by tsommer on 6 Jun 2018 13:17 UTC |
Comment by Andreas Nicolai on 6 Jun 2018 16:45 UTC
I can only imagine a scenario for the exporting FMU where some of the For the importing side things could be resolved equally simple by Still, in my oponion, the request is valid - don't make an API more -Andreas |
Comment by pierre.mai on 12 Jun 2018 21:11 UTC
So not only is the current definition inconvenient for a number of importing tools, it is also inconvenient for FMU writers (especially those FMUs which are manually programmed and not auto-generated, since of course auto-generators can inline calls to the callback at all appropriate places). Additionally there have been quite a few instances where ABI implementations between compilers have had subtle differences in handling of stack alignment for variadic functions, so the current approach also risks subtle stack or memory corrupting bugs in those cases (this in itself is not a compelling argument, but adds to my weariness in having variadic functions in cross-compiler calls ... I've spent too much blood on dealing with these issues on various PowerPC ABIs for example). Handling of variable references On a related note, the facility for referencing variables through their value references also seems problematic, since VRs do not actually uniquely identify variables (=> aliases), so the simulation environment cannot know which variable name to use in those cases (this was more clear in FMI 1.0, where one of the aliases was to be called out as not an alias, but for FMI 2.0 this restriction no longer exists). It is also unclear what advantages this offers, since the FMU itself should be able to know its variable names (and changing them in the modelDescription.xml after generation is not allowed). So unless I'm missing a compelling reason for this added complexity (which I very well might, BTW), I think this needs at least re-design or clarification. |
Comment by hansolsson on 6 Jul 2018 12:09 UTC IF that weren't the case the variable number of argument variants would have an advantage in terms of allowing an implementation to delay formatting messages until it knows they will actually be logged. As I understand it variable number of argument functions are problematic for safety reasons (and there exists a number of variants to reduce this). The simplest mistake would be when we have a pre-formatted message and use logger(..., message) instead of logger(..., "%s", message). Thus I see that it would make sense to use a fixed number of arguments function in the interface. |
Comment by Andreas Nicolai on 6 Jul 2018 12:30 UTC In my opinion there are only two valid use cases that warrant the splitting of text and arguments:
The first is clearly out of focus, since it would require much more conventions for message strings generated by FMUs to work. The second is more or less artificial, since the printf() format specifications already allow definition of precision/number formats and those would then be overruled by, for example, the GUI that displays the message. But that overruling of number formatting may not be in the interest of the FMU that generated the message in the first place (just think about layout problems, where the FMU tries to generate a concise table-like output where fixed number sizes are used). Hence, both use cases are not applicable. Personally, I see no use case to split message and arguments in the first place. Do you? If there is no valid reason, please change the logger interface into a simple function that provides a complete message string and a fixed number of arguments! -Andreas |
Comment by dag.bruck on 6 Jul 2018 12:50 UTC (As a side note, MSL got it wrong in at least two places.) |
Comment by anonymous on 25 Jul 2018 14:05 UTC |
Comment by beutlich on 13 Aug 2018 07:41 UTC
Do you mean the availability or the usage of the Modelica utility functions ModelicaFormatMessage / ModelicaFormatError / ModelicaFormatWarning? In case of the availability it is a Modelica specification issue and not a library issue (though MSL still could avoid to use these functions). |
I think this should be decided soon by polling: A) Leave as is
B) Remove VarArgs, but leave in #type-style variable references
C) Remove VarArgs and #type-style variable references, i.e. only a simple uninterpreted string is passed
|
The difference between B) and C) is that the message cannot contain place holders with the value references any more, right? This would require that all FMUs know the name of the variable to create human readable messages. One of the early design rationales was that use an external modelDescription.xml to "lighten" the FMU and it must not know details about the variables, such as names. Are we giving up on that? Why? Or did I miss something in the arguments? |
Yes, that would be the difference between B) and C). The problem with the current approach is that a VR does not uniquely identify a variable name to print due to aliasing (see my comments above from 12. June):
Since the vrs will now be unique across types, the vr place holder mechanism will require a redesign in any case, so if that design rationale is still taken to be worth the effort, we should desing a replacement, or we should do away with the current one. Personally I'd rather have the knowledge which variable names to use in the FMU than the environment, but if it is deemed worthwhile to split that knowledge from the FMU, I'd give this rationale in the document. |
No more poll needed. |
Reported by tsommer on 6 Jun 2018 08:09 UTC
Currently it is not possible to call or implement functions with a variable number of arguments in languages
and libraries that bind to functions in shared libraries dynamically like Java Native Access,
Python ctypes and .NET P/Invoke.
In order to allow these platforms to fully support the FMI API, I suggest to remove all variable arguments lists from the C-API.
Currently variable arguments are only used in one callback function (fmi2FunctionTypes.h, line 124):
The same result can be achieved by formatting the message string using sprintf() in the FMU and passing it to the callback as a single argument.
Migrated-From: https://trac.fmi-standard.org/ticket/435
The text was updated successfully, but these errors were encountered: