summaryrefslogtreecommitdiff
path: root/processor/processor.m4
blob: 03eaef7d182d21393baae94985dab2aa382bff86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
dnl ================
/* {{{ Pre-declare */
DECL_STRUCT_P_FUNC(`zval')
DECL_STRUCT_P_FUNC(`zval_ptr')
DECL_STRUCT_P_FUNC(`zval_ptr_nullable')
DECL_STRUCT_P_FUNC(`zend_op_array')
DECL_STRUCT_P_FUNC(`zend_class_entry')
#ifdef HAVE_XCACHE_CONSTANT
DECL_STRUCT_P_FUNC(`zend_constant')
#endif
DECL_STRUCT_P_FUNC(`zend_function')
DECL_STRUCT_P_FUNC(`xc_entry_var_t')
DECL_STRUCT_P_FUNC(`xc_entry_php_t')
#ifdef ZEND_ENGINE_2
DECL_STRUCT_P_FUNC(`zend_property_info')
#endif
/* }}} */
dnl ====================================================
#ifdef IS_CV
DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `dnl {{{
	PROCESS(int, name_len)
	PROC_ZSTRING_L(, name, name_len)
	PROCESS(ulong, hash_value)
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{
	IFCOPY(`DST()[0] = SRC()[0];')
	IFDPRINT(`
		INDENT()
		fprintf(stderr, "%u\n", SRC()[0]);
	')
	DONE_SIZE(sizeof(SRC()[0]))
')
dnl }}}
#ifndef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`int', , `dnl {{{
	IFCOPY(`*DST() = *SRC();')
	IFDPRINT(`
		INDENT()
		fprintf(stderr, "%d\n", SRC()[0]);
	')
	DONE_SIZE(sizeof(SRC()[0]))
')
dnl }}}
#endif
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{
	PROCESS(zend_uint, try_op)
	PROCESS(zend_uint, catch_op)
#ifdef ZEND_ENGINE_2_5
	PROCESS(zend_uint, finally_op)
	PROCESS(zend_uint, finally_end)
#endif
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
#ifdef ZEND_ENGINE_2_2
	PROCESS(int, start)
#endif
	PROCESS(int, cont)
	PROCESS(int, brk)
	PROCESS(int, parent)
')
dnl }}}
DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr',           `zval_ptr')
DEF_HASH_TABLE_FUNC(`HashTable_zend_function',      `zend_function')
#ifdef ZEND_ENGINE_2
DEF_HASH_TABLE_FUNC(`HashTable_zend_property_info', `zend_property_info')
#endif
#ifdef IS_CONSTANT_AST
define(`ZEND_AST_HELPER', `dnl {{{
{
	IFCALCCOPY(`
		size_t zend_ast_size = ($1->kind == ZEND_CONST)
		 ? sizeof(zend_ast) + sizeof(zval)
		 : sizeof(zend_ast) + sizeof(zend_ast *) * ($1->children - 1);
	')

	pushdef(`ALLOC_SIZE_HELPER', `zend_ast_size')
	$2
	popdef(`ALLOC_SIZE_HELPER')
}
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_ast', , `dnl {{{
		zend_ushort i;
		PROCESS(zend_ushort, kind)
		PROCESS(zend_ushort, children)
		DONE(u)
		DISABLECHECK(`
			if (SRC()->kind == ZEND_CONST) {
				assert(SRC()->u.val);
				IFCOPY(`
					DST()->u.val = (zval *) (DST() + 1);
					memcpy(DST()->u.val, SRC()->u.val, sizeof(zval));
				')
				STRUCT_P_EX(zval, DST()->u.val, SRC()->u.val, `[]', `', ` ')
				RELOCATE_EX(zval, DST()->u.val)
			}
			else {
				for (i = 0; i < SRC()->children; ++i) {
					zend_ast *src_ast = (&SRC()->u.child)[i];
					if (src_ast) {
						ZEND_AST_HELPER(`src_ast', `
							ALLOC(`(&DST()->u.child)[i]', zend_ast)
							STRUCT_P_EX(zend_ast, (&DST()->u.child)[i], src_ast, `[]', `', ` ')
						')
						RELOCATE_EX(zend_ast, (&DST()->u.child)[i])
					}
					else {
						SETNULL_EX(`(&DST()->u.child)[i]', `[]')
					}
				}
			}
		')
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_object', , `dnl {{{
	IFCALC(`
		xc_var_collect_class(processor, SRC(ce) TSRMLS_CC);
		DONE(ce)
	', `IFSTORE(`
		DST(ce) = (zend_class_entry *) xc_var_store_ce(processor, SRC(ce) TSRMLS_CC);
		DONE(ce)
	', `IFRESTORE(`
		assert(processor->index_to_ce);
		DST(ce) = processor->index_to_ce[(size_t) SRC(ce)];
		DONE(ce)
	', `
		PROCESS_SCALAR(ce, lu, unsigned long)
	')')')

	STRUCT_P(HashTable, properties, HashTable_zval_ptr)
#ifdef ZEND_ENGINE_2_4
	dnl TODO: how to rebuild properties_table
	STRUCT_ARRAY(int, IFRESTORE(`DST(`ce->default_properties_count')', `SRC(`ce->default_properties_count')'), zval_ptr, properties_table)
#endif
#ifdef ZEND_ENGINE_2
	COPYNULL(`guards')
#endif
')
dnl }}}
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_object_value', , `dnl {{{
	IFCALC(`
		xc_var_collect_object(processor, SRC(handle) TSRMLS_CC);
		DONE(handle)
	', `IFSTORE(`
		DST(handle) = (zend_object_handle) xc_var_store_handle(processor, SRC(handle) TSRMLS_CC);
		DONE(handle)
	', `IFRESTORE(`
		DST(handle) = xc_var_restore_handle(processor, (size_t) SRC(handle) TSRMLS_CC);
		DONE(handle)
	', `
		PROCESS(zend_object_handle, handle)
	')')')
	COPY(handlers)
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zval', , `dnl {{{
	IFDASM(`do {
		zval_dtor(DST());
		*DST() = *SRC();
		zval_copy_ctor(DST());
		Z_SET_REFCOUNT(*DST(), 1);
		DONE(value)
		DONE(type)
#ifdef ZEND_ENGINE_2_3
		DONE(is_ref__gc)
		DONE(refcount__gc)
#else
		DONE(is_ref)
		DONE(refcount)
#endif
	} while(0);
	', `
		dnl IFDASM else
		/* Variable information */
dnl {{{ zvalue_value
		DISABLECHECK(`
		switch ((Z_TYPE_P(SRC()) & IS_CONSTANT_TYPE_MASK)) {
			case IS_LONG:
			case IS_BOOL:
				PROCESS(long, value.lval)
				break;
			case IS_DOUBLE:
				PROCESS(double, value.dval)
				break;
			case IS_NULL:
				IFDPRINT(`INDENT()`'fprintf(stderr, "\tNULL\n");')
				break;

			case IS_CONSTANT:
#ifdef IS_UNICODE
				if (UG(unicode)) {
					goto proc_unicode;
				}
#endif
			case IS_STRING:
#ifdef FLAG_IS_BC
			case FLAG_IS_BC:
#endif
				PROCESS(int, value.str.len)
				IFRESTORE(`
					TRACE("%p, %p, %d", src->value.str.val, processor->entry_php_src->filepath.str, src->value.str.val == processor->entry_php_src->filepath.str);
				')
				PROC_STRING_L(value.str.val, value.str.len)
				dnl IFSTORE(`
				dnl 	TRACE("%s, %d", dst->value.str.val, dst->value.str.val == processor->entry_php_dst->filepath.str);
				dnl ')
				break;
#ifdef IS_UNICODE
			case IS_UNICODE:
proc_unicode:
				PROCESS(int32_t, value.uni.len)
				PROC_ZSTRING_L(1, value.uni.val, value.uni.len)
				break;
#endif

			case IS_ARRAY:
#ifdef IS_CONSTANT_ARRAY
			case IS_CONSTANT_ARRAY:
#endif
				assert(SRC()->value.ht);
				STRUCT_P(HashTable, value.ht, HashTable_zval_ptr)
				break;

#ifdef IS_CONSTANT_AST
			case IS_CONSTANT_AST:
				assert(SRC()->value.ast);
				ZEND_AST_HELPER(`SRC()->value.ast', `STRUCT_P(zend_ast, value.ast)')
				break;
#endif

			case IS_OBJECT:
#ifdef ZEND_ENGINE_2
				STRUCT(zend_object_value, value.obj)
#else
				STRUCT(zend_object, value.obj)
#endif
				break;

			default:
				/* IS_RESOURCE */
				IFCOPY(`Z_TYPE_P(DST()) = IS_LONG;')
				PROCESS(long, value.lval)
				break;
		}
		')
dnl }}}
		DONE(value)
		PROCESS(xc_zval_type_t, type)
#ifdef ZEND_ENGINE_2_3
		PROCESS(zend_uchar, is_ref__gc)
#else
		PROCESS(zend_uchar, is_ref)
#endif

#ifdef ZEND_ENGINE_2_3
		PROCESS(zend_uint, refcount__gc)
#elif defined(ZEND_ENGINE_2)
		PROCESS(zend_uint, refcount)
#else
		PROCESS(zend_ushort, refcount)
#endif
	')dnl IFDASM
')
dnl }}}
DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
	IFDASM(`
		pushdefFUNC_NAME(`zval')
		FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
		popdef(`FUNC_NAME')
	', `
		do {
			IFCALCCOPY(`
				if (processor->handle_reference) {
					zval_ptr *ppzv;
					if (zend_hash_find(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void **) &ppzv) == SUCCESS) {
						IFCOPY(`
							DST()[0] = *ppzv;
							IFSTORE(`
								Z_ADDREF(**DST());
								TRACE("add refcount to %d", Z_REFCOUNT(**DST()));
							')
							/* *DST() is updated */
							TRACE("*DST() is set to %p, PROCESSOR_TYPE is_shm %d", (void *) DST()[0], xc_is_shm(DST()[0]));
						')
						IFCALCSTORE(`processor->have_references = 1;')
						IFSTORE(`assert(xc_is_shm(DST()[0]));')
						IFRESTORE(`assert(!xc_is_shm(DST()[0]));')
						break;
					}
				}
			')
			
			ALLOC(DST()[0], zval)
			IFCALCCOPY(`
				if (processor->handle_reference) {
					IFCALC(`
						/* make dummy */
						zval_ptr pzv = (zval_ptr)-1;
					', `
						zval_ptr pzv = DST()[0];
						RELOCATE_EX(zval, pzv)
					')
					if (zend_hash_add(&processor->zvalptrs, (char *) &SRC()[0], sizeof(SRC()[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) { /* first add, go on */
						dnl IFSTORE(`fprintf(stderr, "mark[%p] = %p\n", (void *) SRC()[0], (void *) pzv);')
					}
					else {
						assert(0);
					}
				}
			')
			IFCOPY(`
				TRACE("copy from %p to %p", SRC()[0], DST()[0]);
			')
			IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", (void *) SRC()[0]);')
			STRUCT_P_EX(zval, DST()[0], SRC()[0], `[0]', `', ` ')
			dnl set refcount here instead of struct zval?
			IFSTORE(`
				Z_SET_REFCOUNT(**DST(), 1);
				TRACE("set refcount to %d", Z_REFCOUNT(**DST()));
			')
			RELOCATE_EX(zval, DST()[0])
		} while (0);
	')
	DONE_SIZE(sizeof(zval_ptr))
')
dnl }}}
DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{
	if (SRC()[0]) {
		pushdef(`DASM_STRUCT_DIRECT')
		STRUCT_P_EX(zval_ptr, DST(), SRC(), `', `', ` ')
		popdef(`DASM_STRUCT_DIRECT')
	}
	else {
		IFCOPY(`COPYNULL_EX(DST()[0], SRC())')
	}
	DONE_SIZE(sizeof(zval_ptr_nullable))
')
dnl }}}
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
	PROCESS(zend_uint, name_len)
	PROC_ZSTRING_L(, name, name_len)
	PROCESS(zend_uint, class_name_len)
	PROC_ZSTRING_L(, class_name, class_name_len)
#ifdef ZEND_ENGINE_2_4
	PROCESS(zend_uchar, type_hint)
#elif defined(ZEND_ENGINE_2_1)
	PROCESS(zend_bool, array_type_hint)
#endif
#ifdef ZEND_ENGINE_2_6
	PROCESS(zend_uchar, pass_by_reference)
#endif
	PROCESS(zend_bool, allow_null)

#ifdef ZEND_ENGINE_2_6
	PROCESS(zend_bool, is_variadic)
#else
	PROCESS(zend_bool, pass_by_reference)
#endif

#ifndef ZEND_ENGINE_2_4
	PROCESS(zend_bool, return_reference)
	PROCESS(int, required_num_args)
#endif
')
dnl }}}
#endif
#ifdef HAVE_XCACHE_CONSTANT
DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
	STRUCT(zval, value)
	PROCESS(int, flags)
	PROCESS(uint, name_len)
	pushdef(`estrndup', `zend_strndup')
	PROC_ZSTRING_N(, name, name_len)
	popdef(`estrndup')
	PROCESS(int, module_number)
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{
	DISABLECHECK(`
	switch (SRC(`type')) {
	case ZEND_INTERNAL_FUNCTION:
	case ZEND_OVERLOADED_FUNCTION:
		IFNOTMEMCPY(`IFCOPY(`memcpy(DST(), SRC(), sizeof(SRC()[0]));')')
		break;

	case ZEND_USER_FUNCTION:
	case ZEND_EVAL_CODE:
		DONE(type)
		STRUCT(zend_op_array, op_array)
		break;

	default:
		assert(0);
	}
	')
	DONE_SIZE(sizeof(SRC()[0]))
')
dnl }}}
#ifdef ZEND_ENGINE_2
DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
	PROCESS(zend_uint, flags)
	PROCESS(int, name_length)
	PROC_ZSTRING_L(, name, name_length)
	PROCESS(ulong, h)
#ifdef ZEND_ENGINE_2_4
	PROCESS(int, offset)
#endif
#ifdef ZEND_ENGINE_2_1
	PROCESS(int, doc_comment_len)
	PROC_ZSTRING_L(, doc_comment, doc_comment_len)
#endif
	dnl isnt in php6 yet
#if defined(ZEND_ENGINE_2_2)
	PROC_CLASS_ENTRY_P(ce)
#endif
')
dnl }}}
#endif
#ifdef ZEND_ENGINE_2_4
DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
	PROCESS(unsigned int, mname_len)
	PROC_STRING_L(method_name, mname_len)
	COPYNULL(ce)
	PROCESS(unsigned int, cname_len)
	PROC_STRING_L(class_name, cname_len)
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
	STRUCT_P(zend_trait_method_reference, trait_method)
	PROCESS(unsigned int, alias_len)
	PROC_STRING_L(alias, alias_len)
	PROCESS(zend_uint, modifiers)
#ifndef ZEND_ENGINE_2_5
	COPYNULL(function)
#endif
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
	STRUCT_P(zend_trait_method_reference, trait_method)
	PROCESS_ARRAY(, xc_ztstring, exclude_from_classes, zend_class_entry*)
#ifndef ZEND_ENGINE_2_5
	COPYNULL(function)
#endif
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
	IFDASM(`
		pushdefFUNC_NAME(`zend_trait_alias')
		FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
		popdef(`FUNC_NAME')
	', `
		ALLOC(DST()[0], zend_trait_alias)
		STRUCT_P_EX(zend_trait_alias, DST()[0], SRC()[0], `[0]', `', ` ')
		RELOCATE_EX(zend_trait_alias, DST()[0])
	')
	DONE_SIZE(sizeof(zend_trait_alias))
')
dnl }}}
DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
	IFDASM(`
		pushdefFUNC_NAME(`zend_trait_precedence')
		FUNC_NAME (dasm, DST(), SRC()[0] TSRMLS_CC);
		popdef(`FUNC_NAME')
	', `
		ALLOC(DST()[0], zend_trait_precedence)
		STRUCT_P_EX(zend_trait_precedence, DST()[0], SRC()[0], `[0]', `', ` ')
		RELOCATE_EX(zend_trait_precedence, DST()[0])
	')
	DONE_SIZE(sizeof(zend_trait_precedence))
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
	IFCALCCOPY(`
		processor->active_class_entry_src = SRC();
		IFCOPY(`processor->active_class_entry_dst = DST();')
	')
	PROCESS(char, type)
	PROCESS(zend_uint, name_length)
	PROC_ZSTRING_L(, name, name_length)
	IFRESTORE(`
#ifndef ZEND_ENGINE_2
		/* just copy parent and resolve on install_class */
		COPYPOINTER(parent)
#else
		PROC_CLASS_ENTRY_P(parent)
#endif
	', `
		PROC_CLASS_ENTRY_P(parent)
	')
#ifdef ZEND_ENGINE_2
	PROCESS(int, refcount)
#else
	STRUCT_P(int, refcount)
#endif
#ifndef ZEND_ENGINE_2_4
	PROCESS(zend_bool, constants_updated)
#endif
#ifdef ZEND_ENGINE_2
	PROCESS(zend_uint, ce_flags)
#endif

#ifdef ZEND_ENGINE_2
	STRUCT(HashTable, properties_info, HashTable_zend_property_info)
#endif

#ifdef ZEND_ENGINE_2_4
	STRUCT_ARRAY(int, SRC(`default_properties_count'), zval_ptr_nullable, default_properties_table)
	PROCESS(int, default_properties_count)
	STRUCT_ARRAY(int, SRC(`default_static_members_count'), zval_ptr_nullable, default_static_members_table)
	PROCESS(int, default_static_members_count)
	IFCOPY(`DST(`static_members_table') = DST(`default_static_members_table');')
	DONE(static_members_table)
#else
	IFCOPY(`DST(`builtin_functions') = SRC(`builtin_functions');')
	DONE(builtin_functions)
	STRUCT(HashTable, default_properties, HashTable_zval_ptr)
#	ifdef ZEND_ENGINE_2_1
	STRUCT(HashTable, default_static_members, HashTable_zval_ptr)
	IFCOPY(`DST(`static_members') = &DST(`default_static_members');')
	DONE(static_members)
#	elif defined(ZEND_ENGINE_2)
	STRUCT_P(HashTable, static_members, HashTable_zval_ptr)
#	endif
#endif /* ZEND_ENGINE_2_4 */

#ifdef ZEND_ENGINE_2
	STRUCT(HashTable, constants_table, HashTable_zval_ptr)

#ifdef ZEND_ENGINE_2_2
	dnl runtime binding: ADD_INTERFACE will deal with it
	COPYNULL(`interfaces')
	COPYZERO(`num_interfaces')

#	ifdef ZEND_ENGINE_2_4
	dnl runtime binding: ADD_TRAIT will deal with it
	COPYNULL(traits)
	COPYZERO(num_traits)
	STRUCT_ARRAY(, , zend_trait_alias_ptr, trait_aliases)
	STRUCT_ARRAY(, , zend_trait_precedence_ptr, trait_precedences)
#	endif
#else
	IFRESTORE(`
		if (SRC(`num_interfaces')) {
			CALLOC(DST(`interfaces'), zend_class_entry*, SRC(`num_interfaces'))
			DONE(`interfaces')
		}
		else {
			COPYNULL(`interfaces')
		}
	', `
		DONE(`interfaces')
	')
	PROCESS(zend_uint, num_interfaces)
#endif

#	ifdef ZEND_ENGINE_2_4
	DISABLECHECK(`
	IFRESTORE(`DST(`info.user.filename') = processor->entry_php_src->filepath.str;', `PROC_STRING(info.user.filename)')
	PROCESS(zend_uint, info.user.line_start)
	PROCESS(zend_uint, info.user.line_end)
	PROCESS(zend_uint, info.user.doc_comment_len)
	PROC_ZSTRING_L(, info.user.doc_comment, info.user.doc_comment_len)
	')
	DONE(info)
#	else
	IFRESTORE(`DST(`filename') = processor->entry_php_src->filepath.str;DONE(filename)', `PROC_STRING(filename)')
	PROCESS(zend_uint, line_start)
	PROCESS(zend_uint, line_end)
	PROCESS(zend_uint, doc_comment_len)
	PROC_ZSTRING_L(, doc_comment, doc_comment_len)
#	endif

	/* # NOT DONE */
#	ifdef ZEND_ENGINE_2_1
	PROCESS_CTEXTPOINTER(serialize_func)
	PROCESS_CTEXTPOINTER(unserialize_func)
#	endif
	PROCESS_CTEXTPOINTER(iterator_funcs)
	PROCESS_CTEXTPOINTER(create_object)
	PROCESS_CTEXTPOINTER(get_iterator)
	PROCESS_CTEXTPOINTER(interface_gets_implemented)
#	ifdef ZEND_ENGINE_2_3
	PROCESS_CTEXTPOINTER(get_static_method)
#	endif
#	ifdef ZEND_ENGINE_2_1
	PROCESS_CTEXTPOINTER(serialize)
	PROCESS_CTEXTPOINTER(unserialize)
#	endif
	/* deal with it inside xc_fix_method */
	SETNULL(constructor)
	PROCESS_CTEXTPOINTER(destructor)
	PROCESS_CTEXTPOINTER(clone)
	PROCESS_CTEXTPOINTER(__get)
	PROCESS_CTEXTPOINTER(__set)
/* should be >5.1 */
#	ifdef ZEND_ENGINE_2_1
	PROCESS_CTEXTPOINTER(__unset)
	PROCESS_CTEXTPOINTER(__isset)
#	endif
	PROCESS_CTEXTPOINTER(__call)
#	ifdef ZEND_CALLSTATIC_FUNC_NAME
	PROCESS_CTEXTPOINTER(__callstatic)
#	endif
# if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
	PROCESS_CTEXTPOINTER(__tostring)
# endif
# if defined(ZEND_ENGINE_2_6)
	PROCESS_CTEXTPOINTER(__debugInfo)
# endif
#	ifndef ZEND_ENGINE_2_4
	/* # NOT DONE */
	PROCESS_CTEXTPOINTER(module)
#	endif
#else /* ZEND_ENGINE_2 */
	PROCESS_CTEXTPOINTER(handle_function_call)
	PROCESS_CTEXTPOINTER(handle_property_get)
	PROCESS_CTEXTPOINTER(handle_property_set)
#endif
	dnl must do after SETNULL(constructor) and DST()->parent
	STRUCT(HashTable, function_table, HashTable_zend_function)
	IFRESTORE(`DST(`function_table.pDestructor') = ZEND_FUNCTION_DTOR;')
	IFCALCCOPY(`
		processor->active_class_entry_src = NULL;
		IFCOPY(`processor->active_class_entry_dst = NULL;')
	')
')
dnl }}}
#ifdef ZEND_ENGINE_2_4
undefine(`UNION_znode_op')
define(`UNION_znode_op', `dnl {{{
#ifndef NDEBUG
	switch ((SRC(`$1_type') ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
	case IS_CONST:
	case IS_VAR:
	case IS_CV:
	case IS_TMP_VAR:
	case IS_UNUSED:
		break;

	default:
		assert(0);
	}
#endif

	dnl dirty dispatch
	DISABLECHECK(`
	switch ((SRC(`$1_type') ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
		case IS_CONST:
			ifelse($1, `result', `
				PROCESS(zend_uint, $1.constant)
			', `
				IFDASM(`{
					zval *zv;
					zval *srczv;
					PROCESS(zend_uint, $1.var)
					if (SRC(`$1.constant') < dasm->active_op_array_src->last_literal) {
						srczv = &dasm->active_op_array_src->literals[SRC(`$1.constant')].constant;
						ALLOC_ZVAL(zv);
						MAKE_COPY_ZVAL(&srczv, zv);
						add_assoc_zval_ex(DST(), XCACHE_STRS("$1.constant"), zv);
					}
					else {
						dnl fprintf(stderr, "opcode %s $1 want literal %d\n", xc_get_opcode(SRC(`opcode')), SRC(`$1.constant'));
					}
				}
				', `
					IFCOPY(`
						DST(`$1') = SRC(`$1');
					', `
						PROCESS(zend_uint, $1.constant)
					')
				')
			')
			break;
		IFCOPY(`
			IFNOTMEMCPY(`
				default:
					DST(`$1') = SRC(`$1');
			')
		', `
		case IS_VAR:
		case IS_TMP_VAR:
			IFDASM(`
#ifdef ZEND_ENGINE_2_5
				add_assoc_long_ex(DST(), XCACHE_STRS("$1.var"), (temp_variable *)0 - (temp_variable *)((int) SRC($1.var)) - 1);
				break;
#endif
			', `
				/* no break */
			')
		case IS_CV:
			PROCESS(zend_uint, $1.var)
			break;
		case IS_UNUSED:
			IFDASM(`PROCESS(zend_uint, $1.var)')
			PROCESS(zend_uint, $1.opline_num)
			break;
		')
	}
	')
	DONE($1)
')
dnl }}}
#else
DEF_STRUCT_P_FUNC(`znode', , `dnl {{{
	PROCESS(xc_op_type, op_type)

#ifdef IS_CV
#	define XCACHE_IS_CV IS_CV
#else
/* compatible with zend optimizer */
#	define XCACHE_IS_CV 16
#endif
	assert(SRC(`op_type') == IS_CONST ||
		SRC(`op_type') == IS_VAR ||
		SRC(`op_type') == XCACHE_IS_CV ||
		SRC(`op_type') == IS_TMP_VAR ||
		SRC(`op_type') == IS_UNUSED);
	dnl dirty dispatch
	DISABLECHECK(`
	switch (SRC(`op_type')) {
		case IS_CONST:
			STRUCT(zval, u.constant)
			break;
		IFCOPY(`
			IFNOTMEMCPY(`
				default:
					DST(`u') = SRC(`u');
			')
		', `
		case IS_VAR:
		case IS_TMP_VAR:
		case XCACHE_IS_CV:
			PROCESS(zend_uint, u.var)
			PROCESS(zend_uint, u.EA.type)
			break;
		case IS_UNUSED:
			IFDASM(`PROCESS(zend_uint, u.var)')
			PROCESS(zend_uint, u.opline_num)
#ifndef ZEND_ENGINE_2
			PROCESS(zend_uint, u.fetch_type)
#endif
			PROCESS(zend_uint, u.EA.type)
			break;
		')
	}
	')
	DONE(u)
#if 0
	DONE(EA)
#endif
#undef XCACHE_IS_CV
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
	PROCESS(xc_opcode, opcode)
#ifdef ZEND_ENGINE_2_4
	IFRESTORE(`', `
	switch (SRC(`opcode')) {
	case ZEND_BIND_TRAITS:
		((zend_op *) SRC())->op2_type = IS_UNUSED;
		break;
	}
	')
	UNION_znode_op(result)
	UNION_znode_op(op1)
	UNION_znode_op(op2)
#else
	STRUCT(znode, result)
	STRUCT(znode, op1)
	STRUCT(znode, op2)
#endif
	PROCESS(ulong, extended_value)
	PROCESS(uint, lineno)
#ifdef ZEND_ENGINE_2_4
	PROCESS(zend_uchar, op1_type)
	PROCESS(zend_uchar, op2_type)
	PROCESS(zend_uchar, result_type)
#endif
	IFCOPY(`
		assert(processor->active_op_array_src);
		assert(processor->active_op_array_dst);
#ifdef ZEND_ENGINE_2_4
		pushdef(`UNION_znode_op_literal', `
			if (SRC(`$1_type') == IS_CONST) {
				DST(`$1').constant = SRC(`$1.literal') - processor->active_op_array_src->literals;
				DST(`$1').literal = &processor->active_op_array_dst->literals[DST(`$1').constant];
			}
		')
		UNION_znode_op_literal(op1)
		UNION_znode_op_literal(op2)
#endif
		popdef(`UNION_znode_op_literal')
#ifdef ZEND_ENGINE_2
		switch (SRC(`opcode')) {
#	ifdef ZEND_GOTO
			case ZEND_GOTO:
#	endif
			case ZEND_JMP:
#	ifdef ZEND_FAST_CALL
			case ZEND_FAST_CALL:
#	endif
				assert(Z_OP(SRC(`op1')).jmp_addr >= processor->active_op_array_src->opcodes);
				assert(Z_OP(SRC(`op1')).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
				Z_OP(DST(`op1')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op1')).jmp_addr - processor->active_op_array_src->opcodes);
				assert(Z_OP(DST(`op1')).jmp_addr >= processor->active_op_array_dst->opcodes);
				assert(Z_OP(DST(`op1')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
				RELOCATE_EX(zend_op, `Z_OP(DST(`op1')).jmp_addr')
				break;

			case ZEND_JMPZ:
			case ZEND_JMPNZ:
			case ZEND_JMPZ_EX:
			case ZEND_JMPNZ_EX:
#	ifdef ZEND_JMP_SET
			case ZEND_JMP_SET:
#	endif
#	ifdef ZEND_JMP_SET_VAR
			case ZEND_JMP_SET_VAR:
#	endif
				assert(Z_OP(SRC(`op2')).jmp_addr >= processor->active_op_array_src->opcodes);
				assert(Z_OP(SRC(`op2')).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
				Z_OP(DST(`op2')).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(SRC(`op2')).jmp_addr - processor->active_op_array_src->opcodes);
				assert(Z_OP(DST(`op2')).jmp_addr >= processor->active_op_array_dst->opcodes);
				assert(Z_OP(DST(`op2')).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
				RELOCATE_EX(zend_op, `Z_OP(DST(`op2')).jmp_addr')
				break;

			default:
				break;
		}
#	endif
	')
#ifdef ZEND_ENGINE_2
	PROCESS(opcode_handler_t, handler)
#endif
')
dnl }}}
#ifdef ZEND_ENGINE_2_4
DEF_STRUCT_P_FUNC(`zend_literal', , `dnl {{{
	STRUCT(zval, constant)
	PROCESS(zend_ulong, hash_value)
	PROCESS(zend_uint,  cache_slot)
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
	IFCOPY(`
		processor->active_op_array_dst = DST();
		processor->active_op_array_src = SRC();
	')
	IFDASM(`
		dasm->active_op_array_src = SRC();
	')
	{
	IFRESTORE(`
	const xc_op_array_info_t *op_array_info = &processor->active_op_array_infos_src[processor->active_op_array_index++];
	dnl shadow copy must NOT meet:
	dnl readonly_protection=on
	dnl main op_array && have early binding
#ifdef ZEND_COMPILE_DELAYED_BINDING
	zend_bool need_early_binding = 0;
#else
	zend_bool need_early_binding = processor->php_src->have_early_binding;
#endif
	zend_bool shallow_copy = !processor->readonly_protection && !(SRC() == processor->php_src->op_array && need_early_binding);
	if (shallow_copy) {
		zend_bool gc_arg_info = 0;
		zend_bool gc_opcodes  = 0;
#ifdef ZEND_ENGINE_2_4
		zend_bool gc_literals = 0;
#endif
		/* really fast shallow copy */
		memcpy(DST(), SRC(), sizeof(SRC()[0]));
		DST(`refcount') = &XG(op_array_dummy_refcount_holder);
		XG(op_array_dummy_refcount_holder) = ((zend_uint) -1) / 2;
#ifdef ZEND_ACC_ALIAS
		if ((processor->active_class_entry_src && (processor->active_class_entry_src->ce_flags & ZEND_ACC_TRAIT))) {
			PROC_ZSTRING(, function_name)
		}
#endif
		/* deep */
		STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
#ifdef ZEND_ENGINE_2
		if (SRC(`arg_info')) {
			gc_arg_info = 1;
			STRUCT_ARRAY(zend_uint, SRC(`num_args'), zend_arg_info, arg_info)
		}
#endif
		DST(`filename') = processor->entry_php_src->filepath.str;

#ifdef ZEND_ENGINE_2_4
		if (SRC(`literals') && op_array_info->constantinfo_cnt) {
			gc_opcodes = 1;
			gc_literals = 1;
		}
#else
		if (op_array_info->constantinfo_cnt) {
			gc_opcodes = 1;
		}
#endif

#ifdef ZEND_ENGINE_2_4
		if (gc_literals) {
			dnl used when copying opcodes
			COPY_N_EX(last_literal, zend_literal, literals)
		}
#endif
		if (gc_opcodes) {
			zend_op *opline, *end;
			COPY_N_EX(last, zend_op, opcodes)

			for (opline = DST(`opcodes'), end = opline + SRC(`last'); opline < end; ++opline) {
#ifdef ZEND_ENGINE_2_4
				pushdef(`UNION_znode_op_literal', `
					if (opline->$1_type == IS_CONST) {
						opline->$1.literal = &DST(`literals[opline->$1.literal - SRC(`literals')]');
					}
				')
				UNION_znode_op_literal(op1)
				UNION_znode_op_literal(op2)
				popdef(`UNION_znode_op_literal')
#endif

				switch (opline->opcode) {
#ifdef ZEND_GOTO
					case ZEND_GOTO:
#endif
					case ZEND_JMP:
#ifdef ZEND_FAST_CALL
					case ZEND_FAST_CALL:
#endif
#ifdef ZEND_ENGINE_2
						Z_OP(opline->op1).jmp_addr = &DST(`opcodes[Z_OP(opline->op1).jmp_addr') - SRC(`opcodes')];
#endif
						break;

					case ZEND_JMPZ:
					case ZEND_JMPNZ:
					case ZEND_JMPZ_EX:
					case ZEND_JMPNZ_EX:
#ifdef ZEND_JMP_SET
					case ZEND_JMP_SET:
#endif
#ifdef ZEND_JMP_SET_VAR
			case ZEND_JMP_SET_VAR:
#endif
#ifdef ZEND_ENGINE_2
						Z_OP(opline->op2).jmp_addr = &DST(`opcodes[Z_OP(opline->op2).jmp_addr') - SRC(`opcodes')];
#endif
						break;

					default:
						break;
				}
			}
		}
		if (gc_arg_info || gc_opcodes
#ifdef ZEND_ENGINE_2_4
		 || gc_literals
#endif
		) {
			xc_gc_op_array_t gc_op_array;
#ifdef ZEND_ENGINE_2
			gc_op_array.num_args = gc_arg_info ? DST(`num_args') : 0;
			gc_op_array.arg_info = gc_arg_info ? DST(`arg_info') : NULL;
#endif
			gc_op_array.opcodes  = gc_opcodes ? DST(`opcodes') : NULL;
#ifdef ZEND_ENGINE_2_4
			gc_op_array.literals = gc_literals ? DST(`literals') : NULL;
#endif
			xc_gc_add_op_array(&gc_op_array TSRMLS_CC);
		}
		IFAUTOCHECK(`xc_autocheck_skip = 1;')
	}
	else
	')
	do {
	dnl RESTORE is done above!

	/* Common elements */
	PROCESS(zend_uchar, type)
	PROC_ZSTRING(, function_name)
#ifdef ZEND_ENGINE_2
	PROCESS(zend_uint, fn_flags)
	STRUCT_ARRAY(zend_uint, SRC(`num_args'), zend_arg_info, arg_info)
	PROCESS(zend_uint, num_args)
	PROCESS(zend_uint, required_num_args)
#	ifndef ZEND_ENGINE_2_4
	PROCESS(zend_bool, pass_rest_by_reference)
#	endif
#else
	if (SRC(`arg_types')) {
		ALLOC(`DST(`arg_types')', zend_uchar, SRC(`arg_types[0]') + 1)
		IFCOPY(`memcpy(DST(`arg_types'), SRC(`arg_types'), sizeof(SRC(`arg_types[0]')) * (SRC(`arg_types[0]')+1));')
		IFDASM(`do {
			int i;
			zval *zv;
			ALLOC_INIT_ZVAL(zv);
			array_init(zv);
			for (i = 0; i < SRC(`arg_types[0]'); i ++) {
				add_next_index_long(zv, SRC(`arg_types[i + 1]'));
			}
			add_assoc_zval_ex(DST(), ZEND_STRS("arg_types"), zv);
		} while (0);')
		DONE(arg_types)
	}
	else {
		COPYNULL(arg_types)
	}
#endif
#ifndef ZEND_ENGINE_2_4
	PROCESS(unsigned char, return_reference)
#endif
	/* END of common elements */
#ifdef IS_UNICODE
	dnl SETNULL(u_twin)
#endif

	IFSTORE(`pushdef(`RELOCATE_EX')')
	STRUCT_P(zend_uint, refcount)
	IFSTORE(`
		popdef(`RELOCATE_EX')
		DST(`refcount[0]') = 1;
		RELOCATE(zend_uint, refcount)
	')

#ifdef ZEND_ENGINE_2_4
	dnl used when copying opcodes
	STRUCT_ARRAY(int, SRC(`last_literal'), zend_literal, literals)
	PROCESS(int, last_literal)
#endif

	dnl uses literals
	STRUCT_ARRAY(zend_uint, SRC(`last'), zend_op, opcodes)
	PROCESS(zend_uint, last)
#ifndef ZEND_ENGINE_2_4
	IFCOPY(`DST(`size') = SRC(`last');DONE(size)', `PROCESS(zend_uint, size)')
#endif

#ifdef IS_CV
	STRUCT_ARRAY(int, SRC(`last_var'), zend_compiled_variable, vars)
	PROCESS(int, last_var)
#	ifndef ZEND_ENGINE_2_4
	IFCOPY(`DST(`size_var') = SRC(`last_var');DONE(size_var)', `PROCESS(zend_uint, size_var)')
#	endif
#else
	dnl zend_cv.m4 is illegal to be made public, don not ask me for it
	IFDASM(`
		sinclude(__dir__`/zend_cv.m4')
		')
#endif

	PROCESS(zend_uint, T)

#ifdef ZEND_ENGINE_2_5
	PROCESS(zend_uint, nested_calls)
	PROCESS(zend_uint, used_stack)
#endif

	STRUCT_ARRAY(last_brk_cont_t, SRC(`last_brk_cont'), zend_brk_cont_element, brk_cont_array)
	PROCESS(last_brk_cont_t, last_brk_cont)
#ifndef ZEND_ENGINE_2_4
	PROCESS(zend_uint, current_brk_cont)
#endif
#ifndef ZEND_ENGINE_2
	PROCESS(zend_bool, uses_globals)
#endif

#ifdef ZEND_ENGINE_2
	STRUCT_ARRAY(int, SRC(`last_try_catch'), zend_try_catch_element, try_catch_array)
	PROCESS(int, last_try_catch)
#endif
#ifdef ZEND_ENGINE_2_5
	PROCESS(zend_bool, has_finally_block)
#endif

	STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)

#ifndef ZEND_ENGINE_2_4
	COPYPOINTER(start_op)
	PROCESS(int, backpatch_count)
#endif
#ifdef ZEND_ENGINE_2_3
	PROCESS(zend_uint, this_var)
#endif

#ifndef ZEND_ENGINE_2_4
	PROCESS(zend_bool, done_pass_two)
#endif
	/* 5.0 <= ver < 5.3 */
#if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_3)
	PROCESS(zend_bool, uses_this)
#endif

	IFRESTORE(`DST(`filename') = processor->entry_php_src->filepath.str; DONE(filename)', `PROC_STRING(filename)')
#ifdef IS_UNICODE
	IFRESTORE(`
		COPYPOINTER(script_encoding)
	', `
		PROC_STRING(script_encoding)
	')
#endif
#ifdef ZEND_ENGINE_2
	PROCESS(zend_uint, line_start)
	PROCESS(zend_uint, line_end)
	PROCESS(int, doc_comment_len)
	PROC_ZSTRING_L(, doc_comment, doc_comment_len)
#endif
#ifdef ZEND_COMPILE_DELAYED_BINDING
	PROCESS(zend_uint, early_binding);
#endif

	/* reserved */
	DONE(reserved)
#if defined(HARDENING_PATCH) && HARDENING_PATCH
	PROCESS(zend_bool, created_by_eval)
#endif
#ifdef ZEND_ENGINE_2_4
	SETNULL(run_time_cache)
	PROCESS(int, last_cache_slot)
#endif
	} while (0);
	IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, DST(), shallow_copy, op_array_info TSRMLS_CC);')

#ifdef ZEND_ENGINE_2
	dnl mark it as -1 on store, and lookup parent on restore
	IFSTORE(`DST(`prototype') = (processor->active_class_entry_src && SRC(`prototype')) ? (zend_function *) -1 : NULL;', `
		IFRESTORE(`do {
			zend_function *parent;
			if (SRC(`prototype') != NULL
			 && zend_u_hash_find(&(processor->active_class_entry_dst->parent->function_table),
					UG(unicode) ? IS_UNICODE : IS_STRING,
					SRC(`function_name'), xc_zstrlen(UG(unicode) ? IS_UNICODE : IS_STRING, SRC(`function_name')) + 1,
					(void **) &parent) == SUCCESS) {
				/* see do_inherit_method_check() */
				if ((parent->common.fn_flags & ZEND_ACC_ABSTRACT)) {
					DST(`prototype') = parent;
				} else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
					/* ctors only have a prototype if it comes from an interface */
					DST(`prototype') = parent->common.prototype ? parent->common.prototype : parent;
				}
				else {
					DST(`prototype') = NULL;
				}
			}
			else {
				DST(`prototype') = NULL;
			}
		} while (0);
		')
	')
	DONE(prototype)

#endif

#ifdef ZEND_ENGINE_2
	PROC_CLASS_ENTRY_P(scope)
	IFCOPY(`
		if (SRC(`scope')) {
			xc_fix_method(processor, DST() TSRMLS_CC);
		}
	')
#endif

	IFRESTORE(`
		if (xc_have_op_array_ctor) {
			zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) xc_zend_extension_op_array_ctor_handler, DST() TSRMLS_CC);
		}
	')
	}
	IFCOPY(`
		processor->active_op_array_dst = NULL;
		processor->active_op_array_src = NULL;
	')
	IFDASM(`
		dasm->active_op_array_src = NULL;
	')
')
dnl }}}

#ifdef HAVE_XCACHE_CONSTANT
DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{
	PROCESS(zend_uint, key_size)
#ifdef IS_UNICODE
	PROCESS(zend_uchar, type)
#endif
	IFRESTORE(`COPYPOINTER(key)', `
		PROC_ZSTRING_N(type, key, key_size)
	')
	PROCESS(ulong, h)
	STRUCT(zend_constant, constant)
')
dnl }}}
#endif
IFRESTORE(`', `
DEF_STRUCT_P_FUNC(`xc_constant_info_t', , `dnl {{{
	PROCESS(zend_uint, index)
	PROCESS(zend_uint, info)
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_op_array_info_t', , `dnl {{{
	PROCESS(zend_uint, constantinfo_cnt)
	STRUCT_ARRAY(zend_uint, SRC(`constantinfo_cnt'), xc_constant_info_t, constantinfos)
')
dnl }}}
')
DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{
	PROCESS(zend_uint, key_size)
#ifdef IS_UNICODE
	PROCESS(zend_uchar, type)
#endif
	IFRESTORE(`COPYPOINTER(key)', `
		PROC_ZSTRING_N(type, key, key_size)
	')
	PROCESS(ulong, h)
	IFRESTORE(`COPYPOINTER(op_array_info)', `
		STRUCT(xc_op_array_info_t, op_array_info)
	')
	IFRESTORE(`
		processor->active_op_array_infos_src = &SRC(`op_array_info');
		processor->active_op_array_index = 0;
	')
	STRUCT(zend_function, func)
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
	PROCESS(zend_uint, key_size)
#ifdef IS_UNICODE
	PROCESS(zend_uchar, type)
#endif
	IFRESTORE(`COPYPOINTER(key)', `
		PROC_ZSTRING_N(type, key, key_size)
	')
	PROCESS(ulong, h)
	PROCESS(zend_uint, methodinfo_cnt)
	IFRESTORE(`COPYPOINTER(methodinfos)', `
		STRUCT_ARRAY(zend_uint, SRC(`methodinfo_cnt'), xc_op_array_info_t, methodinfos)
	')
#ifdef ZEND_ENGINE_2
	PROCESS(zend_uint, constantinfo_cnt)
	IFRESTORE(`COPYPOINTER(constantinfos)', `
		STRUCT_ARRAY(zend_uint, SRC(`constantinfo_cnt'), xc_constant_info_t, constantinfos)
	')
#endif
	IFRESTORE(`
		processor->active_op_array_infos_src = SRC(`methodinfos');
		processor->active_op_array_index = 0;
	')
#ifdef ZEND_ENGINE_2
	STRUCT_P(zend_class_entry, cest)
#else
	STRUCT(zend_class_entry, cest)
#endif
#ifdef ZEND_ENGINE_2
	IFRESTORE(`xc_fix_class_info(processor->entry_php_src, DST(), 0 TSRMLS_CC);')
#endif
#ifndef ZEND_COMPILE_DELAYED_BINDING
	PROCESS(int, oplineno)
#endif
')
dnl }}}
IFRESTORE(`', `
#ifdef ZEND_ENGINE_2_1
DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
	PROCESS(zend_uint, key_len)
#ifdef IS_UNICODE
	PROCESS(zend_uchar, type)
#endif
	IFRESTORE(`COPYPOINTER(key)', `
		PROC_ZSTRING_L(type, key, key_len)
	')
	PROCESS(ulong, h)
')
dnl }}}
#endif
')
IFRESTORE(`', `
#ifdef XCACHE_ERROR_CACHING
DEF_STRUCT_P_FUNC(`xc_compilererror_t', , `dnl {{{
	PROCESS(int, type)
	PROCESS(uint, lineno)
	PROCESS(int, error_len)
	PROC_STRING_L(error, error_len)
')
dnl }}}
#endif
')
DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
	IFCOPY(`
		processor->php_dst = DST();
		processor->php_src = SRC();
	')

	/* skip */
	DONE(next)
	PROCESS(xc_hash_value_t, hvalue)
	PROCESS(xc_md5sum_t, md5)
	PROCESS(zend_ulong, refcount)

	PROCESS(zend_ulong, hits)
	PROCESS(size_t, size)

	IFRESTORE(`COPYPOINTER(op_array_info)', `
		STRUCT(xc_op_array_info_t, op_array_info)
	')
	IFRESTORE(`
		processor->active_op_array_infos_src = &DST(`op_array_info');
		processor->active_op_array_index = 0;
	')
	STRUCT_P(zend_op_array, op_array)

#ifdef HAVE_XCACHE_CONSTANT
	PROCESS(zend_uint, constinfo_cnt)
	STRUCT_ARRAY(zend_uint, SRC(`constinfo_cnt'), xc_constinfo_t, constinfos)
#endif

	PROCESS(zend_uint, funcinfo_cnt)
	STRUCT_ARRAY(zend_uint, SRC(`funcinfo_cnt'), xc_funcinfo_t, funcinfos)

	PROCESS(zend_uint, classinfo_cnt)
	STRUCT_ARRAY(zend_uint, SRC(`classinfo_cnt'), xc_classinfo_t, classinfos, , IFCOPY(`processor->active_class_index'))
#ifdef ZEND_ENGINE_2_1
	PROCESS(zend_uint, autoglobal_cnt)
	IFRESTORE(`
		COPYPOINTER(autoglobals)
	', `
		STRUCT_ARRAY(zend_uint, SRC(`autoglobal_cnt'), xc_autoglobal_t, autoglobals)
	')
#endif
#ifdef XCACHE_ERROR_CACHING
	PROCESS(zend_uint, compilererror_cnt)
	IFRESTORE(`
		COPYPOINTER(compilererrors)
	', `
		STRUCT_ARRAY(zend_uint, SRC(`compilererror_cnt'), xc_compilererror_t, compilererrors)
	')
#endif
#ifndef ZEND_COMPILE_DELAYED_BINDING
	PROCESS(zend_bool, have_early_binding)
#endif
	PROCESS(zend_bool, have_references)
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
	/* skip */
	DONE(next)
	PROCESS(size_t, size)

	PROCESS(time_t, ctime)
	PROCESS(time_t, atime)
	PROCESS(time_t, dtime)
	PROCESS(long, ttl)
	PROCESS(zend_ulong, hits)
	DONE(name) dnl handle in xc_entry_php_t and xc_entry_var_t
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_constant_string_t', , `dnl {{{
	PROCESS(size_t, len)
	IFRESTORE(`COPYPOINTER(str)', `PROC_STRING_L(str, len)')
')
dnl }}}
#ifdef IS_UNICODE
DEF_STRUCT_P_FUNC(`xc_constant_u_string_t', , `dnl {{{
	PROCESS(size_t, len)
	IFRESTORE(`COPYPOINTER(str)', `PROC_USTRING_L(str, len)')
')
dnl }}}
#endif
DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
	STRUCT(xc_entry_t, entry)
	DISABLECHECK(`
		PROCESS(int, entry.name.str.len)
		IFRESTORE(`COPYPOINTER(entry.name.str.val)', `
			PROC_STRING_L(entry.name.str.val, entry.name.str.len)
		')
	')

	IFCALCCOPY(`COPYPOINTER(php)', `STRUCT_P(xc_entry_data_php_t, php)')

	IFSTORE(`DST(`refcount') = 0; DONE(refcount)', `PROCESS(long, refcount)')
	PROCESS(time_t, file_mtime)
	PROCESS(size_t, file_size)
	PROCESS(size_t, file_device)
	PROCESS(size_t, file_inode)

	STRUCT(xc_constant_string_t, filepath)
#ifdef ZEND_ENGINE_2_3
	STRUCT(xc_constant_string_t, dirpath)
#endif
#ifdef IS_UNICODE
	STRUCT(xc_constant_u_string_t, u_filepath)
	STRUCT(xc_constant_u_string_t, u_dirpath)
#endif
')
dnl }}}
DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
	IFCALCSTORE(`xc_entry_var_t *vsrc = /* const_cast */ (xc_entry_var_t *) src;')
	IFRESTORE(`processor->entry_var_src = src;')

	dnl restore is done in foot.m4
	STRUCT(xc_entry_t, entry)

#ifdef IS_UNICODE
	PROCESS(zend_uchar, name_type)
#endif
	dnl {{{ entry.name
	DISABLECHECK(`
#ifdef IS_UNICODE
		if (SRC(`name_type') == IS_UNICODE) {
			PROCESS(int32_t, entry.name.ustr.len)
		}
		else {
			PROCESS(int, entry.name.str.len)
		}
#else
		PROCESS(int, entry.name.str.len)
#endif
		IFRESTORE(`COPYPOINTER(entry.name.str.val)', `
#ifdef IS_UNICODE
			PROC_ZSTRING_L(name_type, entry.name.uni.val, entry.name.uni.len)
#else
			PROC_STRING_L(entry.name.str.val, entry.name.str.len)
#endif
		')
	')
	dnl }}}

	IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
	STRUCT_P_EX(zval_ptr, DST(`value'), SRC(`value'), `value', `', `&')
	DONE(value)
#if 0
	IFSTORE(`
	{
		HashTable *ht;
		zval **zv;

		assert(Z_TYPE_P(DST(`value')) == IS_ARRAY);
		ht = Z_ARRVAL_P(DST(`value'));
		assert(ht->nNumOfElements == 1);
		fprintf(stderr, "key %s\n", ht->pListHead->arKey);

		zv = (zval **) ht->pListHead->pData;
		assert(Z_TYPE_PP(zv) == IS_ARRAY);
		assert(Z_ARRVAL_PP(zv) == ht);
		fprintf(stderr, "refcount=%d\n", Z_REFCOUNT(*DST(`value')));
		fprintf(stderr, "refcount=%d\n", Z_REFCOUNT(**zv));
	}
	')
#endif

#ifdef ZEND_ENGINE_2
	IFCALC(`
		dnl objects = collect_from(value + objects);
		pushdef(`src', `vsrc')
		SRC(objects_count) = xc_vector_size(&processor->objects);
		SRC(objects) = xc_vector_detach(zend_object, &processor->objects);
		popdef(`src')
		xc_vector_destroy(&processor->objects);
	')
	dnl must be after calc .value
	PROCESS(zend_uint, objects_count)
	STRUCT_ARRAY(zend_uint, SRC(`objects_count'), zend_object, objects)
	IFSTORE(`{
		/* no longer needed */
		if (vsrc->objects_count) {
			efree(vsrc->objects);
			vsrc->objects_count = 0;
			vsrc->objects = NULL;
			zend_hash_destroy(&processor->handle_to_index);
		}
	}')
#endif

	dnl classe_
	IFCALC(`
		dnl class_names = collect_from(objects);
		pushdef(`src', `vsrc')
		SRC(class_names_count) = xc_vector_size(&processor->class_names);
		SRC(class_names) = xc_vector_detach(xc_constant_string_t, &processor->class_names);
		popdef(`src')
		xc_vector_destroy(&processor->class_names);
	')
	PROCESS(zend_uint, class_names_count)
	STRUCT_ARRAY(zend_uint, SRC(`class_names_count'), xc_constant_string_t, class_names)
	IFSTORE(`
		/* no longer needed */
		if (vsrc->class_names_count) {
			efree(vsrc->class_names);
			vsrc->class_names_count = 0;
			vsrc->class_names = NULL;
			zend_hash_destroy(&processor->class_name_to_index);
		}
	')

	PROCESS(zend_bool, have_references)
')
dnl }}}
dnl ====================================================