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,
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;
}
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);
}
}
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. */