@@ -690,6 +690,44 @@ typedef struct pmix_byte_object {
690690} pmix_byte_object_t ;
691691
692692
693+ /**** PMIX DATA BUFFER ****/
694+ typedef struct pmix_data_buffer {
695+ /** Start of my memory */
696+ char * base_ptr ;
697+ /** Where the next data will be packed to (within the allocated
698+ memory starting at base_ptr) */
699+ char * pack_ptr ;
700+ /** Where the next data will be unpacked from (within the
701+ allocated memory starting as base_ptr) */
702+ char * unpack_ptr ;
703+ /** Number of bytes allocated (starting at base_ptr) */
704+ size_t bytes_allocated ;
705+ /** Number of bytes used by the buffer (i.e., amount of data --
706+ including overhead -- packed in the buffer) */
707+ size_t bytes_used ;
708+ } pmix_data_buffer_t ;
709+ #define PMIX_DATA_BUFFER_CREATE (m ) \
710+ do { \
711+ (m) = (pmix_data_buffer_t*)calloc(1, sizeof(pmix_data_buffer_t)); \
712+ } while (0)
713+ #define PMIX_DATA_BUFFER_RELEASE (m ) \
714+ do { \
715+ if (NULL != (m)->base_ptr) { \
716+ free((m)->base_ptr); \
717+ } \
718+ free((m)); \
719+ (m) = NULL; \
720+ } while (0)
721+ #define PMIX_DATA_BUFFER_CONSTRUCT (m ) \
722+ memset((m), 0, sizeof(pmix_data_buffer_t))
723+ #define PMIX_DATA_BUFFER_DESTRUCT (m ) \
724+ do { \
725+ if (NULL != (m)->base_ptr) { \
726+ free((m)->base_ptr); \
727+ } \
728+ } while (0)
729+
730+
693731/**** PMIX PROC OBJECT ****/
694732typedef struct pmix_proc {
695733 char nspace [PMIX_MAX_NSLEN + 1 ];
@@ -700,9 +738,10 @@ typedef struct pmix_proc {
700738 (m) = (pmix_proc_t*)calloc((n) , sizeof(pmix_proc_t)); \
701739 } while (0)
702740
703- #define PMIX_PROC_RELEASE (m ) \
704- do { \
705- PMIX_PROC_FREE((m)); \
741+ #define PMIX_PROC_RELEASE (m ) \
742+ do { \
743+ free((m)); \
744+ (m) = NULL; \
706745 } while (0)
707746
708747#define PMIX_PROC_CONSTRUCT (m ) \
@@ -957,7 +996,6 @@ pmix_status_t pmix_setenv(const char *name, const char *value,
957996#define PMIX_SETENV (a , b , c ) \
958997 pmix_setenv((a), (b), true, (c))
959998
960-
961999/**** PMIX INFO STRUCT ****/
9621000struct pmix_info_t {
9631001 char key [PMIX_MAX_KEYLEN + 1 ]; // ensure room for the NULL terminator
@@ -1492,6 +1530,209 @@ pmix_status_t PMIx_Store_internal(const pmix_proc_t *proc,
14921530 const char * key , pmix_value_t * val );
14931531
14941532
1533+ /**
1534+ * Top-level interface function to pack one or more values into a
1535+ * buffer.
1536+ *
1537+ * The pack function packs one or more values of a specified type into
1538+ * the specified buffer. The buffer must have already been
1539+ * initialized via the PMIX_DATA_BUFFER_CREATE or PMIX_DATA_BUFFER_CONSTRUCT
1540+ * call - otherwise, the pack_value function will return an error.
1541+ * Providing an unsupported type flag will likewise be reported as an error.
1542+ *
1543+ * Note that any data to be packed that is not hard type cast (i.e.,
1544+ * not type cast to a specific size) may lose precision when unpacked
1545+ * by a non-homogeneous recipient. The PACK function will do its best to deal
1546+ * with heterogeneity issues between the packer and unpacker in such
1547+ * cases. Sending a number larger than can be handled by the recipient
1548+ * will return an error code (generated upon unpacking) -
1549+ * the error cannot be detected during packing.
1550+ *
1551+ * @param *buffer A pointer to the buffer into which the value is to
1552+ * be packed.
1553+ *
1554+ * @param *src A void* pointer to the data that is to be packed. Note
1555+ * that strings are to be passed as (char **) - i.e., the caller must
1556+ * pass the address of the pointer to the string as the void*. This
1557+ * allows PMIx to use a single pack function, but still allow
1558+ * the caller to pass multiple strings in a single call.
1559+ *
1560+ * @param num_values An int32_t indicating the number of values that are
1561+ * to be packed, beginning at the location pointed to by src. A string
1562+ * value is counted as a single value regardless of length. The values
1563+ * must be contiguous in memory. Arrays of pointers (e.g., string
1564+ * arrays) should be contiguous, although (obviously) the data pointed
1565+ * to need not be contiguous across array entries.
1566+ *
1567+ * @param type The type of the data to be packed - must be one of the
1568+ * PMIX defined data types.
1569+ *
1570+ * @retval PMIX_SUCCESS The data was packed as requested.
1571+ *
1572+ * @retval PMIX_ERROR(s) An appropriate PMIX error code indicating the
1573+ * problem encountered. This error code should be handled
1574+ * appropriately.
1575+ *
1576+ * @code
1577+ * pmix_data_buffer_t *buffer;
1578+ * int32_t src;
1579+ *
1580+ * PMIX_DATA_BUFFER_CREATE(buffer);
1581+ * status_code = PMIx_Data_pack(buffer, &src, 1, PMIX_INT32);
1582+ * @endcode
1583+ */
1584+ pmix_status_t PMIx_Data_pack (pmix_data_buffer_t * buffer ,
1585+ void * src , int32_t num_vals ,
1586+ pmix_data_type_t type );
1587+
1588+ /**
1589+ * Unpack values from a buffer.
1590+ *
1591+ * The unpack function unpacks the next value (or values) of a
1592+ * specified type from the specified buffer.
1593+ *
1594+ * The buffer must have already been initialized via an PMIX_DATA_BUFFER_CREATE or
1595+ * PMIX_DATA_BUFFER_CONSTRUCT call (and assumedly filled with some data) -
1596+ * otherwise, the unpack_value function will return an
1597+ * error. Providing an unsupported type flag will likewise be reported
1598+ * as an error, as will specifying a data type that DOES NOT match the
1599+ * type of the next item in the buffer. An attempt to read beyond the
1600+ * end of the stored data held in the buffer will also return an
1601+ * error.
1602+ *
1603+ * NOTE: it is possible for the buffer to be corrupted and that
1604+ * PMIx will *think* there is a proper variable type at the
1605+ * beginning of an unpack region - but that the value is bogus (e.g., just
1606+ * a byte field in a string array that so happens to have a value that
1607+ * matches the specified data type flag). Therefore, the data type error check
1608+ * is NOT completely safe. This is true for ALL unpack functions.
1609+ *
1610+ *
1611+ * Unpacking values is a "nondestructive" process - i.e., the values are
1612+ * not removed from the buffer. It is therefore possible for the caller
1613+ * to re-unpack a value from the same buffer by resetting the unpack_ptr.
1614+ *
1615+ * Warning: The caller is responsible for providing adequate memory
1616+ * storage for the requested data. As noted below, the user
1617+ * must provide a parameter indicating the maximum number of values that
1618+ * can be unpacked into the allocated memory. If more values exist in the
1619+ * buffer than can fit into the memory storage, then the function will unpack
1620+ * what it can fit into that location and return an error code indicating
1621+ * that the buffer was only partially unpacked.
1622+ *
1623+ * Note that any data that was not hard type cast (i.e., not type cast
1624+ * to a specific size) when packed may lose precision when unpacked by
1625+ * a non-homogeneous recipient. PMIx will do its best to deal with
1626+ * heterogeneity issues between the packer and unpacker in such
1627+ * cases. Sending a number larger than can be handled by the recipient
1628+ * will return an error code generated upon unpacking - these errors
1629+ * cannot be detected during packing.
1630+ *
1631+ * @param *buffer A pointer to the buffer from which the value will be
1632+ * extracted.
1633+ *
1634+ * @param *dest A void* pointer to the memory location into which the
1635+ * data is to be stored. Note that these values will be stored
1636+ * contiguously in memory. For strings, this pointer must be to (char
1637+ * **) to provide a means of supporting multiple string
1638+ * operations. The unpack function will allocate memory for each
1639+ * string in the array - the caller must only provide adequate memory
1640+ * for the array of pointers.
1641+ *
1642+ * @param type The type of the data to be unpacked - must be one of
1643+ * the BFROP defined data types.
1644+ *
1645+ * @retval *max_num_values The number of values actually unpacked. In
1646+ * most cases, this should match the maximum number provided in the
1647+ * parameters - but in no case will it exceed the value of this
1648+ * parameter. Note that if you unpack fewer values than are actually
1649+ * available, the buffer will be in an unpackable state - the function will
1650+ * return an error code to warn of this condition.
1651+ *
1652+ * @note The unpack function will return the actual number of values
1653+ * unpacked in this location.
1654+ *
1655+ * @retval PMIX_SUCCESS The next item in the buffer was successfully
1656+ * unpacked.
1657+ *
1658+ * @retval PMIX_ERROR(s) The unpack function returns an error code
1659+ * under one of several conditions: (a) the number of values in the
1660+ * item exceeds the max num provided by the caller; (b) the type of
1661+ * the next item in the buffer does not match the type specified by
1662+ * the caller; or (c) the unpack failed due to either an error in the
1663+ * buffer or an attempt to read past the end of the buffer.
1664+ *
1665+ * @code
1666+ * pmix_data_buffer_t *buffer;
1667+ * int32_t dest;
1668+ * char **string_array;
1669+ * int32_t num_values;
1670+ *
1671+ * num_values = 1;
1672+ * status_code = PMIx_Data_unpack(buffer, (void*)&dest, &num_values, PMIX_INT32);
1673+ *
1674+ * num_values = 5;
1675+ * string_array = malloc(num_values*sizeof(char *));
1676+ * status_code = PMIx_Data_unpack(buffer, (void*)(string_array), &num_values, PMIX_STRING);
1677+ *
1678+ * @endcode
1679+ */
1680+ pmix_status_t PMIx_Data_unpack (pmix_data_buffer_t * buffer , void * dest ,
1681+ int32_t * max_num_values ,
1682+ pmix_data_type_t type );
1683+
1684+ /**
1685+ * Copy a data value from one location to another.
1686+ *
1687+ * Since registered data types can be complex structures, the system
1688+ * needs some way to know how to copy the data from one location to
1689+ * another (e.g., for storage in the registry). This function, which
1690+ * can call other copy functions to build up complex data types, defines
1691+ * the method for making a copy of the specified data type.
1692+ *
1693+ * @param **dest The address of a pointer into which the
1694+ * address of the resulting data is to be stored.
1695+ *
1696+ * @param *src A pointer to the memory location from which the
1697+ * data is to be copied.
1698+ *
1699+ * @param type The type of the data to be copied - must be one of
1700+ * the PMIx defined data types.
1701+ *
1702+ * @retval PMIX_SUCCESS The value was successfully copied.
1703+ *
1704+ * @retval PMIX_ERROR(s) An appropriate error code.
1705+ *
1706+ */
1707+ pmix_status_t PMIx_Data_copy (void * * dest , void * src , pmix_data_type_t type );
1708+
1709+ /**
1710+ * Print a data value.
1711+ *
1712+ * Since registered data types can be complex structures, the system
1713+ * needs some way to know how to print them (i.e., convert them to a string
1714+ * representation). Provided for debug purposes.
1715+ *
1716+ * @retval PMIX_SUCCESS The value was successfully printed.
1717+ *
1718+ * @retval PMIX_ERROR(s) An appropriate error code.
1719+ */
1720+ pmix_status_t PMIx_Data_print (char * * output , char * prefix ,
1721+ void * src , pmix_data_type_t type );
1722+
1723+ /**
1724+ * Copy a payload from one buffer to another
1725+ *
1726+ * This function will append a copy of the payload in one buffer into
1727+ * another buffer.
1728+ * NOTE: This is NOT a destructive procedure - the
1729+ * source buffer's payload will remain intact, as will any pre-existing
1730+ * payload in the destination's buffer.
1731+ */
1732+ pmix_status_t PMIx_Data_copy_payload (pmix_data_buffer_t * dest ,
1733+ pmix_data_buffer_t * src );
1734+
1735+
14951736/* Key-Value pair management macros */
14961737// TODO: add all possible types/fields here.
14971738
0 commit comments