Skip to content

device: fix read/write_memory python bindings#1056

Merged
EmmanuelP merged 2 commits intomainfrom
issue/1055/device-gi-fix
Feb 24, 2026
Merged

device: fix read/write_memory python bindings#1056
EmmanuelP merged 2 commits intomainfrom
issue/1055/device-gi-fix

Conversation

@EmmanuelP
Copy link
Contributor

No description provided.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request fixes Python bindings for device memory read/write operations by introducing GObject Introspection (GI)-friendly wrapper functions. The original arv_device_read_memory and arv_device_write_memory functions require pre-allocated buffers, which is not idiomatic for language bindings. The new arv_device_read_bytes and arv_device_write_bytes functions use GByteArray for automatic memory management, making them suitable for Python and other high-level language bindings.

Changes:

  • Added arv_device_read_bytes and arv_device_write_bytes wrapper functions with (rename-to) annotations for GI bindings
  • Enhanced fake device implementation with error handling and debug tracing for memory operations
  • Added Python test suite to verify the new bindings work correctly

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/arvdevice.h Declares new GI-friendly read_bytes and write_bytes functions
src/arvdevice.c Implements wrapper functions and updates documentation annotations for GI compatibility
src/arvfakedevice.c Adds error handling and debug tracing to fake device memory operations
src/arvdebugprivate.h Adds arv_trace_device macro for device-level trace logging
src/arvcamera.c Adds (get-property device) annotation to arv_camera_get_device
tests/meson.build Registers new Python test file
tests/device.py Tests memory read/write operations through Python bindings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (!success)
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_INVALID_PARAMETER,
"Invalid write at 0x%lx, size %d", address, size);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format specifier issue: Using %lx for a guint64 type is not portable. On 32-bit platforms, long is 32 bits while guint64 is always 64 bits. Use "%" G_GINT64_MODIFIER "x" for hexadecimal format to ensure correct formatting across all platforms.

Copilot uses AI. Check for mistakes.
Comment on lines +188 to +190
buffer = g_new (guint8, size);

success = ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, size, buffer, error);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential overflow: The size parameter is size_t (which can be 64-bit) but it's cast to guint32 when passed to read_memory at line 190. If size is larger than GUINT32_MAX, it will be silently truncated, leading to reading fewer bytes than requested. Consider adding a check: if (size > G_MAXUINT32) { g_set_error(...); return NULL; }

Suggested change
buffer = g_new (guint8, size);
success = ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, size, buffer, error);
if (size > G_MAXUINT32) {
if (error != NULL) {
g_set_error (error,
arv_device_error_quark (),
0,
"Requested read size (%" G_GSIZE_FORMAT ") exceeds maximum supported size (%u)",
size,
G_MAXUINT32);
}
return NULL;
}
buffer = g_new (guint8, size);
success = ARV_DEVICE_GET_CLASS (device)->read_memory (device, address, (guint32) size, buffer, error);

Copilot uses AI. Check for mistakes.
src/arvdevice.c Outdated
*
* Reads @size bytes from the device memory.
*
* Return value: (transfer full): a new [class@Glib.Bytes), %NULL on error
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation error: the return value says "a new [class@Glib.Bytes)" but the function actually returns a GByteArray. The documentation should say "[type@GLib.ByteArray]" instead. Also, there's a mismatched closing parenthesis - it should be a closing bracket.]

Suggested change
* Return value: (transfer full): a new [class@Glib.Bytes), %NULL on error
* Return value: (transfer full): a new [type@GLib.ByteArray], %NULL on error

Copilot uses AI. Check for mistakes.
return arv_fake_camera_read_memory (priv->camera, address, size, buffer);
success = arv_fake_camera_read_memory (priv->camera, address, size, buffer);

arv_trace_device ("Fake device read at address = %ld, size = %d", address, size);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format specifier issue: Using %ld for a guint64 type is not portable. On 32-bit platforms, long is 32 bits while guint64 is always 64 bits. Use G_GUINT64_FORMAT instead to ensure correct formatting across all platforms.

Copilot uses AI. Check for mistakes.

if (!success)
g_set_error (error, ARV_DEVICE_ERROR, ARV_DEVICE_ERROR_INVALID_PARAMETER,
"Invalid read at 0x%lx, size %d", address, size);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format specifier issue: Using %lx for a guint64 type is not portable. On 32-bit platforms, long is 32 bits while guint64 is always 64 bits. Use "%" G_GINT64_MODIFIER "x" for hexadecimal format to ensure correct formatting across all platforms.

Copilot uses AI. Check for mistakes.
ArvFakeDevicePrivate *priv = arv_fake_device_get_instance_private (ARV_FAKE_DEVICE (device));
gboolean success;

arv_trace_device ("Fake device write at address = %ld, size = %d", address, size);
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Format specifier issue: Using %ld for a guint64 type is not portable. On 32-bit platforms, long is 32 bits while guint64 is always 64 bits. Use G_GUINT64_FORMAT instead to ensure correct formatting across all platforms.

Copilot uses AI. Check for mistakes.
@EmmanuelP EmmanuelP force-pushed the issue/1055/device-gi-fix branch from ff42f39 to 63b4ab8 Compare February 24, 2026 21:26
@EmmanuelP EmmanuelP merged commit 128d36d into main Feb 24, 2026
4 of 5 checks passed
@EmmanuelP EmmanuelP deleted the issue/1055/device-gi-fix branch February 24, 2026 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants