mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	Fix embarrassing typo and fix constantification of None
This commit is contained in:
		
							parent
							
								
									117a05ed50
								
							
						
					
					
						commit
						20e1199fbe
					
				
					 2 changed files with 15 additions and 6 deletions
				
			
		| 
						 | 
					@ -49,6 +49,11 @@ def f(x):
 | 
				
			||||||
            self.assert_(elem not in asm)
 | 
					            self.assert_(elem not in asm)
 | 
				
			||||||
        for elem in ('LOAD_CONST', '(None)'):
 | 
					        for elem in ('LOAD_CONST', '(None)'):
 | 
				
			||||||
            self.assert_(elem in asm)
 | 
					            self.assert_(elem in asm)
 | 
				
			||||||
 | 
					        def f():
 | 
				
			||||||
 | 
					            'Adding a docstring made this test fail in Py2.5.0'
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					        self.assert_('LOAD_CONST' in disassemble(f))
 | 
				
			||||||
 | 
					        self.assert_('LOAD_GLOBAL' not in disassemble(f))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_while_one(self):
 | 
					    def test_while_one(self):
 | 
				
			||||||
        # Skip over:  LOAD_CONST trueconst  JUMP_IF_FALSE xx  POP_TOP
 | 
					        # Skip over:  LOAD_CONST trueconst  JUMP_IF_FALSE xx  POP_TOP
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,4 +1,4 @@
 | 
				
			||||||
/* Peehole optimizations for bytecode compiler. */
 | 
					/* Peephole optimizations for bytecode compiler. */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#include "Python.h"
 | 
					#include "Python.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -386,13 +386,17 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
 | 
				
			||||||
				if (name == NULL  ||  strcmp(name, "None") != 0)
 | 
									if (name == NULL  ||  strcmp(name, "None") != 0)
 | 
				
			||||||
					continue;
 | 
										continue;
 | 
				
			||||||
				for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {
 | 
									for (j=0 ; j < PyList_GET_SIZE(consts) ; j++) {
 | 
				
			||||||
					if (PyList_GET_ITEM(consts, j) == Py_None) {
 | 
										if (PyList_GET_ITEM(consts, j) == Py_None)
 | 
				
			||||||
						codestr[i] = LOAD_CONST;
 | 
					 | 
				
			||||||
						SETARG(codestr, i, j);
 | 
					 | 
				
			||||||
						cumlc = lastlc + 1;
 | 
					 | 
				
			||||||
						break;
 | 
											break;
 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									if (j == PyList_GET_SIZE(consts)) {
 | 
				
			||||||
 | 
										if (PyList_Append(consts, Py_None) == -1)
 | 
				
			||||||
 | 
										        goto exitUnchanged;                                        
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									assert(PyList_GET_ITEM(consts, j) == Py_None);
 | 
				
			||||||
 | 
									codestr[i] = LOAD_CONST;
 | 
				
			||||||
 | 
									SETARG(codestr, i, j);
 | 
				
			||||||
 | 
									cumlc = lastlc + 1;
 | 
				
			||||||
				break;
 | 
									break;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				/* Skip over LOAD_CONST trueconst
 | 
									/* Skip over LOAD_CONST trueconst
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue