Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update of documentation - added info about yr_fetch_block_data #2071

Merged
merged 1 commit into from
Apr 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading