File: weave_imp.cpp

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (69 lines) | stat: -rw-r--r-- 2,196 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/******************************************** 
  copyright 1999 McMillan Enterprises, Inc.
  www.mcmillan-inc.com

  modified for weave by eric jones.
*********************************************/
#include "object.h"

using namespace py;

//---------------------------------------------------------------------------
// object
//
// !! Wish I knew how to get these defined inline in object.h...
//---------------------------------------------------------------------------

object::keyed_ref object::operator [] (object& key) {
  object rslt = PyObject_GetItem(_obj, key);
  lose_ref(rslt);
  if (!(PyObject*)rslt)
  {
    // don't throw error for when [] fails because it might be on left hand 
    // side (a[0] = 1).  If the obj was just created, it will be filled 
    // with NULL values, and setting the values should be ok.  However, we
    // do want to catch index errors that might occur on the right hand side
    // (obj = a[4] when a has len==3).
      if (PyErr_ExceptionMatches(PyExc_KeyError))
           PyErr_Clear(); // Ignore key errors
      else if (PyErr_ExceptionMatches(PyExc_IndexError))
        throw 1;
  }
  return object::keyed_ref(rslt, *this, key);
};
object::keyed_ref object::operator [] (const char* key) {
  object _key = object(key);
  return operator[](_key);
};
object::keyed_ref object::operator [] (const std::string& key) {
  object _key = object(key);
  return operator [](_key);
};
object::keyed_ref object::operator [] (int key) {
  object _key = object(key);
  return operator [](_key);
};
object::keyed_ref object::operator [] (double key) {
  object _key = object(key);
  return operator [](_key);
};
object::keyed_ref object::operator [] (const std::complex<double>& key) {
  object _key = object(key);
  return operator [](_key);
};

std::ostream& operator <<(std::ostream& os, py::object& obj)
{
    os << obj.repr();
    return os;
}

//---------------------------------------------------------------------------
// Fail method for throwing exceptions with a given message.
//---------------------------------------------------------------------------

void py::fail(PyObject* exc, const char* msg)
{
  PyErr_SetString(exc, msg);
  throw 1;
}