File: PWOImp.cpp

package info (click to toggle)
metakit 2.4.3-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 6,468 kB
  • ctags: 3,548
  • sloc: xml: 29,455; cpp: 23,339; sh: 9,051; tcl: 1,195; python: 577; makefile: 254; ansic: 14
file content (60 lines) | stat: -rwxr-xr-x 1,657 bytes parent folder | download
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
/******************************************** 
  copyright 1999 McMillan Enterprises, Inc.
  www.mcmillan-inc.com
*********************************************/
#include "PWOSequence.h"
#include "PWOMSequence.h"
#include "PWOMapping.h"
#include "PWOCallable.h"

  // incref new owner, and decref old owner, and adjust to new owner
void PWOBase::GrabRef(PyObject* newObj)
{
    // be careful to incref before decref if old is same as new
  Py_XINCREF(newObj);
  Py_XDECREF(_own);
  _own = _obj = newObj;
}

PWOTuple::PWOTuple(const PWOList& list)
  : PWOSequence (PyList_AsTuple(list)) { LoseRef(_obj); }

PWOListMmbr::PWOListMmbr(PyObject* obj, PWOList& parent, int ndx) 
  : PWOBase(obj), _parent(parent), _ndx(ndx) { }

PWOListMmbr& PWOListMmbr::operator=(const PWOBase& other) {
  GrabRef(other);
  //Py_XINCREF(_obj); // this one is for setItem to steal
  _parent.setItem(_ndx, *this);
  return *this;
}
PWOMappingMmbr& PWOMappingMmbr::operator=(const PWOBase& other) {
  GrabRef(other);
  _parent.setItem(_key, *this);
  return *this;
}
PWOBase PWOCallable::call() const {
  static PWOTuple _empty;
  PyObject *rslt = PyEval_CallObjectWithKeywords(*this, _empty, NULL);
  if (rslt == 0)
    throw 1;
  return rslt;
}
PWOBase PWOCallable::call(PWOTuple& args) const {
  PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, NULL);
  if (rslt == 0)
    throw 1;
  return rslt;
}
PWOBase PWOCallable::call(PWOTuple& args, PWOMapping& kws) const {
  PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, kws);
  if (rslt == 0)
    throw 1;
  return rslt;
}

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