Commit 49ee07fa authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge branch 'tp_as_number'

parents 76210a33 b679d358
......@@ -321,7 +321,7 @@ NONSTDLIB_SRCS := $(MAIN_SRCS) $(OPTIONAL_SRCS) $(TOOL_SRCS) $(UNITTEST_SRCS)
# all: pyston_dbg pyston_release pyston_oprof pyston_prof $(OPTIONAL_SRCS:.cpp=.o) ext_python ext_pyston
all: pyston_dbg pyston_release pyston_prof ext_python ext_pyston unittests
ALL_HEADERS := $(wildcard src/*/*.h) $(wildcard src/*/*/*.h) $(wildcard cpython2.7/Include/*.h)
ALL_HEADERS := $(wildcard src/*/*.h) $(wildcard src/*/*/*.h) $(wildcard from_cpython/Include/*.h)
tags: $(SRCS) $(OPTIONAL_SRCS) $(FROM_CPYTHON_SRCS) $(ALL_HEADERS)
$(ECHO) Calculating tags...
$(VERB) ctags $^
......@@ -865,6 +865,10 @@ $(call make_target,_grwl)
$(call make_target,_grwl_dbg)
$(call make_target,_nosync)
runpy_%: %.py ext_python
PYTHONPATH=test/test_extension/build/lib.linux-x86_64-2.7 python $<
$(call make_search,runpy_%)
# "kill valgrind":
kv:
ps aux | awk '/[v]algrind/ {print $$2}' | xargs kill -9; true
......
......@@ -42,7 +42,7 @@ PyAPI_FUNC(bool) PyInt_Check(PyObject*);
#define PyInt_Check(op) \
PyType_FastSubclass((op)->ob_type, Py_TPFLAGS_INT_SUBCLASS)
#endif
#define PyInt_CheckExact(op) ((op)->ob_type == &PyInt_Type)
#define PyInt_CheckExact(op) (Py_TYPE(op) == &PyInt_Type)
PyAPI_FUNC(PyObject *) PyInt_FromString(char*, char**, int);
#ifdef Py_USING_UNICODE
......
......@@ -75,4 +75,29 @@ extern "C" int PyObject_GenericSetAttr(PyObject* obj, PyObject* name, PyObject*
extern "C" int PyObject_AsWriteBuffer(PyObject* obj, void** buffer, Py_ssize_t* buffer_len) {
Py_FatalError("unimplemented");
}
/* Return -1 if error; 1 if v op w; 0 if not (v op w). */
extern "C" int PyObject_RichCompareBool(PyObject* v, PyObject* w, int op) {
PyObject* res;
int ok;
/* Quick result when objects are the same.
Guarantees that identity implies equality. */
if (v == w) {
if (op == Py_EQ)
return 1;
else if (op == Py_NE)
return 0;
}
res = PyObject_RichCompare(v, w, op);
if (res == NULL)
return -1;
if (PyBool_Check(res))
ok = (res == Py_True);
else
ok = PyObject_IsTrue(res);
Py_DECREF(res);
return ok;
}
}
This diff is collapsed.
......@@ -353,6 +353,7 @@ BoxedClass::BoxedClass(BoxedClass* metaclass, BoxedClass* base, gcvisit_func gc_
tp_basicsize = instance_size;
tp_flags |= Py_TPFLAGS_HEAPTYPE;
tp_flags |= Py_TPFLAGS_CHECKTYPES;
if (metaclass == NULL) {
assert(type_cls == NULL);
......@@ -1456,26 +1457,6 @@ void setattrInternal(Box* obj, const std::string& attr, Box* val, SetattrRewrite
descr = typeLookup(obj->cls, attr, NULL);
}
if (isSubclass(obj->cls, type_cls)) {
BoxedClass* self = static_cast<BoxedClass*>(obj);
if (attr == _getattr_str || attr == _getattribute_str) {
// Will have to embed the clear in the IC, so just disable the patching for now:
rewrite_args = NULL;
// TODO should put this clearing behavior somewhere else, since there are probably more
// cases in which we want to do it.
self->dependent_icgetattrs.invalidateAll();
}
if (attr == "__base__" && self->getattr("__base__"))
raiseExcHelper(TypeError, "readonly attribute");
bool touched_slot = update_slot(self, attr);
if (touched_slot)
rewrite_args = NULL;
}
Box* _set_ = NULL;
RewriterVar* r_set = NULL;
if (descr) {
......@@ -1511,6 +1492,26 @@ void setattrInternal(Box* obj, const std::string& attr, Box* val, SetattrRewrite
} else {
obj->setattr(attr, val, rewrite_args);
}
if (isSubclass(obj->cls, type_cls)) {
BoxedClass* self = static_cast<BoxedClass*>(obj);
if (attr == _getattr_str || attr == _getattribute_str) {
// Will have to embed the clear in the IC, so just disable the patching for now:
rewrite_args = NULL;
// TODO should put this clearing behavior somewhere else, since there are probably more
// cases in which we want to do it.
self->dependent_icgetattrs.invalidateAll();
}
if (attr == "__base__" && self->getattr("__base__"))
raiseExcHelper(TypeError, "readonly attribute");
bool touched_slot = update_slot(self, attr);
if (touched_slot)
rewrite_args = NULL;
}
}
extern "C" void setattr(Box* obj, const char* attr, Box* attr_val) {
......
This diff is collapsed.
......@@ -2,18 +2,43 @@ import slots_test
for i in xrange(3):
t = slots_test.SlotsTesterSeq(i + 5)
print t, repr(t), t(), t[2]
print hash(t), t < 1, t > 2, t != 3
print t, repr(t), str(t), t(), t[2]
print hash(t), t < 1, t > 2, t != 3, bool(t)
# print slots_test.SlotsTesterSeq.__doc__
print slots_test.SlotsTesterSeq.set_through_tpdict, slots_test.SlotsTesterSeq(5).set_through_tpdict
for i in xrange(3):
t = slots_test.SlotsTesterMap(i + 5)
print len(t), t[2]
print len(t), t[2], repr(t), str(t)
t[1] = 5
del t[2]
for i in xrange(3):
t = slots_test.SlotsTesterNum(i)
print bool(t)
print t + 5
print t - 5
print t * 5
print t / 5
print t % 5
print divmod(t, 5)
print t ** 5
print t << 5
print t >> 5
print t & 5
print t ^ 5
print t | 5
print +t
print -t
print abs(t)
print ~t
print int(t)
print long(t)
print float(t)
print hex(t)
print oct(t)
class C(object):
def __repr__(self):
print "__repr__()"
......@@ -33,4 +58,14 @@ slots_test.call_funcs(C())
def repr2(self):
return "repr2()"
C.__repr__ = repr2
def nonzero(self):
print "nonzero"
return True
C.__nonzero__ = nonzero
def add(self, rhs):
print "add", self, rhs
C.__add__ = add
slots_test.call_funcs(C())
......@@ -350,7 +350,7 @@ if __name__ == "__main__":
run_memcheck = False
start = 1
opts, patterns = getopt.gnu_getopt(sys.argv[1:], "j:a:t:mR:k")
opts, patterns = getopt.gnu_getopt(sys.argv[1:], "j:a:t:mR:kK")
for (t, v) in opts:
if t == '-m':
run_memcheck = True
......@@ -361,6 +361,8 @@ if __name__ == "__main__":
IMAGE = v
elif t == '-k':
KEEP_GOING = True
elif t == '-K':
KEEP_GOING = False
elif t == '-a':
EXTRA_JIT_ARGS.append(v)
elif t == '-t':
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment