Function ruby_xmalloc2

Source
pub unsafe extern "C" fn ruby_xmalloc2(
    nelems: size_t,
    elemsiz: size_t,
) -> *mut c_void
Expand description

Identical to ruby_xmalloc(), except it allocates nelems * elemsiz bytes. This is needed because the multiplication could integer overflow. On such situations Ruby does not try to allocate at all but raises Ruby level exceptions instead. If there is no integer overflow the behaviour is exactly the same as ruby_xmalloc(nelems*elemsiz).

§@param[in] nelems Number of elements. @param[in] elemsiz Size of an element. @exception rb_eNoMemError No space left for allocation. @exception rb_eArgError nelems * elemsiz would overflow. @return A valid pointer to an allocated storage instance; which has at least nelems * elemsiz bytes width, with appropriate alignment detected by the underlying malloc() routine. @note It doesn’t return NULL. @note Unlike some malloc() implementations, it allocates something and returns a meaningful value even when nelems or elemsiz or both are zero. @warning The return value shall be invalidated exactly once by either ruby_xfree(), ruby_xrealloc(), or ruby_xrealloc2(). It is a failure to pass it to system free(), because the system and Ruby might or might not share the same malloc() implementation.

Generated by rb-sys for Ruby mri-x86_64-linux-gnu-3.0.2