[libvirt] [libvirt-java] [PATCH 10/65] Fix wrapping of native size_t data type

Claudio Bley cbley at av-test.de
Fri Feb 21 13:42:26 UTC 2014


At Fri, 21 Feb 2014 10:37:36 +0000,
Daniel P. Berrange wrote:
> 
> On Thu, Feb 13, 2014 at 04:22:18PM +0100, Claudio Bley wrote:
> > Libvirt function parameters having type (pointer to) size_t were
> > wrapped via JNA using int, long or even NativeLong. Alas, none of
> > these is actually correct as the size of size_t may be the same as the
> > size of either (unsigned) int, long or even long long on different
> > platforms.
> > 
> > JNA provides the size of a native size_t to us, so using this
> > information we define and use class SizeT and class SizeTByReference for
> > wrapping a native size_t and size_t*, respectively.
> > 
> > Signed-off-by: Claudio Bley <cbley at av-test.de>
> > ---
> >  src/main/java/org/libvirt/Domain.java              |    5 +-
> >  src/main/java/org/libvirt/Secret.java              |   10 ++--
> >  src/main/java/org/libvirt/Stream.java              |    7 ++-
> >  src/main/java/org/libvirt/jna/Libvirt.java         |   14 +++---
> >  src/main/java/org/libvirt/jna/SizeT.java           |   19 ++++++++
> >  .../java/org/libvirt/jna/SizeTByReference.java     |   50 ++++++++++++++++++++
> >  6 files changed, 87 insertions(+), 18 deletions(-)
> >  create mode 100644 src/main/java/org/libvirt/jna/SizeT.java
> >  create mode 100644 src/main/java/org/libvirt/jna/SizeTByReference.java
> 
> ACK

Thanks. I'll squash this in before pushing, since throwing an
IllegalArgumentException is not appropriate here.

------- >8 ----------- 8< -------------------- >8 ----------------- 8< -----------------------------------------------
diff --git a/src/main/java/org/libvirt/jna/SizeTByReference.java b/src/main/java/org/libvirt/jna/SizeTByReference.java
index 474527f..24a4677 100644
--- a/src/main/java/org/libvirt/jna/SizeTByReference.java
+++ b/src/main/java/org/libvirt/jna/SizeTByReference.java
@@ -30,7 +30,7 @@ public final class SizeTByReference extends ByReference {
             p.setLong(0, value);
             break;
         default:
-            throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE);
+            throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE);
         }
     }

@@ -44,7 +44,7 @@ public final class SizeTByReference extends ByReference {
         case 8:
             return p.getLong(0);
         default:
-            throw new IllegalArgumentException("Unsupported size: " + Native.SIZE_T_SIZE);
+            throw new RuntimeException("Unsupported size: " + Native.SIZE_T_SIZE);
         }
     }
 }




More information about the libvir-list mailing list