Skip to contentSkip to conversation

exec: don't use void* in pointer arithmetic in headers

PATCH Applied Roman Kiryanov 3 participants 4 messages Jun 20, 2024 – Jun 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 exec: don't use void* in pointer arithmetic in headers

void* pointer arithmetic is a GCC extentension
which could not be available in other build
tools (e.g. C++). This changes removes this
assumption.

Google-Bug-Id: 331190993

Change-Id I5a064853429f627c17a9213910811dea4ced6174

---
v2: renamed from "use char* for pointer arithmetic"
and removed all explicit extra cast with one typedef in memory.h.

 include/exec/memory.h | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
include/exec/memory.h +3 -1
index b1713f30b8..b616338f05 100644
@@ -2795,8 +2795,10 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,
 #define ARG1_DECL    AddressSpace *as
 #include "exec/memory_ldst_phys.h.inc"
 
+typedef uint8_t *MemoryRegionCachePtr;
+
 struct MemoryRegionCache {
-    void *ptr;
+    MemoryRegionCachePtr ptr;
     hwaddr xlat;
     hwaddr len;
     FlatView *fv;
Signature · 1 line
2.45.2.741.gdbec12cfda-goog
#1 lore raw

Hi Roman,

Quoted 6 lines · Roman Kiryanov

void* pointer arithmetic is a GCC extentension
which could not be available in other build
tools (e.g. C++). This changes removes this
assumption.

Google-Bug-Id: 331190993

Again [*] I'm trying to figure what this tag is, no hit on
https://issuetracker.google.com/issues?q=id:331190993; is this useful to commit it in the mainstream repository? So far it is confusing me.

[*] https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 1 line

Change-Id: I5a064853429f627c17a9213910811dea4ced6174

Ditto, not useful.

Per https://lore.kernel.org/qemu-devel/[email protected]/
I wonder if this deserves a:

Quoted 14 lines

---
v2: renamed from "use char* for pointer arithmetic"
and removed all explicit extra cast with one typedef in memory.h.

  include/exec/memory.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
include/exec/memory.h +0 -0
index b1713f30b8..b616338f05 100644

include/exec/memory.h MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr, · line 2799

Quoted 5 lines
include/exec/memory.h +2 -0
@@ -2795,8 +2795,10 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,
  #define ARG1_DECL    AddressSpace *as
  #include "exec/memory_ldst_phys.h.inc"
 
+typedef uint8_t *MemoryRegionCachePtr;
+

What about:

typedef uint8_t UnstructuredData;

include/exec/memory.h MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr, · line 2801

Quoted 3 lines
include/exec/memory.h +1 -1
  struct MemoryRegionCache {
-    void *ptr;
+    MemoryRegionCachePtr ptr;

and:

      UnstructuredData *ptr;

?

Quoted 3 lines
include/exec/memory.h +0 -0
      hwaddr xlat;
      hwaddr len;
      FlatView *fv;
#2 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé

Hi Roman,

Quoted 1 line · Roman Kiryanov

Google-Bug-Id: 331190993

Again [*] I'm trying to figure what this tag is, no hit on
https://issuetracker.google.com/issues?q=id:331190993; is this useful to commit it in the mainstream repository? So far it is confusing me.

Quoted 6 lines

[*]
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 1 line

Change-Id: I5a064853429f627c17a9213910811dea4ced6174

Ditto, not useful.

I am sorry, Philippe, I missed your message. If you prefer us to remove Google specific tags from our commits, we will remove them.

Regards,
Roman.

#3 lore raw
In reply to Roman Kiryanov
Quoted 22 lines · Roman Kiryanov

void* pointer arithmetic is a GCC extentension which could not be available in other build tools (e.g. C++). This changes removes this assumption.

Google-Bug-Id: 331190993

Change-Id I5a064853429f627c17a9213910811dea4ced6174

---
v2: renamed from "use char* for pointer arithmetic"
and removed all explicit extra cast with one typedef in memory.h.

  include/exec/memory.h | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
include/exec/memory.h +0 -0
index b1713f30b8..b616338f05 100644

include/exec/memory.h MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr, · line 2801

Quoted 8 lines
include/exec/memory.h +3 -1
@@ -2795,8 +2795,10 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,
  #define ARG1_DECL    AddressSpace *as
  #include "exec/memory_ldst_phys.h.inc"
 
+typedef uint8_t *MemoryRegionCachePtr;
+
  struct MemoryRegionCache {
-    void *ptr;
+    MemoryRegionCachePtr ptr;

Just "uint8_t *ptr" is enough; thanks for testing that it's enough.

Queued for the next pull request, thanks.

Paolo

Quoted 3 lines
include/exec/memory.h +0 -0
      hwaddr xlat;
      hwaddr len;
      FlatView *fv;