From 958843c32b7a29741f2e45996b5b3e89f9e108b0 Mon Sep 17 00:00:00 2001
From: emaste <emaste@FreeBSD.org>
Date: Wed, 19 Mar 2014 13:11:35 +0000
Subject: MFC r258054: Update LLDB to upstream r194122 snapshot

  Inludes minor changes relative to upstream, for compatibility with
  FreeBSD's in-tree LLVM 3.3:

  - Reverted LLDB r191806, restoring use of previous API.
  - Reverted part of LLDB r189317, restoring previous enum names.
  - Work around missing LLVM r192504, using previous registerEHFrames API
    (limited functionality).
  - Removed PlatformWindows header include and init/terminate calls.

Sponsored by:	DARPA, AFRL
---
 .../lldb/source/Interpreter/PythonDataObjects.cpp  | 60 +++++++++++++++-------
 1 file changed, 42 insertions(+), 18 deletions(-)

(limited to 'contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp')

diff --git a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp
index 2a1f348..da4e085 100644
--- a/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp
+++ b/contrib/llvm/tools/lldb/source/Interpreter/PythonDataObjects.cpp
@@ -93,18 +93,22 @@ PythonObject::Str ()
 //----------------------------------------------------------------------
 
 PythonString::PythonString (PyObject *py_obj) :
-    PythonObject(py_obj)
+    PythonObject()
 {
+    Reset(py_obj); // Use "Reset()" to ensure that py_obj is a string
 }
 
 PythonString::PythonString (const PythonObject &object) :
-    PythonObject(object.GetPythonObject())
+    PythonObject()
 {
+    Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a string
 }
 
 PythonString::PythonString (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
-    PythonObject (script_object_sp)
+    PythonObject()
 {
+    if (script_object_sp)
+        Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string
 }
 
 PythonString::PythonString (const char* string) :
@@ -158,23 +162,28 @@ PythonString::SetString (const char* string)
 //----------------------------------------------------------------------
 
 PythonInteger::PythonInteger (PyObject *py_obj) :
-    PythonObject(py_obj)
+    PythonObject()
 {
+    Reset(py_obj); // Use "Reset()" to ensure that py_obj is a integer type
 }
 
 PythonInteger::PythonInteger (const PythonObject &object) :
-    PythonObject(object.GetPythonObject())
+    PythonObject()
 {
+    Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a integer type
 }
 
 PythonInteger::PythonInteger (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
-    PythonObject (script_object_sp)
+    PythonObject()
 {
+    if (script_object_sp)
+        Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a string
 }
 
 PythonInteger::PythonInteger (int64_t value) :
-    PythonObject(PyInt_FromLong(value))
+    PythonObject()
 {
+    SetInteger (value);
 }
 
 
@@ -185,8 +194,11 @@ PythonInteger::~PythonInteger ()
 bool
 PythonInteger::Reset (PyObject *py_obj)
 {
-    if (py_obj && PyInt_Check(py_obj))
-        return PythonObject::Reset(py_obj);
+    if (py_obj)
+    {
+        if (PyInt_Check (py_obj) || PyLong_Check(py_obj))
+            return PythonObject::Reset(py_obj);
+    }
     
     PythonObject::Reset(NULL);
     return py_obj == NULL;
@@ -196,15 +208,19 @@ int64_t
 PythonInteger::GetInteger()
 {
     if (m_py_obj)
-        return PyInt_AsLong(m_py_obj);
-    else
-        return UINT64_MAX;
+    {
+        if (PyInt_Check(m_py_obj))
+            return PyInt_AsLong(m_py_obj);
+        else if (PyLong_Check(m_py_obj))
+            return PyLong_AsLongLong(m_py_obj);
+    }
+    return UINT64_MAX;
 }
 
 void
 PythonInteger::SetInteger (int64_t value)
 {
-    PythonObject::Reset(PyInt_FromLong(value));
+    PythonObject::Reset(PyLong_FromLongLong(value));
 }
 
 //----------------------------------------------------------------------
@@ -222,19 +238,23 @@ PythonList::PythonList (uint32_t count) :
 }
 
 PythonList::PythonList (PyObject *py_obj) :
-    PythonObject(py_obj)
+    PythonObject()
 {
+    Reset(py_obj); // Use "Reset()" to ensure that py_obj is a list
 }
 
 
 PythonList::PythonList (const PythonObject &object) :
-    PythonObject(object.GetPythonObject())
+    PythonObject()
 {
+    Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a list
 }
 
 PythonList::PythonList (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
-    PythonObject (script_object_sp)
+    PythonObject()
 {
+    if (script_object_sp)
+        Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a list
 }
 
 PythonList::~PythonList ()
@@ -293,17 +313,21 @@ PythonDictionary::PythonDictionary () :
 PythonDictionary::PythonDictionary (PyObject *py_obj) :
     PythonObject(py_obj)
 {
+    Reset(py_obj); // Use "Reset()" to ensure that py_obj is a dictionary
 }
 
 
 PythonDictionary::PythonDictionary (const PythonObject &object) :
-    PythonObject(object.GetPythonObject())
+    PythonObject()
 {
+    Reset(object.GetPythonObject()); // Use "Reset()" to ensure that py_obj is a dictionary
 }
 
 PythonDictionary::PythonDictionary (const lldb::ScriptInterpreterObjectSP &script_object_sp) :
-    PythonObject (script_object_sp)
+    PythonObject ()
 {
+    if (script_object_sp)
+        Reset((PyObject *)script_object_sp->GetObject()); // Use "Reset()" to ensure that py_obj is a dictionary
 }
 
 PythonDictionary::~PythonDictionary ()
-- 
cgit v1.1