@@ -840,3 +840,138 @@ PyWrapper_New(PyObject *d, PyObject *self)
840840 }
841841 return (PyObject * )wp ;
842842}
843+
844+
845+ /* A built-in 'getset' type */
846+
847+ /*
848+ class getset(object):
849+
850+ def __init__(self, get=None, set=None):
851+ self.__get = get
852+ self.__set = set
853+
854+ def __get__(self, inst, type=None):
855+ if self.__get is None:
856+ raise AttributeError, "unreadable attribute"
857+ if inst is None:
858+ return self
859+ return self.__get(inst)
860+
861+ def __set__(self, inst, value):
862+ if self.__set is None:
863+ raise AttributeError, "unsettable attribute"
864+ return self.__set(inst, value)
865+ */
866+
867+ typedef struct {
868+ PyObject_HEAD
869+ PyObject * get ;
870+ PyObject * set ;
871+ } getsetobject ;
872+
873+ static void
874+ getset_dealloc (PyObject * self )
875+ {
876+ getsetobject * gs = (getsetobject * )self ;
877+
878+ Py_XDECREF (gs -> get );
879+ Py_XDECREF (gs -> set );
880+ self -> ob_type -> tp_free (self );
881+ }
882+
883+ static PyObject *
884+ getset_descr_get (PyObject * self , PyObject * obj , PyObject * type )
885+ {
886+ getsetobject * gs = (getsetobject * )self ;
887+
888+ if (gs -> get == NULL ) {
889+ PyErr_SetString (PyExc_AttributeError , "unreadable attribute" );
890+ return NULL ;
891+ }
892+ if (obj == NULL || obj == Py_None ) {
893+ Py_INCREF (self );
894+ return self ;
895+ }
896+ return PyObject_CallFunction (gs -> get , "(O)" , obj );
897+ }
898+
899+ static int
900+ getset_descr_set (PyObject * self , PyObject * obj , PyObject * value )
901+ {
902+ getsetobject * gs = (getsetobject * )self ;
903+ PyObject * res ;
904+
905+ if (gs -> set == NULL ) {
906+ PyErr_SetString (PyExc_AttributeError , "unsettable attribute" );
907+ return -1 ;
908+ }
909+ res = PyObject_CallFunction (gs -> set , "(OO)" , obj , value );
910+ if (res == NULL )
911+ return -1 ;
912+ Py_DECREF (res );
913+ return 0 ;
914+ }
915+
916+ static int
917+ getset_init (PyObject * self , PyObject * args , PyObject * kwds )
918+ {
919+ PyObject * get , * set ;
920+ getsetobject * gs = (getsetobject * )self ;
921+
922+ if (!PyArg_ParseTuple (args , "OO:getset.__init__" , & get , & set ))
923+ return -1 ;
924+ if (get == Py_None )
925+ get = NULL ;
926+ if (set == Py_None )
927+ set = NULL ;
928+ Py_XINCREF (get );
929+ Py_XINCREF (set );
930+ gs -> get = get ;
931+ gs -> set = set ;
932+ return 0 ;
933+ }
934+
935+ PyTypeObject PyGetSet_Type = {
936+ PyObject_HEAD_INIT (& PyType_Type )
937+ 0 , /* ob_size */
938+ "getset" , /* tp_name */
939+ sizeof (getsetobject ), /* tp_basicsize */
940+ 0 , /* tp_itemsize */
941+ /* methods */
942+ getset_dealloc , /* tp_dealloc */
943+ 0 , /* tp_print */
944+ 0 , /* tp_getattr */
945+ 0 , /* tp_setattr */
946+ 0 , /* tp_compare */
947+ 0 , /* tp_repr */
948+ 0 , /* tp_as_number */
949+ 0 , /* tp_as_sequence */
950+ 0 , /* tp_as_mapping */
951+ 0 , /* tp_hash */
952+ 0 , /* tp_call */
953+ 0 , /* tp_str */
954+ PyObject_GenericGetAttr , /* tp_getattro */
955+ 0 , /* tp_setattro */
956+ 0 , /* tp_as_buffer */
957+ Py_TPFLAGS_DEFAULT , /* tp_flags */
958+ 0 , /* tp_doc */
959+ 0 , /* tp_traverse */
960+ 0 , /* tp_clear */
961+ 0 , /* tp_richcompare */
962+ 0 , /* tp_weaklistoffset */
963+ 0 , /* tp_iter */
964+ 0 , /* tp_iternext */
965+ 0 , /* tp_methods */
966+ 0 , /* tp_members */
967+ 0 , /* tp_getset */
968+ 0 , /* tp_base */
969+ 0 , /* tp_dict */
970+ getset_descr_get , /* tp_descr_get */
971+ getset_descr_set , /* tp_descr_set */
972+ 0 , /* tp_dictoffset */
973+ getset_init , /* tp_init */
974+ PyType_GenericAlloc , /* tp_alloc */
975+ PyType_GenericNew , /* tp_new */
976+ _PyObject_Del , /* tp_free */
977+ };
0 commit comments