mirror of
				https://github.com/python/cpython.git
				synced 2025-10-31 05:31:20 +00:00 
			
		
		
		
	Array module's buffer interface can now handle empty arrays.
This commit is contained in:
		
							parent
							
								
									e6e660bde3
								
							
						
					
					
						commit
						01a807db2a
					
				
					 2 changed files with 13 additions and 0 deletions
				
			
		|  | @ -1745,6 +1745,8 @@ static PyMappingMethods array_as_mapping = { | |||
| 	(objobjargproc)array_ass_subscr | ||||
| }; | ||||
| 
 | ||||
| static const void *emptybuf = ""; | ||||
| 
 | ||||
| static Py_ssize_t | ||||
| array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr) | ||||
| { | ||||
|  | @ -1754,6 +1756,8 @@ array_buffer_getreadbuf(arrayobject *self, Py_ssize_t index, const void **ptr) | |||
| 		return -1; | ||||
| 	} | ||||
| 	*ptr = (void *)self->ob_item; | ||||
| 	if (*ptr == NULL) | ||||
| 		*ptr = emptybuf; | ||||
| 	return self->ob_size*self->ob_descr->itemsize; | ||||
| } | ||||
| 
 | ||||
|  | @ -1766,6 +1770,8 @@ array_buffer_getwritebuf(arrayobject *self, Py_ssize_t index, const void **ptr) | |||
| 		return -1; | ||||
| 	} | ||||
| 	*ptr = (void *)self->ob_item; | ||||
| 	if (*ptr == NULL) | ||||
| 		*ptr = emptybuf; | ||||
| 	return self->ob_size*self->ob_descr->itemsize; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Raymond Hettinger
						Raymond Hettinger