mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	Fix my last change on PyUnicode_Join(): don't process separator if len==1
This commit is contained in:
		
							parent
							
								
									25a4b29c95
								
							
						
					
					
						commit
						acf47b807f
					
				
					 1 changed files with 32 additions and 28 deletions
				
			
		|  | @ -9145,37 +9145,41 @@ PyUnicode_Join(PyObject *separator, PyObject *seq) | ||||||
| 
 | 
 | ||||||
|     /* If singleton sequence with an exact Unicode, return that. */ |     /* If singleton sequence with an exact Unicode, return that. */ | ||||||
|     items = PySequence_Fast_ITEMS(fseq); |     items = PySequence_Fast_ITEMS(fseq); | ||||||
|     if (seqlen == 1 && PyUnicode_CheckExact(items[0])) { |     if (seqlen == 1) { | ||||||
|         res = items[0]; |         if (PyUnicode_CheckExact(items[0])) { | ||||||
|         Py_INCREF(res); |             res = items[0]; | ||||||
|         Py_DECREF(fseq); |             Py_INCREF(res); | ||||||
|         return res; |             Py_DECREF(fseq); | ||||||
|     } |             return res; | ||||||
| 
 |         } | ||||||
|     /* Set up sep and seplen */ |         sep = NULL; | ||||||
|     if (separator == NULL) { |  | ||||||
|         /* fall back to a blank space separator */ |  | ||||||
|         sep = PyUnicode_FromOrdinal(' '); |  | ||||||
|         if (!sep) |  | ||||||
|             goto onError; |  | ||||||
|         maxchar = 32; |  | ||||||
|     } |     } | ||||||
|     else { |     else { | ||||||
|         if (!PyUnicode_Check(separator)) { |         /* Set up sep and seplen */ | ||||||
|             PyErr_Format(PyExc_TypeError, |         if (separator == NULL) { | ||||||
|                          "separator: expected str instance," |             /* fall back to a blank space separator */ | ||||||
|                          " %.80s found", |             sep = PyUnicode_FromOrdinal(' '); | ||||||
|                          Py_TYPE(separator)->tp_name); |             if (!sep) | ||||||
|             goto onError; |                 goto onError; | ||||||
|  |             maxchar = 32; | ||||||
|  |         } | ||||||
|  |         else { | ||||||
|  |             if (!PyUnicode_Check(separator)) { | ||||||
|  |                 PyErr_Format(PyExc_TypeError, | ||||||
|  |                              "separator: expected str instance," | ||||||
|  |                              " %.80s found", | ||||||
|  |                              Py_TYPE(separator)->tp_name); | ||||||
|  |                 goto onError; | ||||||
|  |             } | ||||||
|  |             if (PyUnicode_READY(separator)) | ||||||
|  |                 goto onError; | ||||||
|  |             sep = separator; | ||||||
|  |             seplen = PyUnicode_GET_LENGTH(separator); | ||||||
|  |             maxchar = PyUnicode_MAX_CHAR_VALUE(separator); | ||||||
|  |             /* inc refcount to keep this code path symmetric with the
 | ||||||
|  |                above case of a blank separator */ | ||||||
|  |             Py_INCREF(sep); | ||||||
|         } |         } | ||||||
|         if (PyUnicode_READY(separator)) |  | ||||||
|             goto onError; |  | ||||||
|         sep = separator; |  | ||||||
|         seplen = PyUnicode_GET_LENGTH(separator); |  | ||||||
|         maxchar = PyUnicode_MAX_CHAR_VALUE(separator); |  | ||||||
|         /* inc refcount to keep this code path symmetric with the
 |  | ||||||
|            above case of a blank separator */ |  | ||||||
|         Py_INCREF(sep); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /* There are at least two things to join, or else we have a subclass
 |     /* There are at least two things to join, or else we have a subclass
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner