gdb
[deliverable/binutils-gdb.git] / gdb / python / py-value.c
index 714aa1180055c8b5d324e9a8c6fa17c5eb77ae13..e2ae0baddc7395bf610f4b5162c6399c0ac47ab4 100644 (file)
@@ -238,6 +238,7 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
   const char *errors = NULL;
   const char *user_encoding = NULL;
   const char *la_encoding = NULL;
+  struct type *char_type;
   static char *keywords[] = { "encoding", "errors", "length" };
 
   if (!PyArg_ParseTupleAndKeywords (args, kw, "|ssi", keywords,
@@ -246,12 +247,13 @@ valpy_string (PyObject *self, PyObject *args, PyObject *kw)
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      LA_GET_STRING (value, &buffer, &length, &la_encoding);
+      LA_GET_STRING (value, &buffer, &length, &char_type, &la_encoding);
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
   encoding = (user_encoding && *user_encoding) ? user_encoding : la_encoding;
-  unicode = PyUnicode_Decode (buffer, length, encoding, errors);
+  unicode = PyUnicode_Decode (buffer, length * TYPE_LENGTH (char_type),
+                             encoding, errors);
   xfree (buffer);
 
   return unicode;
@@ -784,6 +786,13 @@ valpy_int (PyObject *self)
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
+#ifdef HAVE_LONG_LONG          /* Defined by Python.  */
+  /* If we have 'long long', and the value overflows a 'long', use a
+     Python Long; otherwise use a Python Int.  */
+  if (sizeof (l) > sizeof (long) && (l > PyInt_GetMax ()
+                                    || l < (- (LONGEST) PyInt_GetMax ()) - 1))
+    return PyLong_FromLongLong (l);
+#endif
   return PyInt_FromLong (l);
 }
 
@@ -808,7 +817,11 @@ valpy_long (PyObject *self)
     }
   GDB_PY_HANDLE_EXCEPTION (except);
 
+#ifdef HAVE_LONG_LONG          /* Defined by Python.  */
+  return PyLong_FromLongLong (l);
+#else
   return PyLong_FromLong (l);
+#endif
 }
 
 /* Implements conversion to float.  */
This page took 0.024542 seconds and 4 git commands to generate.