def getweakrefs(space, w_obj):
    """Return a list of all weak reference objects that point to 'obj'."""
    lifeline = w_obj.getweakref()
    if lifeline is None:
        return space.newlist([])
    else:
        result = []
        for i in range(len(lifeline.refs_weak)):
            w_ref = lifeline.refs_weak[i]()
            if w_ref is not None:
                result.append(w_ref)
        return space.newlist(result)