mirror of
				https://github.com/python/cpython.git
				synced 2025-11-01 06:01:29 +00:00 
			
		
		
		
	Fix gdb/libpython.py for not ready Unicode strings
_PyUnicode_CheckConsistency() checks also hash and length value for not ready Unicode strings.
This commit is contained in:
		
							parent
							
								
									2fc507fe45
								
							
						
					
					
						commit
						e30c0a1014
					
				
					 3 changed files with 10 additions and 10 deletions
				
			
		|  | @ -231,22 +231,24 @@ typedef struct { | |||
|          * utf8_length = 0 if utf8 is NULL | ||||
|          * wstr is shared with data and wstr_length=length | ||||
|            if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2 | ||||
|            or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4 | ||||
|            or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_t)=4 | ||||
|          * wstr_length = 0 if wstr is NULL | ||||
|          * (data starts just after the structure) | ||||
| 
 | ||||
|        - legacy string, not ready: | ||||
| 
 | ||||
|          * structure = PyUnicodeObject | ||||
|          * length = 0 (use wstr_length) | ||||
|          * hash = -1 | ||||
|          * kind = PyUnicode_WCHAR_KIND | ||||
|          * compact = 0 | ||||
|          * ascii = 0 | ||||
|          * ready = 0 | ||||
|          * interned = SSTATE_NOT_INTERNED | ||||
|          * wstr is not NULL | ||||
|          * data.any is NULL | ||||
|          * utf8 is NULL | ||||
|          * utf8_length = 0 | ||||
|          * interned = SSTATE_NOT_INTERNED | ||||
| 
 | ||||
|        - legacy string, ready: | ||||
| 
 | ||||
|  | @ -258,7 +260,7 @@ typedef struct { | |||
|          * data.any is not NULL | ||||
|          * utf8 is shared and utf8_length = length with data.any if ascii = 1 | ||||
|          * utf8_length = 0 if utf8 is NULL | ||||
|          * wstr is shared and wstr_length = length with data.any | ||||
|          * wstr is shared with data.any and wstr_length = length | ||||
|            if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2 | ||||
|            or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4 | ||||
|          * wstr_length = 0 if wstr is NULL | ||||
|  |  | |||
|  | @ -328,18 +328,21 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content) | |||
|             assert(ascii->state.ascii == 0); | ||||
|             assert(ascii->state.ready == 1); | ||||
|             assert (compact->utf8 != data); | ||||
|         } else { | ||||
|         } | ||||
|         else { | ||||
|             PyUnicodeObject *unicode = (PyUnicodeObject *)op; | ||||
| 
 | ||||
|             data = unicode->data.any; | ||||
|             if (kind == PyUnicode_WCHAR_KIND) { | ||||
|                 assert(ascii->length == 0); | ||||
|                 assert(ascii->hash == -1); | ||||
|                 assert(ascii->state.compact == 0); | ||||
|                 assert(ascii->state.ascii == 0); | ||||
|                 assert(ascii->state.ready == 0); | ||||
|                 assert(ascii->state.interned == SSTATE_NOT_INTERNED); | ||||
|                 assert(ascii->wstr != NULL); | ||||
|                 assert(data == NULL); | ||||
|                 assert(compact->utf8 == NULL); | ||||
|                 assert(ascii->state.interned == SSTATE_NOT_INTERNED); | ||||
|             } | ||||
|             else { | ||||
|                 assert(kind == PyUnicode_1BYTE_KIND | ||||
|  |  | |||
|  | @ -1123,9 +1123,6 @@ def char_width(self): | |||
|         return _type_Py_UNICODE.sizeof | ||||
| 
 | ||||
|     def proxyval(self, visited): | ||||
|         # From unicodeobject.h: | ||||
|         #     Py_ssize_t length;  /* Length of raw Unicode data in buffer */ | ||||
|         #     Py_UNICODE *str;    /* Raw Unicode buffer */ | ||||
|         if _is_pep393: | ||||
|             # Python 3.3 and newer | ||||
|             may_have_surrogates = False | ||||
|  | @ -1138,8 +1135,6 @@ def proxyval(self, visited): | |||
|                 # string is not ready | ||||
|                 may_have_surrogates = True | ||||
|                 field_str = ascii['wstr'] | ||||
|                 if not is_compact_ascii: | ||||
|                     field_length = compact('wstr_length') | ||||
|             else: | ||||
|                 if is_compact_ascii: | ||||
|                     field_str = ascii.address + 1 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Victor Stinner
						Victor Stinner