Skip to content

Commit

Permalink
Updated writingmodules.rst - replaced fetch_data by the new func (#2071)
Browse files Browse the repository at this point in the history
  • Loading branch information
vojone committed Apr 30, 2024
1 parent 1be9811 commit adf3dde
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions docs/writingmodules.rst
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ checks in your code nevertheless). In those cases you can use the
block = first_memory_block(context);
if (block != NULL)
{
block_data = block->fetch_data(block)
block_data = yr_fetch_block_data(block)
if (block_data != NULL)
{
Expand All @@ -668,23 +668,23 @@ checks in your code nevertheless). In those cases you can use the
}
}
In the previous example you can also see how to use the ``fetch_data`` function.
This function, which is a member of the ``YR_MEMORY_BLOCK`` structure, receives
a pointer to the same block (as a ``self`` or ``this`` pointer) and returns a
pointer to the block's data. Your module doesn't own the memory pointed to by
this pointer, freeing that memory is not your responsibility. However keep in
mind that the pointer is valid only until you ask for the next memory block. As
long as you use the pointer within the scope of a ``foreach_memory_block`` you
are on the safe side. Also take into account that ``fetch_data`` can return a
NULL pointer, your code must be prepared for that case.
In the previous example you can also see how to use the ``yr_fetch_block_data``
function. This function receives a pointer to the same block (as a ``self`` or
``this`` pointer) and returns a pointer to the block's data. Your module
doesn't own the memory pointed to by this pointer, freeing that memory is not
your responsibility. However keep in mind that the pointer is valid only until
you ask for the next memory block. As long as you use the pointer within the
scope of a ``foreach_memory_block`` you are on the safe side. Also take into
account that ``yr_fetch_block_data`` can return a NULL pointer, your code must
be prepared for that case.

.. code-block:: c
const uint8_t* block_data;
foreach_memory_block(context, block)
{
block_data = block->fetch_data(block);
block_data = yr_fetch_block_data(block);
if (block_data != NULL)
{
Expand Down

0 comments on commit adf3dde

Please sign in to comment.