[Python-checkins] python/dist/src/Mac/Modules/snd _Sndmodule.c,1.10,1.11 sndsupport.py,1.19,1.20

jackjansen@users.sourceforge.net jackjansen@users.sourceforge.net
Fri, 29 Nov 2002 15:40:49 -0800


Update of /cvsroot/python/python/dist/src/Mac/Modules/snd
In directory sc8-pr-cvs1:/tmp/cvs-serv8673/snd

Modified Files:
	_Sndmodule.c sndsupport.py 
Log Message:
Converted the Carbon modules to use PEP252-style objects, with
descriptors in stead of manual getattr hooks to get at attributes
of the objects.

For Qd I have in stead gotten rid of most of the attribute access
in favor of the carbon-style accessor methods (with the exception
of visRgn, to be done later), and of the Carbon.Qd.qd global object,
for which accessor functions are also available.

For List I have fixed the fact that various methods were incorrectly
generated as functions.

CF is untouched: PEP252 doesn't allow "poor-mans-inheritance" with
basechain, so it will have to wait for PEP253 support.


Index: _Sndmodule.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/snd/_Sndmodule.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** _Sndmodule.c	16 Aug 2002 09:09:30 -0000	1.10
--- _Sndmodule.c	29 Nov 2002 23:40:47 -0000	1.11
***************
*** 301,312 ****
  };
  
! static PyMethodChain SndCh_chain = { SndCh_methods, NULL };
! 
! static PyObject *SndCh_getattr(SndChannelObject *self, char *name)
! {
! 	return Py_FindMethodInChain(&SndCh_chain, (PyObject *)self, name);
! }
  
- #define SndCh_setattr NULL
  
  #define SndCh_compare NULL
--- 301,306 ----
  };
  
! #define SndCh_getsetlist NULL
  
  
  #define SndCh_compare NULL
***************
*** 325,330 ****
  	(destructor) SndCh_dealloc, /*tp_dealloc*/
  	0, /*tp_print*/
! 	(getattrfunc) SndCh_getattr, /*tp_getattr*/
! 	(setattrfunc) SndCh_setattr, /*tp_setattr*/
  	(cmpfunc) SndCh_compare, /*tp_compare*/
  	(reprfunc) SndCh_repr, /*tp_repr*/
--- 319,324 ----
  	(destructor) SndCh_dealloc, /*tp_dealloc*/
  	0, /*tp_print*/
! 	(getattrfunc)0, /*tp_getattr*/
! 	(setattrfunc)0, /*tp_setattr*/
  	(cmpfunc) SndCh_compare, /*tp_compare*/
  	(reprfunc) SndCh_repr, /*tp_repr*/
***************
*** 333,336 ****
--- 327,347 ----
  	(PyMappingMethods *)0, /* tp_as_mapping */
  	(hashfunc) SndCh_hash, /*tp_hash*/
+ 	0, /*tp_call*/
+ 	0, /*tp_str*/
+ 	PyObject_GenericGetAttr, /*tp_getattro*/
+ 	PyObject_GenericSetAttr, /*tp_setattro */
+ 	0, /*outputHook_tp_as_buffer*/
+ 	0, /*outputHook_tp_flags*/
+ 	0, /*outputHook_tp_doc*/
+ 	0, /*outputHook_tp_traverse*/
+ 	0, /*outputHook_tp_clear*/
+ 	0, /*outputHook_tp_richcompare*/
+ 	0, /*outputHook_tp_weaklistoffset*/
+ 	0, /*outputHook_tp_iter*/
+ 	0, /*outputHook_tp_iternext*/
+ 	SndCh_methods, /* tp_methods */
+ 	0, /*outputHook_tp_members*/
+ 	SndCh_getsetlist, /*tp_getset*/
+ 	0, /*outputHook_tp_base*/
  };
  
***************
*** 392,441 ****
  };
  
! static PyMethodChain SPBObj_chain = { SPBObj_methods, NULL };
  
! static PyObject *SPBObj_getattr(SPBObject *self, char *name)
  {
  
! 				if (strcmp(name, "inRefNum") == 0)
! 					return Py_BuildValue("l", self->ob_spb.inRefNum);
! 				else if (strcmp(name, "count") == 0)
! 					return Py_BuildValue("l", self->ob_spb.count);
! 				else if (strcmp(name, "milliseconds") == 0)
! 					return Py_BuildValue("l", self->ob_spb.milliseconds);
! 				else if (strcmp(name, "error") == 0)
! 					return Py_BuildValue("h", self->ob_spb.error);
! 	return Py_FindMethodInChain(&SPBObj_chain, (PyObject *)self, name);
  }
  
! static int SPBObj_setattr(SPBObject *self, char *name, PyObject *value)
  {
  
! 		int rv = 0;
! 		
! 		if (strcmp(name, "inRefNum") == 0)
! 			rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
! 		else if (strcmp(name, "count") == 0)
! 			rv = PyArg_Parse(value, "l", &self->ob_spb.count);
! 		else if (strcmp(name, "milliseconds") == 0)
! 			rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
! 		else if (strcmp(name, "buffer") == 0)
! 			rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
! 		else if (strcmp(name, "completionRoutine") == 0) {
! 			self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
! 			self->ob_completion = value;
! 			Py_INCREF(value);
! 			rv = 1;
! #if !TARGET_API_MAC_CARBON
! 		} else if (strcmp(name, "interruptRoutine") == 0) {
! 			self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
! 			self->ob_interrupt = value;
! 			Py_INCREF(value);
! 			rv = 1;
! #endif
! 		}
! 		if ( rv ) return 0;
! 		else return -1;
  }
  
  #define SPBObj_compare NULL
  
--- 403,466 ----
  };
  
! static PyObject *SPBObj_get_inRefNum(SPBObject *self, void *closure)
! {
! 	return Py_BuildValue("l", self->ob_spb.inRefNum);
! }
  
! static int SPBObj_set_inRefNum(SPBObject *self, PyObject *v, void *closure)
  {
+ 	return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);
+ 	return 0;
+ }
  
! static PyObject *SPBObj_get_count(SPBObject *self, void *closure)
! {
! 	return Py_BuildValue("l", self->ob_spb.count);
  }
  
! static int SPBObj_set_count(SPBObject *self, PyObject *v, void *closure)
  {
+ 	return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);
+ 	return 0;
+ }
  
! static PyObject *SPBObj_get_milliseconds(SPBObject *self, void *closure)
! {
! 	return Py_BuildValue("l", self->ob_spb.milliseconds);
  }
  
+ static int SPBObj_set_milliseconds(SPBObject *self, PyObject *v, void *closure)
+ {
+ 	return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);
+ 	return 0;
+ }
+ 
+ static PyObject *SPBObj_get_error(SPBObject *self, void *closure)
+ {
+ 	return Py_BuildValue("h", self->ob_spb.error);
+ }
+ 
+ #define SPBObj_set_error NULL
+ 
+ #define SPBObj_get_completionRoutine NULL
+ 
+ static int SPBObj_set_completionRoutine(SPBObject *self, PyObject *v, void *closure)
+ {
+ 	self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
+ 			self->ob_completion = v;
+ 			Py_INCREF(v);
+ 			return 0;
+ 	return 0;
+ }
+ 
+ static PyGetSetDef SPBObj_getsetlist[] = {
+ 	{"inRefNum", (getter)SPBObj_get_inRefNum, (setter)SPBObj_set_inRefNum, NULL},
+ 	{"count", (getter)SPBObj_get_count, (setter)SPBObj_set_count, NULL},
+ 	{"milliseconds", (getter)SPBObj_get_milliseconds, (setter)SPBObj_set_milliseconds, NULL},
+ 	{"error", (getter)SPBObj_get_error, (setter)SPBObj_set_error, NULL},
+ 	{"completionRoutine", (getter)SPBObj_get_completionRoutine, (setter)SPBObj_set_completionRoutine, NULL},
+ };
+ 
+ 
  #define SPBObj_compare NULL
  
***************
*** 453,458 ****
  	(destructor) SPBObj_dealloc, /*tp_dealloc*/
  	0, /*tp_print*/
! 	(getattrfunc) SPBObj_getattr, /*tp_getattr*/
! 	(setattrfunc) SPBObj_setattr, /*tp_setattr*/
  	(cmpfunc) SPBObj_compare, /*tp_compare*/
  	(reprfunc) SPBObj_repr, /*tp_repr*/
--- 478,483 ----
  	(destructor) SPBObj_dealloc, /*tp_dealloc*/
  	0, /*tp_print*/
! 	(getattrfunc)0, /*tp_getattr*/
! 	(setattrfunc)0, /*tp_setattr*/
  	(cmpfunc) SPBObj_compare, /*tp_compare*/
  	(reprfunc) SPBObj_repr, /*tp_repr*/
***************
*** 461,464 ****
--- 486,506 ----
  	(PyMappingMethods *)0, /* tp_as_mapping */
  	(hashfunc) SPBObj_hash, /*tp_hash*/
+ 	0, /*tp_call*/
+ 	0, /*tp_str*/
+ 	PyObject_GenericGetAttr, /*tp_getattro*/
+ 	PyObject_GenericSetAttr, /*tp_setattro */
+ 	0, /*outputHook_tp_as_buffer*/
+ 	0, /*outputHook_tp_flags*/
+ 	0, /*outputHook_tp_doc*/
+ 	0, /*outputHook_tp_traverse*/
+ 	0, /*outputHook_tp_clear*/
+ 	0, /*outputHook_tp_richcompare*/
+ 	0, /*outputHook_tp_weaklistoffset*/
+ 	0, /*outputHook_tp_iter*/
+ 	0, /*outputHook_tp_iternext*/
+ 	SPBObj_methods, /* tp_methods */
+ 	0, /*outputHook_tp_members*/
+ 	SPBObj_getsetlist, /*tp_getset*/
+ 	0, /*outputHook_tp_base*/
  };
  

Index: sndsupport.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Modules/snd/sndsupport.py,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -d -r1.19 -r1.20
*** sndsupport.py	5 Feb 2002 22:35:36 -0000	1.19
--- sndsupport.py	29 Nov 2002 23:40:47 -0000	1.20
***************
*** 212,216 ****
  # create the module and object definition and link them
  
! class SndObjectDefinition(ObjectDefinition):
  
  	def outputStructMembers(self):
--- 212,216 ----
  # create the module and object definition and link them
  
! class SndObjectDefinition(PEP252Mixin, ObjectDefinition):
  
  	def outputStructMembers(self):
***************
*** 238,242 ****
  #
  
! class SpbObjectDefinition(ObjectDefinition):
  
  	def outputStructMembers(self):
--- 238,272 ----
  #
  
! class SpbObjectDefinition(PEP252Mixin, ObjectDefinition):
! 	getsetlist = [
! 		(
! 		'inRefNum',
! 		'return Py_BuildValue("l", self->ob_spb.inRefNum);',
! 		'return -1 + PyArg_Parse(v, "l", &self->ob_spb.inRefNum);',
! 		None,
! 		), (
! 		'count',
! 		'return Py_BuildValue("l", self->ob_spb.count);',
! 		'return -1 + PyArg_Parse(v, "l", &self->ob_spb.count);',
! 		None
! 		), (
! 		'milliseconds',
! 		'return Py_BuildValue("l", self->ob_spb.milliseconds);',
! 		'return -1 + PyArg_Parse(v, "l", &self->ob_spb.milliseconds);',
! 		None,
! 		), (
! 		'error',
! 		'return Py_BuildValue("h", self->ob_spb.error);',
! 		None,
! 		None
! 		), (
! 		'completionRoutine',
! 		None,
! 		"""self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
! 		self->ob_completion = v;
! 		Py_INCREF(v);
! 		return 0;""",
! 		None,
! 		)]
  
  	def outputStructMembers(self):
***************
*** 287,338 ****
  		Output("return 1;")
  		OutRbrace()
- 
- 	def outputSetattr(self):
- 		Output()
- 		Output("static int %s_setattr(%s *self, char *name, PyObject *value)", 
- 			self.prefix, self.objecttype)
- 		OutLbrace()
- 		self.outputSetattrBody()
- 		OutRbrace()
- 
- 	def outputSetattrBody(self):
- 		Output("""
- 	int rv = 0;
- 	
- 	if (strcmp(name, "inRefNum") == 0)
- 		rv = PyArg_Parse(value, "l", &self->ob_spb.inRefNum);
- 	else if (strcmp(name, "count") == 0)
- 		rv = PyArg_Parse(value, "l", &self->ob_spb.count);
- 	else if (strcmp(name, "milliseconds") == 0)
- 		rv = PyArg_Parse(value, "l", &self->ob_spb.milliseconds);
- 	else if (strcmp(name, "buffer") == 0)
- 		rv = PyArg_Parse(value, "w#", &self->ob_spb.bufferPtr, &self->ob_spb.bufferLength);
- 	else if (strcmp(name, "completionRoutine") == 0) {
- 		self->ob_spb.completionRoutine = NewSICompletionUPP(SPB_completion);
- 		self->ob_completion = value;
- 		Py_INCREF(value);
- 		rv = 1;
- #if !TARGET_API_MAC_CARBON
- 	} else if (strcmp(name, "interruptRoutine") == 0) {
- 		self->ob_spb.completionRoutine = NewSIInterruptUPP(SPB_interrupt);
- 		self->ob_interrupt = value;
- 		Py_INCREF(value);
- 		rv = 1;
- #endif
- 	}
- 	if ( rv ) return 0;
- 	else return -1;""")
- 			
- 	def outputGetattrHook(self):
- 		Output("""
- 			if (strcmp(name, "inRefNum") == 0)
- 				return Py_BuildValue("l", self->ob_spb.inRefNum);
- 			else if (strcmp(name, "count") == 0)
- 				return Py_BuildValue("l", self->ob_spb.count);
- 			else if (strcmp(name, "milliseconds") == 0)
- 				return Py_BuildValue("l", self->ob_spb.milliseconds);
- 			else if (strcmp(name, "error") == 0)
- 				return Py_BuildValue("h", self->ob_spb.error);""")
- 		
  					
  
--- 317,320 ----