Commit 992eee47 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #409 from undingen/fix_pip_search2

Misc fixes for pip search part 2
parents 2c1b4069 abdf99d3
...@@ -91,9 +91,7 @@ static Box* propertyDel(Box* self, Box* obj) { ...@@ -91,9 +91,7 @@ static Box* propertyDel(Box* self, Box* obj) {
} }
static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) { static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) {
// In CPython, I think this can take a subclass of property, and will call the subclass's RELEASE_ASSERT(isSubclass(old->cls, property_cls), "");
// constructor... for now just enforce that it's a property object and inline the constructor:
RELEASE_ASSERT(old->cls == property_cls, "");
if (!get) if (!get)
get = old->prop_get; get = old->prop_get;
...@@ -102,7 +100,10 @@ static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) { ...@@ -102,7 +100,10 @@ static Box* property_copy(BoxedProperty* old, Box* get, Box* set, Box* del) {
if (!del) if (!del)
del = old->prop_del; del = old->prop_del;
// Optimization for the case when the old propery is not subclassed
if (old->cls == property_cls)
return new BoxedProperty(get, set, del, old->prop_doc); return new BoxedProperty(get, set, del, old->prop_doc);
return runtimeCall(old->cls, ArgPassSpec(4), get, set, del, &old->prop_doc, NULL);
} }
static Box* propertyGetter(Box* self, Box* obj) { static Box* propertyGetter(Box* self, Box* obj) {
......
...@@ -684,6 +684,26 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) { ...@@ -684,6 +684,26 @@ Box* impLoadModule(Box* _name, Box* _file, Box* _pathname, Box** args) {
Py_FatalError("unimplemented"); Py_FatalError("unimplemented");
} }
Box* impGetSuffixes() {
BoxedList* list = new BoxedList;
// For now only add *.py
listAppendInternal(
list, new BoxedTuple({ new BoxedString(".py"), new BoxedString("U"), boxInt(SearchResult::PY_SOURCE) }));
return list;
}
Box* impAcquireLock() {
_PyImport_AcquireLock();
checkAndThrowCAPIException();
return None;
}
Box* impReleaseLock() {
_PyImport_ReleaseLock();
checkAndThrowCAPIException();
return None;
}
void setupImport() { void setupImport() {
BoxedModule* imp_module BoxedModule* imp_module
= createModule("imp", "__builtin__", "'This module provides the components needed to build your own\n" = createModule("imp", "__builtin__", "'This module provides the components needed to build your own\n"
...@@ -714,5 +734,12 @@ void setupImport() { ...@@ -714,5 +734,12 @@ void setupImport() {
ParamNames({ "name", "file", "pathname", "description" }, "", "")); ParamNames({ "name", "file", "pathname", "description" }, "", ""));
imp_module->giveAttr("load_module", new BoxedBuiltinFunctionOrMethod(load_module_func, "load_module")); imp_module->giveAttr("load_module", new BoxedBuiltinFunctionOrMethod(load_module_func, "load_module"));
imp_module->giveAttr("get_suffixes", new BoxedBuiltinFunctionOrMethod(
boxRTFunction((void*)impGetSuffixes, UNKNOWN, 0), "get_suffixes"));
imp_module->giveAttr("acquire_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impAcquireLock, NONE, 0),
"acquire_lock"));
imp_module->giveAttr("release_lock", new BoxedBuiltinFunctionOrMethod(boxRTFunction((void*)impReleaseLock, NONE, 0),
"release_lock"));
} }
} }
...@@ -497,6 +497,8 @@ static void typeSetDict(Box* obj, Box* val, void* context) { ...@@ -497,6 +497,8 @@ static void typeSetDict(Box* obj, Box* val, void* context) {
Box* dict_descr = NULL; Box* dict_descr = NULL;
extern "C" void instancemethodGCHandler(GCVisitor* v, Box* b) { extern "C" void instancemethodGCHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b);
BoxedInstanceMethod* im = (BoxedInstanceMethod*)b; BoxedInstanceMethod* im = (BoxedInstanceMethod*)b;
if (im->obj) { if (im->obj) {
...@@ -506,6 +508,8 @@ extern "C" void instancemethodGCHandler(GCVisitor* v, Box* b) { ...@@ -506,6 +508,8 @@ extern "C" void instancemethodGCHandler(GCVisitor* v, Box* b) {
} }
extern "C" void propertyGCHandler(GCVisitor* v, Box* b) { extern "C" void propertyGCHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b);
BoxedProperty* prop = (BoxedProperty*)b; BoxedProperty* prop = (BoxedProperty*)b;
if (prop->prop_get) if (prop->prop_get)
...@@ -519,6 +523,8 @@ extern "C" void propertyGCHandler(GCVisitor* v, Box* b) { ...@@ -519,6 +523,8 @@ extern "C" void propertyGCHandler(GCVisitor* v, Box* b) {
} }
extern "C" void staticmethodGCHandler(GCVisitor* v, Box* b) { extern "C" void staticmethodGCHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b);
BoxedStaticmethod* sm = (BoxedStaticmethod*)b; BoxedStaticmethod* sm = (BoxedStaticmethod*)b;
if (sm->sm_callable) if (sm->sm_callable)
...@@ -526,6 +532,8 @@ extern "C" void staticmethodGCHandler(GCVisitor* v, Box* b) { ...@@ -526,6 +532,8 @@ extern "C" void staticmethodGCHandler(GCVisitor* v, Box* b) {
} }
extern "C" void classmethodGCHandler(GCVisitor* v, Box* b) { extern "C" void classmethodGCHandler(GCVisitor* v, Box* b) {
boxGCHandler(v, b);
BoxedClassmethod* cm = (BoxedClassmethod*)b; BoxedClassmethod* cm = (BoxedClassmethod*)b;
if (cm->cm_callable) if (cm->cm_callable)
......
...@@ -13,3 +13,6 @@ for a in (1, "", "/proc", "nonexisting_dir"): ...@@ -13,3 +13,6 @@ for a in (1, "", "/proc", "nonexisting_dir"):
except Exception as e: except Exception as e:
print e print e
imp.acquire_lock()
imp.release_lock()
...@@ -63,3 +63,22 @@ try: ...@@ -63,3 +63,22 @@ try:
except AttributeError, e: except AttributeError, e:
print e print e
c.x = 1 c.x = 1
class MyProperty(property):
pass
class C(object):
v = "empty"
@MyProperty
def p(self):
print "get"
return self.v
@p.setter
def p(self, value):
print "set"
self.v = "it " + value
c = C()
c.p = "worked"
print c.p
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