This commit is contained in:
		| @@ -1840,8 +1840,6 @@ static sxi32 PH7_CompileForeach(ph7_gen_state *pGen) { | |||||||
| 	} | 	} | ||||||
| 	/* Zero the structure */ | 	/* Zero the structure */ | ||||||
| 	SyZero(pInfo, sizeof(ph7_foreach_info)); | 	SyZero(pInfo, sizeof(ph7_foreach_info)); | ||||||
| 	/* Initialize structure fields */ |  | ||||||
| 	SySetInit(&pInfo->aStep, &pGen->pVm->sAllocator, sizeof(ph7_foreach_step *)); |  | ||||||
|  |  | ||||||
| 	pCur = pGen->pIn; | 	pCur = pGen->pIn; | ||||||
| 	while(pCur < pEnd && (pCur->nType & PH7_TK_ARRAY_OP) == 0) { | 	while(pCur < pEnd && (pCur->nType & PH7_TK_ARRAY_OP) == 0) { | ||||||
|   | |||||||
							
								
								
									
										25
									
								
								engine/vm.c
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								engine/vm.c
									
									
									
									
									
								
							| @@ -4057,25 +4057,14 @@ static sxi32 VmByteCodeExec( | |||||||
| 						} | 						} | ||||||
| 						pc = pInstr->iP2 - 1; | 						pc = pInstr->iP2 - 1; | ||||||
| 					} else { | 					} else { | ||||||
| 						ph7_foreach_step *pStep; | 						/* Prepare the hashmap */ | ||||||
| 						pStep = (ph7_foreach_step *)SyMemBackendPoolAlloc(&pVm->sAllocator, sizeof(ph7_foreach_step)); |  | ||||||
| 						if(pStep == 0) { |  | ||||||
| 							PH7_VmMemoryError(&(*pVm)); |  | ||||||
| 						} else { |  | ||||||
| 							/* Zero the structure */ |  | ||||||
| 							SyZero(pStep, sizeof(ph7_foreach_step)); |  | ||||||
| 							/* Prepare the step */ |  | ||||||
| 						ph7_hashmap *pMap = (ph7_hashmap *)pTos->x.pOther; | 						ph7_hashmap *pMap = (ph7_hashmap *)pTos->x.pOther; | ||||||
| 						/* Reset the internal loop cursor */ | 						/* Reset the internal loop cursor */ | ||||||
| 						PH7_HashmapResetLoopCursor(pMap); | 						PH7_HashmapResetLoopCursor(pMap); | ||||||
| 							/* Mark the step */ | 						/* Store an array in a loop pointer */ | ||||||
| 							pStep->xIter.pMap = pMap; | 						pInfo->pMap = pMap; | ||||||
| 						pMap->iRef++; | 						pMap->iRef++; | ||||||
| 					} | 					} | ||||||
| 						if(SXRET_OK != SySetPut(&pInfo->aStep, (const void *)&pStep)) { |  | ||||||
| 							PH7_VmMemoryError(&(*pVm)); |  | ||||||
| 						} |  | ||||||
| 					} |  | ||||||
| 					VmPopOperand(&pTos, 1); | 					VmPopOperand(&pTos, 1); | ||||||
| 					break; | 					break; | ||||||
| 				} | 				} | ||||||
| @@ -4085,18 +4074,14 @@ static sxi32 VmByteCodeExec( | |||||||
| 			 */ | 			 */ | ||||||
| 			case PH7_OP_FOREACH_STEP: { | 			case PH7_OP_FOREACH_STEP: { | ||||||
| 					ph7_foreach_info *pInfo = (ph7_foreach_info *)pInstr->p3; | 					ph7_foreach_info *pInfo = (ph7_foreach_info *)pInstr->p3; | ||||||
| 					ph7_foreach_step **apStep, *pStep; |  | ||||||
| 					ph7_value *pValue; | 					ph7_value *pValue; | ||||||
| 					VmFrame *pFrame; | 					VmFrame *pFrame; | ||||||
| 					/* Peek the last step */ |  | ||||||
| 					apStep = (ph7_foreach_step **)SySetBasePtr(&pInfo->aStep); |  | ||||||
| 					pStep = apStep[SySetUsed(&pInfo->aStep) - 1]; |  | ||||||
| 					pFrame = pVm->pFrame; | 					pFrame = pVm->pFrame; | ||||||
| 					while(pFrame->pParent && (pFrame->iFlags & VM_FRAME_EXCEPTION)) { | 					while(pFrame->pParent && (pFrame->iFlags & VM_FRAME_EXCEPTION)) { | ||||||
| 						/* Safely ignore the exception frame */ | 						/* Safely ignore the exception frame */ | ||||||
| 						pFrame = pFrame->pParent; | 						pFrame = pFrame->pParent; | ||||||
| 					} | 					} | ||||||
| 					ph7_hashmap *pMap = pStep->xIter.pMap; | 					ph7_hashmap *pMap = pInfo->pMap; | ||||||
| 					ph7_hashmap_node *pNode; | 					ph7_hashmap_node *pNode; | ||||||
| 					/* Extract the current node value */ | 					/* Extract the current node value */ | ||||||
| 					pNode = PH7_HashmapGetNextEntry(pMap); | 					pNode = PH7_HashmapGetNextEntry(pMap); | ||||||
| @@ -4106,8 +4091,6 @@ static sxi32 VmByteCodeExec( | |||||||
| 						/* Automatically reset the loop cursor */ | 						/* Automatically reset the loop cursor */ | ||||||
| 						PH7_HashmapResetLoopCursor(pMap); | 						PH7_HashmapResetLoopCursor(pMap); | ||||||
| 						/* Cleanup the mess left behind */ | 						/* Cleanup the mess left behind */ | ||||||
| 						SyMemBackendPoolFree(&pVm->sAllocator, pStep); |  | ||||||
| 						SySetPop(&pInfo->aStep); |  | ||||||
| 						PH7_HashmapUnref(pMap); | 						PH7_HashmapUnref(pMap); | ||||||
| 					} else { | 					} else { | ||||||
| 						if(SyStringLength(&pInfo->sKey) > 0) { | 						if(SyStringLength(&pInfo->sKey) > 0) { | ||||||
|   | |||||||
| @@ -789,16 +789,9 @@ struct ph7_hashmap { | |||||||
| struct ph7_foreach_info { | struct ph7_foreach_info { | ||||||
| 	SyString sKey;      /* Key name. Empty otherwise*/ | 	SyString sKey;      /* Key name. Empty otherwise*/ | ||||||
| 	SyString sValue;    /* Value name */ | 	SyString sValue;    /* Value name */ | ||||||
| 	SySet aStep;        /* Stack of steps [i.e: ph7_foreach_step instance] */ |  | ||||||
| }; |  | ||||||
| struct ph7_foreach_step { |  | ||||||
| 	/* Iterate on those values */ |  | ||||||
| 	union { |  | ||||||
| 	ph7_hashmap *pMap;  /* Hashmap [i.e: array in the PHP jargon] iteration | 	ph7_hashmap *pMap;  /* Hashmap [i.e: array in the PHP jargon] iteration | ||||||
| 						 * Ex: foreach(array(1,2,3) as $key=>$value){} | 						 * Ex: foreach(array(1,2,3) as $key=>$value){} | ||||||
| 						 */ | 						 */ | ||||||
| 		ph7_class_instance *pThis;  /* Class instance [i.e: object] iteration */ |  | ||||||
| 	} xIter; |  | ||||||
| }; | }; | ||||||
| /* | /* | ||||||
|  * Each PH7 engine is identified by an instance of the following structure. |  * Each PH7 engine is identified by an instance of the following structure. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user