Finally I have solved most of the segmentation faults in yesterday's midnight. Just two lines of code!
Now I understood that PyObject_New() only allocate memory, but haven't do the works like creating the object's __dict__ and etc. We should use PyBaseObject_Type.tp_new() to create a "full" object. Or maybe PyType_GenericNew() also works?
Another mistake I've made is using obj->tp_dict() directly to access the object's dict. *Must* use _PyObject_GetDictPtr() instead! Otherwise, we only get the dict of the object's type!
Well done, now more than 90% test cases passed! Cheers!
Now I understood that PyObject_New() only allocate memory, but haven't do the works like creating the object's __dict__ and etc. We should use PyBaseObject_Type.tp_new() to create a "full" object. Or maybe PyType_GenericNew() also works?
Another mistake I've made is using obj->tp_dict() directly to access the object's dict. *Must* use _PyObject_GetDictPtr() instead! Otherwise, we only get the dict of the object's type!
Well done, now more than 90% test cases passed! Cheers!
No comments:
Post a Comment