Skip to content

Commit b57fb5c

Browse files
committed
Convert the PMIX_VALUE_GET_NUMBER macro to a function
Converting this macro to a PMIx_Value_get_number function requires a signature change - it is no longer possible to pass the C datatype for casting the result. Instead, we now pass the PMIx datatype that corresponds to the desired C casting. We also extend the function to return a new PMIX_ERR_LOST_PRECISION status when the casting can potentially cause a loss of precision - e.g., when changing from a "float" to an "int" - and a new PMIX_ERR_CHANGE_SIGN status when the casting would cause a change in sign - e.g., when changing from a negative integer to a "size_t". Signed-off-by: Ralph Castain <[email protected]>
1 parent 40c1b3f commit b57fb5c

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

Chap_API_Struct.tex

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,13 @@ \subsection{PMIx Return Status Constants}
198198
\declareconstitemvalue{PMIX_ERR_PARTIAL_SUCCESS}{-52}
199199
The operation is considered successful but not all elements of the operation were concluded (e.g., some members of a group construct operation chose not to participate).
200200
%
201+
\declareconstitemvalueProvisional{PMIX_ERR_LOST_PRECISION}{-400}
202+
The returned value is of a data type that may have lost precision when converted from the original value - e.g., when converting a \code{float} to an \code{int}.
203+
%
204+
\declareconstitemvalueProvisional{PMIX_ERR_CHANGE_SIGN}{-401}
205+
The returned value is of a data type that would cause a change in sign when converted from the original value - e.g., when converting a negative integer to a \code{size_t}.
206+
%
207+
201208
\end{constantdesc}
202209

203210

@@ -1168,26 +1175,38 @@ \subsubsection{Value structure support}
11681175

11691176
%%%%%%%%%%%
11701177
\littleheader{Retrieve a numerical value from a value struct}
1171-
\declaremacro{PMIX_VALUE_GET_NUMBER}
1178+
\declareapiProvisional{PMIx_Value_get_number}
11721179

11731180
Retrieve a numerical value from a \refstruct{pmix_value_t} structure.
11741181

1175-
\copySignature{PMIX_VALUE_GET_NUMBER}{3.0}{
1176-
PMIX_VALUE_GET_NUMBER(s, m, n, t)
1182+
\copySignature{PMIx_Value_get_number}{6.0}{
1183+
pmix_status_t \\
1184+
PMIx_Value_get_number(pmix_value_t *m,
1185+
\hspace*{24\sigspace}void *d,
1186+
\hspace*{24\sigspace}pmix_data_type_t t);
11771187
}
11781188

11791189
\begin{arglist}
1180-
\argout{s}{Status code for the request (\refstruct{pmix_status_t})}
11811190
\argin{m}{Pointer to the\refstruct{pmix_value_t} structure (handle)}
1182-
\argout{n}{Variable to be set to the value}
1183-
\argin{t}{Type of number to be returned in \refarg{m} (\code{C data type})}
1191+
\argout{d}{Pointer to the variable to be set to the value (\code{void*})}
1192+
\argin{t}{Type of number to be returned in \refarg{d} (\refstruct{pmix_data_type_t})}
11841193
\end{arglist}
11851194

1186-
Sets the provided variable equal to the numerical value contained in the given \refstruct{pmix_value_t}, returning success if the data type of the value is a recognized numerical type - the \refconst{PMIX_ERR_BAD_PARAM} error is
1187-
returned if the value contains a non-numerical type. The returned value is type cast to the
1188-
provided C-language data type. It is therefore possible to lose precision - e.g., if the \refstruct{pmix_value_t}
1189-
contains a \refconst{PMIX_FLOAT} and the macro invocation requests that the returned value be type cast to an
1190-
\code{int}.
1195+
Sets the destination variable equal to the numerical value contained in the given \refstruct{pmix_value_t}.
1196+
The \refconst{PMIX_ERR_BAD_PARAM} error is returned if the \refstruct{pmix_value_t} contains a non-numerical
1197+
type. If the destination type (as provided in the \refarg{t} parameter) matches that of the value, then
1198+
the value is simply transferred across.
1199+
1200+
If transfer of the value to the destination would result in a loss of precision - e.g., if the \refstruct{pmix_value_t}
1201+
contains a \refconst{PMIX_FLOAT} and the function invocation passes an
1202+
\code{int} for the destination, the value will not be transferred and the returned status will be \refconst{PMIX_ERR_LOST_PRECISION}.
1203+
1204+
If the transfer could result in a change in sign - e.g., if the \refstruct{pmix_value_t} contains a negative
1205+
integer while the function invocation passes a \code{size_t} for the destination, value will not be
1206+
transferred and the returned status will be \refconst{PMIX_ERR_CHANGE_SIGN}.
1207+
1208+
In all other cases (e.g., the value contains a \code{uint8_t} while the destination is a \code{uint16_t}), the value will
1209+
be transferred to the destination and a \refconst{PMIX_SUCCESS} status will be returned.
11911210

11921211
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11931212
\subsection{Info Structure}

Chap_Revisions.tex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,8 +1632,9 @@ \subsection{Added Macros (Provisional)}
16321632

16331633
\subsection{Added Constants (Provisional)}
16341634

1635-
%\begin{compactitemize}
1636-
%\end{compactitemize}
1635+
\begin{compactitemize}
1636+
\item \refconst{PMIX_ERR_LOST_PRECISION}
1637+
\end{compactitemize}
16371638

16381639
\subsection{Added Attributes}
16391640

@@ -1702,6 +1703,7 @@ \subsection{Added Functions (Provisional)}
17021703
\item \refapi{PMIx_Value_destruct}
17031704
\item \refapi{PMIx_Value_create}
17041705
\item \refapi{PMIx_Value_free}
1706+
\item \refapi{PMIx_Value_get_number}
17051707
\item \refapi{PMIx_Info_construct}
17061708
\item \refapi{PMIx_Info_destruct}
17071709
\item \refapi{PMIx_Info_create}
@@ -1810,15 +1812,18 @@ \subsection{Added Attributes (Provisional)}
18101812

18111813
\subsection{Deprecated constants}
18121814

1813-
The following constants were deprecated in v5.1:
1815+
The following constants were deprecated in v6.0:
18141816

18151817
\subsection{Deprecated attributes}
18161818

1817-
The following attributes were deprecated in v5.1:
1819+
The following attributes were deprecated in v6.0:
18181820

18191821
\subsection{Deprecated macros}
18201822

1821-
The following macros were deprecated in v5.1:
1823+
The following macros were deprecated in v6.0:
1824+
1825+
\declaremacroDEP{PMIX_VALUE_GET_NUMBER} Replaced by the \refapi{PMIx_Value_get_number} \ac{API}. Note that this also
1826+
includes a signature change, and a change in returned value.
18221827

18231828
\subsection{Removed attributes}
18241829

0 commit comments

Comments
 (0)