xref: /imagick/util/checkSymbols.php (revision dab0396e)
1<?php
2
3
4/**
5 * This is a simple script to analyze symbols defined or needed by Imagick.
6 * It is an attempt to check verify that the version info that Imagick is assuming
7 * is true about ImageMagick is actually true.
8 */
9
10class SymbolChecker
11{
12	private $requiredSymbols = [];
13	private $providedSymbols = [];
14	private $exclusionPatterns = [];
15	private $exclusions = [];
16
17	public function addExclusionRegex($pattern)
18	{
19		$this->exclusionPatterns[] = $pattern;
20	}
21
22	public function addExclusion($string)
23	{
24		$this->exclusions[] = $string;
25	}
26
27	public function readSymbolsFromFile($imagickSymbols, $isImagick)
28	{
29		$lines = file($imagickSymbols);
30
31		if ($lines === false) {
32			echo "Failed to read $imagickSymbols \n";
33			exit(-1);
34		}
35
36		foreach ($lines as $line) {
37			$line = trim($line);
38			$matched = preg_match('#(.*)(A|B|D|R|T|U|w) (.*)#', $line, $matches);
39			if (!$matched) {
40				echo "Failed to match line: ".$line."\n";
41				continue;
42			}
43
44			$char = $matches[2];
45			$symbol = $matches[3];
46
47			switch($char) {
48				case('U'): {
49					if ($isImagick) {
50						$this->requiredSymbols[] = trim($symbol);
51					}
52					break;
53				}
54
55				case('T'): {
56					$this->providedSymbols[] = trim($symbol);
57					break;
58				}
59			}
60		}
61	}
62
63
64	function getMissingSymbols()
65	{
66		$missing = [];
67
68		foreach ($this->requiredSymbols as $required) {
69			if (in_array($required, $this->providedSymbols) == true) {
70				continue;
71			}
72
73			foreach ($this->exclusionPatterns as $exclusionPattern) {
74				if (preg_match("#".$exclusionPattern."#", $required)) {
75					continue 2;
76				}
77			}
78
79			if (in_array($required, $this->exclusions)) {
80				continue;
81			}
82
83			$missing[] = $required;
84		}
85
86		return $missing;
87	}
88}
89
90
91$symbolChecker = new SymbolChecker();
92
93$symbolChecker->readSymbolsFromFile(__DIR__."/symbols.imagick.txt", true);
94$symbolChecker->readSymbolsFromFile(__DIR__."/symbols.magickcore.txt", false);
95$symbolChecker->readSymbolsFromFile(__DIR__."/symbols.magickwand.txt", false);
96
97$symbolChecker->addExclusionRegex("^zend_.*");
98$symbolChecker->addExclusionRegex("^_.*");
99$symbolChecker->addExclusionRegex("^php_.*");
100$symbolChecker->addExclusionRegex("^str.*");
101$symbolChecker->addExclusionRegex("^add_.*");
102
103$symbolChecker->addExclusionRegex("^access.*");
104$symbolChecker->addExclusionRegex("^convert_to_.*");
105$symbolChecker->addExclusionRegex("^fclose.*");
106$symbolChecker->addExclusionRegex("^fopen.*");
107$symbolChecker->addExclusionRegex("^fprintf.*");
108$symbolChecker->addExclusionRegex("^instanceof_function_ex.*");
109$symbolChecker->addExclusionRegex("^memcpy.*");
110$symbolChecker->addExclusionRegex("^object_properties_init.*");
111$symbolChecker->addExclusionRegex("^setlocale.*");
112
113$symbolChecker->addExclusionRegex("^atoi.*");
114$symbolChecker->addExclusionRegex("^free.*");
115$symbolChecker->addExclusionRegex("^sqrt.*");
116
117$symbolChecker->addExclusion("core_globals_id");
118$symbolChecker->addExclusion("executor_globals_id");
119$symbolChecker->addExclusion("ts_allocate_id");
120$symbolChecker->addExclusion("tsrm_get_ls_cache");
121$symbolChecker->addExclusion("virtual_access");
122$symbolChecker->addExclusion("OnUpdateBool");
123$symbolChecker->addExclusion("ap_php_snprintf");
124$symbolChecker->addExclusion("core_globals");
125$symbolChecker->addExclusion("display_ini_entries");
126$symbolChecker->addExclusion("empty_fcall_info_cache");
127$symbolChecker->addExclusion("executor_globals");
128$symbolChecker->addExclusion("expand_filepath");
129$symbolChecker->addExclusion("spl_ce_Countable");
130$symbolChecker->addExclusion("spprintf");
131$symbolChecker->addExclusion("ts_resource_ex");
132
133
134
135$missingList = $symbolChecker->getMissingSymbols();
136
137if (count($missingList) == 0) {
138	exit(0);
139}
140
141echo "Detected missing symbols in imagick library:";
142foreach ($missingList as $missing) {
143	echo "$missing\n";
144}
145
146exit(-1);