Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ diff --git a/src/mi/dyn-register.c b/src/mi/dyn-register.c
index c28954a..c4f88b1 100644
--- a/src/mi/dyn-register.c
+++ b/src/mi/dyn-register.c
@@ -32,13 +32,28 @@ _U_dyn_register (unw_dyn_info_t *di)
@@ -32,13 +32,27 @@ _U_dyn_register (unw_dyn_info_t *di)
{
mutex_lock (&_U_dyn_info_list_lock);
{
Expand Down Expand Up @@ -148,8 +148,7 @@ index c28954a..c4f88b1 100644
+ break;
+ }
+
+ if (_U_dyn_info_list_size > 1)
+ memmove(&_U_dyn_info_list[i+1], &_U_dyn_info_list[i], (_U_dyn_info_list_size - i) * sizeof(unw_dyn_info_t*));
+ memmove(&_U_dyn_info_list[i+1], &_U_dyn_info_list[i], (_U_dyn_info_list_size - i) * sizeof(unw_dyn_info_t*));
+ _U_dyn_info_list[i] = di;
+ _U_dyn_info_list_size ++;
}
Expand Down
4 changes: 2 additions & 2 deletions src/capi/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ static int try_3way_compare(PyObject* v, PyObject* w) {
0 if v == w;
1 if v > w.
*/
static int default_3way_compare(PyObject* v, PyObject* w) {
/* Pyston change: static*/ int default_3way_compare(PyObject* v, PyObject* w) {
int c;
const char* vname, *wname;

Expand Down Expand Up @@ -865,7 +865,7 @@ extern "C" int PyObject_Compare(PyObject* v, PyObject* w) noexcept {
}

/* Return (new reference to) Py_True or Py_False. */
static PyObject* convert_3way_to_object(int op, int c) noexcept {
/* Pyston change: static */ PyObject* convert_3way_to_object(int op, int c) noexcept {
PyObject* result;
switch (op) {
case Py_LT:
Expand Down
10 changes: 9 additions & 1 deletion src/capi/typeobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,15 @@ static PyObject* half_richcompare(PyObject* self, PyObject* other, int op) noexc
return res;
}

static PyObject* slot_tp_richcompare(PyObject* self, PyObject* other, int op) noexcept {
/* Pyston change: static*/ PyObject* slot_tp_richcompare(PyObject* self, PyObject* other, int op) noexcept {
static StatCounter slowpath_richcompare("slowpath_richcompare");
slowpath_richcompare.log();
#if 0
std::string per_name_stat_name = "slowpath_richcompare." + std::string(self->cls->tp_name);
int id = Stats::getStatId(per_name_stat_name);
Stats::log(id);
#endif

PyObject* res;

if (Py_TYPE(self)->tp_richcompare == slot_tp_richcompare) {
Expand Down
2 changes: 2 additions & 0 deletions src/capi/typeobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void commonClassSetup(BoxedClass* cls);
PyTypeObject* best_base(PyObject* bases) noexcept;
PyObject* mro_external(PyObject* self) noexcept;
int type_set_bases(PyTypeObject* type, PyObject* value, void* context) noexcept;

PyObject* slot_tp_richcompare(PyObject* self, PyObject* other, int op) noexcept;
}

#endif
3 changes: 3 additions & 0 deletions src/capi/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ class BoxedMethodDescriptor : public Box {
}
};

PyObject* convert_3way_to_object(int op, int c) noexcept;
int default_3way_compare(PyObject* v, PyObject* w);

} // namespace pyston

#endif
14 changes: 8 additions & 6 deletions src/runtime/builtin_modules/builtins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,11 @@ extern "C" Box* min(Box* arg0, BoxedTuple* args) {
if (!minElement) {
minElement = e;
} else {
Box* comp_result = compareInternal(minElement, e, AST_TYPE::Gt, NULL);
if (nonzero(comp_result)) {
int r = PyObject_RichCompareBool(minElement, e, Py_GT);
if (r == -1)
throwCAPIException();
if (r)
minElement = e;
}
}
}

Expand All @@ -192,10 +193,11 @@ extern "C" Box* max(Box* arg0, BoxedTuple* args) {
if (!maxElement) {
maxElement = e;
} else {
Box* comp_result = compareInternal(maxElement, e, AST_TYPE::Lt, NULL);
if (nonzero(comp_result)) {
int r = PyObject_RichCompareBool(maxElement, e, Py_LT);
if (r == -1)
throwCAPIException();
if (r)
maxElement = e;
}
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/runtime/capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,8 +586,11 @@ extern "C" long _Py_HashPointer(void* p) noexcept {
}

extern "C" int PyObject_IsTrue(PyObject* o) noexcept {
if (o->cls == bool_cls)
return o == True;

try {
return nonzero(o);
return o->nonzeroIC();
} catch (ExcInfo e) {
fatalOrError(PyExc_NotImplementedError, "unimplemented");
return -1;
Expand Down Expand Up @@ -1647,6 +1650,13 @@ static Box* methodGetDoc(Box* b, void*) {
return None;
}

static Box* wrapperdescrGetDoc(Box* b, void*) {
assert(b->cls == wrapperdescr_cls);
auto s = static_cast<BoxedWrapperDescriptor*>(b)->wrapper->doc;
assert(s.size());
return boxString(s);
}

/* extension modules might be compiled with GC support so these
functions must always be available */

Expand Down Expand Up @@ -1735,6 +1745,8 @@ void setupCAPI() {
new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__get__, UNKNOWN, 3)));
wrapperdescr_cls->giveAttr("__call__", new BoxedFunction(boxRTFunction((void*)BoxedWrapperDescriptor::__call__,
UNKNOWN, 2, 0, true, true)));
wrapperdescr_cls->giveAttr("__doc__",
new (pyston_getset_cls) BoxedGetsetDescriptor(wrapperdescrGetDoc, NULL, NULL));
wrapperdescr_cls->freeze();

wrapperobject_cls->giveAttr(
Expand Down
138 changes: 29 additions & 109 deletions src/runtime/int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -566,109 +566,6 @@ extern "C" Box* intTruediv(BoxedInt* lhs, Box* rhs) {
}
}

extern "C" Box* intEqInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n == rhs->n);
}

extern "C" Box* intEq(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__eq__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (isSubclass(rhs->cls, int_cls)) {
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n == rhs_int->n);
} else {
return NotImplemented;
}
}

extern "C" Box* intNeInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n != rhs->n);
}

extern "C" Box* intNe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__ne__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n != rhs_int->n);
}

extern "C" Box* intLtInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n < rhs->n);
}

extern "C" Box* intLt(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__lt__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n < rhs_int->n);
}

extern "C" Box* intLeInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n <= rhs->n);
}

extern "C" Box* intLe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__le__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n <= rhs_int->n);
}

extern "C" Box* intGtInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n > rhs->n);
}

extern "C" Box* intGt(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__gt__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n > rhs_int->n);
}

extern "C" Box* intGeInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
return boxBool(lhs->n >= rhs->n);
}

extern "C" Box* intGe(BoxedInt* lhs, Box* rhs) {
if (!isSubclass(lhs->cls, int_cls))
raiseExcHelper(TypeError, "descriptor '__ge__' requires a 'int' object but received a '%s'", getTypeName(lhs));

if (!isSubclass(rhs->cls, int_cls)) {
return NotImplemented;
}
BoxedInt* rhs_int = static_cast<BoxedInt*>(rhs);
return boxBool(lhs->n >= rhs_int->n);
}

extern "C" Box* intLShiftInt(BoxedInt* lhs, BoxedInt* rhs) {
assert(isSubclass(lhs->cls, int_cls));
assert(isSubclass(rhs->cls, int_cls));
Expand Down Expand Up @@ -1119,6 +1016,33 @@ static int64_t int_hash(BoxedInt* o) noexcept {
return n;
}

static PyObject* int_richcompare(PyObject* v, PyObject* w, int op) noexcept {
if (!PyInt_Check(v) || !PyInt_Check(w)) {
Py_INCREF(Py_NotImplemented);
return Py_NotImplemented;
}

int64_t lhs = static_cast<BoxedInt*>(v)->n;
int64_t rhs = static_cast<BoxedInt*>(w)->n;

switch (op) {
case Py_EQ:
return boxBool(lhs == rhs);
case Py_NE:
return boxBool(lhs != rhs);
case Py_LT:
return boxBool(lhs < rhs);
case Py_LE:
return boxBool(lhs <= rhs);
case Py_GT:
return boxBool(lhs > rhs);
case Py_GE:
return boxBool(lhs >= rhs);
default:
RELEASE_ASSERT(0, "%d", op);
}
}

void setupInt() {
for (int i = 0; i < NUM_INTERNED_INTS; i++) {
interned_ints[i] = new BoxedInt(i);
Expand All @@ -1138,12 +1062,8 @@ void setupInt() {
int_cls->giveAttr("__pow__",
new BoxedFunction(boxRTFunction((void*)intPow, UNKNOWN, 3, 1, false, false), { None }));

_addFuncIntUnknown("__eq__", BOXED_BOOL, (void*)intEqInt, (void*)intEq);
_addFuncIntUnknown("__ne__", BOXED_BOOL, (void*)intNeInt, (void*)intNe);
_addFuncIntUnknown("__lt__", BOXED_BOOL, (void*)intLtInt, (void*)intLt);
_addFuncIntUnknown("__le__", BOXED_BOOL, (void*)intLeInt, (void*)intLe);
_addFuncIntUnknown("__gt__", BOXED_BOOL, (void*)intGtInt, (void*)intGt);
_addFuncIntUnknown("__ge__", BOXED_BOOL, (void*)intGeInt, (void*)intGe);
// Note: CPython implements int comparisons using tp_compare
int_cls->tp_richcompare = int_richcompare;

_addFuncIntUnknown("__lshift__", UNKNOWN, (void*)intLShiftInt, (void*)intLShift);
_addFuncIntUnknown("__rshift__", UNKNOWN, (void*)intRShiftInt, (void*)intRShift);
Expand Down
Loading