[Jython-checkins] jython: struct.calcsize('P'), a commonly used method of testing whether Python is

nicholas.riley jython-checkins at python.org
Wed Mar 14 21:41:16 CET 2012


http://hg.python.org/jython/rev/fb93b3a083a9
changeset:   6371:fb93b3a083a9
user:        Nicholas Riley <njriley at illinois.edu>
date:        Wed Mar 14 16:40:08 2012 -0400
summary:
  struct.calcsize('P'), a commonly used method of testing whether Python is running 32- or 64-bit.

files:
  src/org/python/modules/struct.java |  20 ++++++++++++++++++
  1 files changed, 20 insertions(+), 0 deletions(-)


diff --git a/src/org/python/modules/struct.java b/src/org/python/modules/struct.java
--- a/src/org/python/modules/struct.java
+++ b/src/org/python/modules/struct.java
@@ -562,7 +562,26 @@
             return Py.newInteger(buf.readByte());
         }
     }
+    
+    static class PointerFormatDef extends FormatDef {
+        FormatDef init(char name) {
+            String dataModel = System.getProperty("sun.arch.data.model");
+            if (dataModel == null)
+                throw Py.NotImplementedError("Can't determine if JVM is 32- or 64-bit");
+            int length = dataModel.equals("64") ? 8 : 4;
+            super.init(name, length, length);
+            return this;
+        }
+        
+        void pack(ByteStream buf, PyObject value) {
+            throw Py.NotImplementedError("Pointer packing/unpacking not implemented in Jython");
+        }
 
+        Object unpack(ByteStream buf) {
+            throw Py.NotImplementedError("Pointer packing/unpacking not implemented in Jython");
+        }
+    }
+    
     static class LEShortFormatDef extends FormatDef {
         void pack(ByteStream buf, PyObject value) {
             int v = get_int(value);
@@ -876,6 +895,7 @@
         new BEUnsignedLongFormatDef()   .init('Q', 8, 8),
         new BEFloatFormatDef()          .init('f', 4, 4),
         new BEDoubleFormatDef()         .init('d', 8, 8),
+        new PointerFormatDef()          .init('P')
     };
 
 

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list