@@ -1309,10 +1309,37 @@ static inline term term_create_uninitialized_intn(size_t n, term_integer_sign_t
13091309 return ((term ) boxed_int ) | TERM_PRIMARY_BOXED ;
13101310}
13111311
1312- static inline void * term_intn_data (term t )
1312+ /**
1313+ * @brief Initialize multi-precision integer data in a pre-allocated term
1314+ *
1315+ * Copies multi-precision integer digits into an already allocated boxed term,
1316+ * zero-extending to fill the entire allocated space. This function is used
1317+ * after creating an uninitialized bigint term to populate it with actual data.
1318+ *
1319+ * @param t Uninitialized bigint term (created with \c term_create_uninitialized_intn())
1320+ * @param bigint Source digit array to copy
1321+ * @param bigint_len Number of digits in source array
1322+ * @param uninitialized_size Total size of destination buffer in digits
1323+ *
1324+ * @pre t must be a valid uninitialized bigint term
1325+ * @pre bigint != NULL
1326+ * @pre uninitialized_size must match the size allocated for the term
1327+ *
1328+ * @post Copies bigint_len digits from source to term
1329+ * @post Zero-fills remaining space from bigint_len to uninitialized_size
1330+ *
1331+ * @note This function does not set the sign - that should be done when creating the term
1332+ * @note The destination buffer size (uninitialized_size) is typically rounded up for alignment
1333+ *
1334+ * @see term_create_uninitialized_intn() to allocate the term before initialization
1335+ * @see intn_copy() which performs the actual copy and zero-extension
1336+ */
1337+ static inline void term_initialize_bigint (
1338+ term t , const intn_digit_t * bigint , size_t bigint_len , size_t uninitialized_size )
13131339{
13141340 const term * boxed_value = term_to_const_term_ptr (t );
1315- return (void * ) (boxed_value + 1 );
1341+ intn_digit_t * dest_buf = (intn_digit_t * ) (boxed_value + 1 );
1342+ intn_copy (bigint , bigint_len , dest_buf , uninitialized_size );
13161343}
13171344
13181345static inline void term_intn_to_term_size (size_t n , size_t * intn_data_size , size_t * rounded_num_len )
@@ -1404,9 +1431,9 @@ _Static_assert(
14041431static inline void term_to_bigint (
14051432 term t , const intn_digit_t * bigint [], size_t * bigint_len , intn_integer_sign_t * bigint_sign )
14061433{
1407- * bigint = (const intn_digit_t * ) term_intn_data (t );
1408-
14091434 const term * boxed_value = term_to_const_term_ptr (t );
1435+ * bigint = (const intn_digit_t * ) (boxed_value + 1 );
1436+
14101437 size_t boxed_size = term_get_size_from_boxed_header (boxed_value [0 ]);
14111438 * bigint_len = boxed_size * (sizeof (term ) / sizeof (intn_digit_t ));
14121439
0 commit comments