├── .eslintrc.cjs
├── .github
├── FUNDING.yml
├── dependabot.yml
└── workflows
│ ├── playwright.yml
│ ├── review_dog.yml
│ ├── static.yml
│ └── test.yml
├── .gitignore
├── .node-version
├── .prettierignore
├── .prettierrc.json
├── LICENSE
├── Makefile
├── Readme.md
├── assets
├── ads.txt
├── favicon.svg
├── octocat.png
├── ogp.png
├── php-5.6.wasm
├── php-7.0.wasm
├── php-7.1.wasm
├── php-7.2.wasm
├── php-7.3.wasm
├── php-7.4.wasm
├── php-8.0.wasm
├── php-8.1.wasm
├── php-8.2.wasm
├── php-8.3.wasm
├── php-8.4.wasm
├── privacy.html
└── sitemap.xml
├── build.mjs
├── doc
└── demo.gif
├── e2e
└── e2e.spec.ts
├── index.html
├── package-lock.json
├── package.json
├── playwright.config.ts
├── src
├── __test__
│ ├── __snapshots__
│ │ └── php.test.ts.snap
│ ├── php.spec.ts
│ └── php.test.ts
├── app.tsx
├── editor.tsx
├── footer.tsx
├── format.tsx
├── header.tsx
├── index.tsx
├── manual.tsx
├── php-wasm
│ ├── __tests__
│ │ ├── php.ts
│ │ └── utils.ts
│ ├── index.ts
│ ├── php-browser.ts
│ ├── php-server.ts
│ ├── php.ts
│ └── utils.ts
├── php.ts
├── select.tsx
├── switch.tsx
├── theme.tsx
├── wasm-assets
│ ├── php-5.6.js
│ ├── php-7.0.js
│ ├── php-7.1.js
│ ├── php-7.2.js
│ ├── php-7.3.js
│ ├── php-7.4.js
│ ├── php-8.0.js
│ ├── php-8.1.js
│ ├── php-8.2.js
│ ├── php-8.3.js
│ └── php-8.4.js
└── wasm
│ ├── Dockerfile
│ └── build-assets
│ ├── bison27.patch
│ ├── ncurses.patch
│ ├── php5.6-openssl1.1.patch
│ ├── php5.6.patch
│ ├── php7.0.patch
│ ├── php7.1.patch
│ ├── php7.2.patch
│ ├── php7.3.patch
│ ├── php7.4.patch
│ ├── php8.0.patch
│ ├── php8.1.patch
│ ├── php8.2.patch
│ ├── php8.3.patch
│ ├── php8.4.patch
│ ├── php_wasm.c
│ ├── phpwasm-emscripten-library.js
│ ├── replace.sh
│ └── zlib
│ ├── CMakeLists.txt
│ ├── Makefile.in
│ ├── README
│ ├── adler32.c
│ ├── benchmark.c
│ ├── compress.c
│ ├── configure
│ ├── crc32.c
│ ├── crc32.h
│ ├── deflate.c
│ ├── deflate.h
│ ├── example.c
│ ├── gzclose.c
│ ├── gzguts.h
│ ├── gzlib.c
│ ├── gzread.c
│ ├── gzwrite.c
│ ├── infback.c
│ ├── inffast.c
│ ├── inffast.h
│ ├── inffixed.h
│ ├── inflate.c
│ ├── inflate.h
│ ├── inftrees.c
│ ├── inftrees.h
│ ├── minigzip.c
│ ├── readme.txt
│ ├── ref.txt
│ ├── trees.c
│ ├── trees.h
│ ├── uncompr.c
│ ├── zconf.h
│ ├── zconf.h.cmakein
│ ├── zconf.h.in
│ ├── zlib.3
│ ├── zlib.h
│ ├── zlib.map
│ ├── zlib.pc
│ ├── zlib.pc.in
│ ├── zutil.c
│ └── zutil.h
├── tsconfig.json
├── vite.config.js
└── vitest.config.js
/.eslintrc.cjs:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | env: {
3 | browser: true,
4 | es2021: true,
5 | },
6 | settings: {
7 | jsdoc: {
8 | tagNamePreference: {
9 | return: 'returns',
10 | internal: 'internal',
11 | },
12 | },
13 | react: {
14 | version: 'detect',
15 | }
16 | },
17 | extends: [
18 | 'eslint:recommended',
19 | 'plugin:react/recommended',
20 | 'plugin:@typescript-eslint/recommended',
21 | ],
22 | parser: '@typescript-eslint/parser',
23 | parserOptions: {
24 | ecmaVersion: 'latest',
25 | sourceType: 'module',
26 | },
27 | root: true,
28 | ignorePatterns: [
29 | "src/php-wasm/__tests__/*.ts",
30 | "src/wasm/build-assets/*.js",
31 | "src/wasm-assets/*.js"
32 | ],
33 | plugins: ['react', '@typescript-eslint'],
34 | rules: {
35 | 'no-inner-declarations': 0,
36 | 'no-use-before-define': 'off',
37 | 'react/prop-types': 0,
38 | 'no-console': 0,
39 | 'no-empty': 0,
40 | 'no-async-promise-executor': 0,
41 | 'no-constant-condition': 0,
42 | 'no-nested-ternary': 0,
43 | 'jsx-a11y/click-events-have-key-events': 0,
44 | 'jsx-a11y/no-static-element-interactions': 0,
45 | '@typescript-eslint/ban-ts-comment': 0,
46 | '@typescript-eslint/no-non-null-assertion': 0,
47 | },
48 | };
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | # These are supported funding model platforms
2 |
3 | github: glassmonkey
4 |
--------------------------------------------------------------------------------
/.github/dependabot.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | updates:
3 | - package-ecosystem: "npm"
4 | directory: "/"
5 | schedule:
6 | interval: weekly
--------------------------------------------------------------------------------
/.github/workflows/playwright.yml:
--------------------------------------------------------------------------------
1 | name: Playwright Tests
2 | on:
3 | push:
4 | branches:
5 | master
6 | pull_request:
7 | branches:
8 | master
9 | jobs:
10 | test:
11 | timeout-minutes: 60
12 | runs-on: ubuntu-latest
13 | steps:
14 | - uses: actions/checkout@v4
15 | - uses: actions/setup-node@v4
16 | with:
17 | node-version: lts/*
18 | - name: Install dependencies
19 | run: npm ci
20 | - name: Install Playwright Browsers
21 | run: npx playwright install --with-deps
22 | - name: Run Playwright tests
23 | run: npx playwright test
24 | - uses: actions/upload-artifact@v4
25 | if: always()
26 | with:
27 | name: playwright-report
28 | path: playwright-report/
29 | retention-days: 30
30 |
--------------------------------------------------------------------------------
/.github/workflows/review_dog.yml:
--------------------------------------------------------------------------------
1 | name: reviewdog
2 | on: [pull_request]
3 | jobs:
4 | eslint:
5 | name: runner / eslint
6 | runs-on: ubuntu-latest
7 | permissions:
8 | contents: read
9 | pull-requests: write
10 | steps:
11 | - uses: actions/checkout@v4
12 | - uses: reviewdog/action-eslint@v1
13 | with:
14 | github_token: ${{ github.token }}
15 | reporter: github-pr-review # Change reporter.
16 | eslint_flags: 'src/'
--------------------------------------------------------------------------------
/.github/workflows/static.yml:
--------------------------------------------------------------------------------
1 | # Simple workflow for deploying static content to GitHub Pages
2 | name: Deploy static content to Pages
3 |
4 | on:
5 | # Runs on pushes targeting the default branch
6 | push:
7 | branches: ["master"]
8 |
9 | # Allows you to run this workflow manually from the Actions tab
10 | workflow_dispatch:
11 |
12 | # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
13 | permissions:
14 | contents: read
15 | pages: write
16 | id-token: write
17 |
18 | # Allow one concurrent deployment
19 | concurrency:
20 | group: "pages"
21 | cancel-in-progress: true
22 |
23 | jobs:
24 | # Single deploy job since we're just deploying
25 | deploy:
26 | environment:
27 | name: github-pages
28 | url: ${{ steps.deployment.outputs.page_url }}
29 | runs-on: ubuntu-latest
30 | steps:
31 | - name: Checkout
32 | uses: actions/checkout@v4
33 | - name: Setup Pages
34 | uses: actions/configure-pages@v3
35 | - name: Cache node modules
36 | id: cache-npm
37 | uses: actions/cache@v3
38 | env:
39 | cache-name: cache-node-modules
40 | with:
41 | # npm cache files are stored in `~/.npm` on Linux/macOS
42 | path: ~/.npm
43 | key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
44 | restore-keys: |
45 | ${{ runner.os }}-build-${{ env.cache-name }}-
46 | ${{ runner.os }}-build-
47 | ${{ runner.os }}-
48 | - name: Install dependencies
49 | run: npm install
50 | - name: build
51 | run: npm run build
52 | - name: Upload artifact
53 | uses: actions/upload-pages-artifact@v1
54 | with:
55 | # Upload entire repository
56 | path: 'public'
57 | - name: Deploy to GitHub Pages
58 | id: deployment
59 | uses: actions/deploy-pages@v1
60 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Unit Tests
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 |
8 | jobs:
9 | build:
10 | runs-on: ubuntu-latest
11 | steps:
12 | - uses: actions/checkout@v4
13 | - name: Use Node.js
14 | uses: actions/setup-node@v4
15 | with:
16 | node-version: 22.4.0
17 | cache: 'npm'
18 | - run: npm ci
19 | - run: make lint
20 | - run: make test-ci
21 | env:
22 | LANG: ja_JP.UTF-8
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | cmake-build-debug
3 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
4 |
5 | # dependencies
6 | /node_modules
7 | /.pnp
8 | .pnp.js
9 |
10 | # testing
11 | /coverage
12 |
13 | # production
14 | /build
15 |
16 | /public
17 |
18 | # misc
19 | .DS_Store
20 | .env.local
21 | .env.development.local
22 | .env.test.local
23 | .env.production.local
24 |
25 | npm-debug.log*
26 | yarn-debug.log*
27 | yarn-error.log*
28 |
29 | assets/index.js
30 |
31 | build-types
32 | *.tsbuildinfo
33 | /test-results/
34 | /playwright-report/
35 | /blob-report/
36 | /playwright/.cache/
37 |
--------------------------------------------------------------------------------
/.node-version:
--------------------------------------------------------------------------------
1 | 22.4.0
2 |
--------------------------------------------------------------------------------
/.prettierignore:
--------------------------------------------------------------------------------
1 | public/*
2 | src/wasm/*
--------------------------------------------------------------------------------
/.prettierrc.json:
--------------------------------------------------------------------------------
1 | {
2 | "trailingComma": "es5",
3 | "tabWidth": 4,
4 | "useTabs": true,
5 | "semi": true,
6 | "singleQuote": true
7 | }
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | # parametaers
2 | PHP_VERSION := 8.2
3 | WITH_VRZNO := yes
4 | WITH_LIBXML := no
5 | WITH_LIBPNG := no
6 | WITH_MBSTRING := yes
7 | WITH_CLI_SAPI := no
8 | WITH_OPENSSL := no
9 | WITH_NODEFS := no
10 | WITH_CURL := no
11 | WITH_SQLITE := no
12 | WITH_MYSQL := no
13 | WITH_WS_NETWORKING_PROXY := no
14 | # web or node
15 | PLATFORM := web
16 |
17 | PHP_IMAGE := php-wasm:$(PHP_VERSION)
18 |
19 | DIST_DIR := $(PWD)/dist
20 |
21 |
22 | .PHONY: build-image build-wasm build build-all build-5.6 build-7.0 build-7.1 build-7.2 build-7.3 build-7.4 build-8.0 build-8.1 build-8.2
23 | WITH_CACHE :=
24 | ifeq ($(WITH_CACHE),no)
25 | WITH_CACHE := --no-cache
26 | endif
27 |
28 | build-image:
29 | cd src/wasm && \
30 | docker build $(WITH_CACHE) . --tag=$(PHP_IMAGE) \
31 | --build-arg PHP_VERSION=$(PHP_VERSION) \
32 | --build-arg WITH_VRZNO=$(WITH_VRZNO) \
33 | --build-arg WITH_LIBXML=$(WITH_LIBXML) \
34 | --build-arg WITH_LIBPNG=$(WITH_LIBPNG) \
35 | --build-arg WITH_MBSTRING=$(WITH_MBSTRING) \
36 | --build-arg WITH_CLI_SAPI=$(WITH_CLI_SAPI) \
37 | --build-arg WITH_OPENSSL=$(WITH_OPENSSL) \
38 | --build-arg WITH_NODEFS=$(WITH_NODEFS) \
39 | --build-arg WITH_CURL=$(WITH_CURL) \
40 | --build-arg WITH_SQLITE=$(WITH_SQLITE) \
41 | --build-arg WITH_MYSQL=$(WITH_MYSQL) \
42 | --build-arg WITH_WS_NETWORKING_PROXY=$(WITH_WS_NETWORKING_PROXY) \
43 | --build-arg EMSCRIPTEN_ENVIRONMENT=$(PLATFORM) && \
44 | cd -
45 |
46 | CMD_DIST := 'cp /root/output/php* /output'
47 | ifeq ($(WITH_CLI_SAPI),yes)
48 | CMD_DIST = "$(CMD_DIST) && cp /root/lib/share/terminfo/x/xterm /output/terminfo/x"
49 | endif
50 |
51 | build-wasm: build-image
52 | docker run --rm -v $(DIST_DIR):/output $(PHP_IMAGE) \
53 | sh -c $(CMD_DIST);
54 | mv $(DIST_DIR)/php-$(PHP_VERSION).js src/wasm-assets/;
55 | mv $(DIST_DIR)/php-$(PHP_VERSION).wasm assets/;
56 |
57 | JOBS := $(call add $(shell grep cpu.cores /proc/cpuinfo | sort -u | sed 's/[^0-9]//g'), 1)
58 | ifeq ($(shell uname), Darwin)
59 | JOBS = $(shell sysctl -a machdep.cpu | grep core_count | sed 's/[^0-9]//g')
60 | endif
61 |
62 | build:
63 | $(MAKE) build-all -j$(JOBS)
64 |
65 | # too heavy
66 | build-all: build-5.6 build-7.0 build-7.1 build-7.2 build-7.3 build-7.4 build-8.0 build-8.1 build-8.2 build-8.3 build-8.4
67 |
68 | build-5.6:
69 | $(MAKE) build-wasm PHP_VERSION=5.6
70 |
71 | build-7.0:
72 | $(MAKE) build-wasm PHP_VERSION=7.0
73 |
74 | build-7.1:
75 | $(MAKE) build-wasm PHP_VERSION=7.1
76 |
77 | build-7.2:
78 | $(MAKE) build-wasm PHP_VERSION=7.2
79 |
80 | build-7.3:
81 | $(MAKE) build-wasm PHP_VERSION=7.3
82 |
83 | build-7.4:
84 | $(MAKE) build-wasm PHP_VERSION=7.4
85 |
86 | build-8.0:
87 | $(MAKE) build-wasm PHP_VERSION=8.0
88 |
89 | build-8.1:
90 | $(MAKE) build-wasm PHP_VERSION=8.1
91 |
92 | build-8.2:
93 | $(MAKE) build-wasm PHP_VERSION=8.2
94 |
95 | build-8.3:
96 | $(MAKE) build-wasm PHP_VERSION=8.3
97 |
98 | build-8.4:
99 | $(MAKE) build-wasm PHP_VERSION=8.4
100 |
101 | public/index.js:
102 | npm run build
103 |
104 | debug: build-image
105 | docker run -it --rm -v $(DIST_DIR):/output $(PHP_IMAGE) bash
106 |
107 | .PHONY: lint
108 | lint:
109 | npm run lint:js
110 | npm run build:types
111 |
112 | .PHONY: test
113 | test:
114 | npm run test
115 |
116 | .PHONY: test-cl
117 | test-ci:
118 | npm run test:ci
119 |
120 | .PHONY: style-fix
121 | style-fix:
122 | npm run lint:js:fix
123 | npm run format
124 |
125 | .PHONY: clean-image
126 | clean-image:
127 | docker image rm `docker images php-wasm -q`
--------------------------------------------------------------------------------
/Readme.md:
--------------------------------------------------------------------------------
1 | 
2 | 
3 |
4 | # php-playground
5 |
6 | PHP Playground let you to execute basic PHP code in real time.
7 |
8 | https://php-play.dev
9 |
10 | 
11 |
12 | # usage build
13 | build web assembly
14 | ```
15 | make build
16 | ```
17 |
18 | build JavaScript with watching
19 | ```
20 | npm run dev
21 | ```
22 |
23 | build JavaScript
24 | ```
25 | npm run build
26 | ```
27 |
28 | build JavaScript and preview
29 | ```
30 | npm run preview
31 | ```
32 |
33 | # related
34 |
35 | ## chrome extension
36 | install: [store page](https://chromewebstore.google.com/detail/run-on-php-playground/ddhmobhdfmhfckpkedkompdjdmpapeng)
37 | repository: [meihei3/run-on-php-playground](https://github.com/meihei3/run-on-php-playground)
38 |
39 | ## PHP to WebAssembly build pipeline
40 |
41 | The bulild pipeline was created by Forking [WordPress/wordpress-playground](https://github.com/WordPress/wordpress-playground).
42 | Please refer to the [original document](https://wordpresswasm.readthedocs.io/en/latest/using-php-in-javascript/) for details.
43 |
44 | # Licence
45 |
46 | Apache License 2.0
47 |
--------------------------------------------------------------------------------
/assets/favicon.svg:
--------------------------------------------------------------------------------
1 |
2 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/assets/octocat.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/octocat.png
--------------------------------------------------------------------------------
/assets/ogp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/ogp.png
--------------------------------------------------------------------------------
/assets/php-5.6.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-5.6.wasm
--------------------------------------------------------------------------------
/assets/php-7.0.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.0.wasm
--------------------------------------------------------------------------------
/assets/php-7.1.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.1.wasm
--------------------------------------------------------------------------------
/assets/php-7.2.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.2.wasm
--------------------------------------------------------------------------------
/assets/php-7.3.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.3.wasm
--------------------------------------------------------------------------------
/assets/php-7.4.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-7.4.wasm
--------------------------------------------------------------------------------
/assets/php-8.0.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.0.wasm
--------------------------------------------------------------------------------
/assets/php-8.1.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.1.wasm
--------------------------------------------------------------------------------
/assets/php-8.2.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.2.wasm
--------------------------------------------------------------------------------
/assets/php-8.3.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.3.wasm
--------------------------------------------------------------------------------
/assets/php-8.4.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/assets/php-8.4.wasm
--------------------------------------------------------------------------------
/assets/sitemap.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | https://php-play.dev/
5 |
6 |
--------------------------------------------------------------------------------
/build.mjs:
--------------------------------------------------------------------------------
1 | import * as esbuild from 'esbuild'
2 |
3 | let options = {
4 | entryPoints: ['src/index.tsx'],
5 | bundle: true,
6 | outdir: 'public',
7 | tsconfig: "./tsconfig.json"
8 | }
9 |
10 | const context = await esbuild.context(options)
11 | const result = await context.rebuild()
12 | console.log(result)
13 |
14 | if (process.env.WATCH !== "true") {
15 | context.dispose();
16 |
17 | } else{
18 | console.log("begin: watch")
19 | await context.watch()
20 | }
21 |
--------------------------------------------------------------------------------
/doc/demo.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/glassmonkey/php-playground/ef1307233eb9ef4b6abeb12ea27f8d36db29b1cc/doc/demo.gif
--------------------------------------------------------------------------------
/e2e/e2e.spec.ts:
--------------------------------------------------------------------------------
1 | import {expect, test} from '@playwright/test';
2 | import {versions} from "../src/php-wasm/php";
3 |
4 | const PAGE = 'http://127.0.0.1:18888';
5 | test.describe('default page', () => {
6 | test.beforeEach(async ({page}) => {
7 | await page.goto(PAGE);
8 | })
9 | test('has title', async ({ page }) => {
10 | await expect(page).toHaveTitle('PHP Playground');
11 | });
12 | test('default version is 8.4', async ({ page }) => {
13 | await expect(page.getByText('8.4')).toBeVisible()
14 | })
15 | test('default code is `phpinfo()`', async ({ page }) => {
16 | await expect(page.getByRole('code')).toContainText('phpinfo();')
17 | })
18 |
19 | test('default URL', async ({ page }) => {
20 | const defaultPage = `${PAGE}/?c=DwfgDgFmBQD0sAICmAPAhgWzAGyQgxgPYAmS0kYAlgHYBmhAFAJQDcQA&v=8.4&f=html`
21 | await page.waitForURL(defaultPage)
22 | expect(page.url()).toContain(defaultPage)
23 | })
24 |
25 | test('switch preview', async ({ page }) => {
26 | // html preview
27 | await page.getByTestId('checkbox-format').check()
28 | await expect(await page.getByTestId('preview-html').getAttribute('srcdoc')).toContain('PHP Version 8.4')
29 | await expect(await page.getByTestId('preview-console')).not.toBeVisible()
30 |
31 | // console pvreview
32 | await page.getByTestId('checkbox-format').uncheck()
33 | await expect(await page.getByTestId('preview-console')).toContainText('PHP Version 8.4')
34 | await expect(await page.getByTestId('preview-html')).not.toBeVisible()
35 | })
36 | })
37 |
38 | test.describe('select version', () => {
39 | // ref: https://github.com/microsoft/playwright/issues/7036
40 | versions.forEach((v) => {
41 | test.describe(`select version v=${v}`, () => {
42 | test.beforeEach(async ({page}) => {
43 | await page.goto(PAGE);
44 | })
45 | test(`running php info`, async ({page}) => {
46 | const input = page.locator('#select-input-php')
47 | await input.fill(v)
48 | await page.keyboard.down("Tab");
49 |
50 | // html preview
51 | await page.getByTestId('checkbox-format').check()
52 | await expect(await page.getByTestId('preview-html').getAttribute('srcdoc')).toContain(`PHP Version ${v}`)
53 | expect(page.url()).toContain(`v=${v}`)
54 | })
55 | test(`compute php code(1+1)`, async ({page}) => {
56 | await page.goto(`${PAGE}/?c=DwfgUEA`);
57 | // select version
58 | const input = page.locator('#select-input-php')
59 | await input.fill(v)
60 | await page.keyboard.down("Tab");
61 |
62 | const editor = page.getByRole('code')
63 | // focus editor
64 | await editor.click()
65 | // display code in editor
66 | await expect(page.getByRole('presentation')).toHaveText('')
67 | // try 1+1
68 | await page.keyboard.type(' echo(1+1);')
69 | // display code in editor
70 | await expect(page.getByRole('presentation')).toHaveText(' echo(1+1);')
71 | // run and result is 2
72 | await page.getByTestId('checkbox-format').uncheck()
73 | await expect(await page.getByTestId('preview-console')).toHaveText('2')
74 | })
75 |
76 | test(`compute php code(1+1) with strict`, async ({page}) => {
77 | if (v < '7.0') {
78 | console.log("strict_types is not supported")
79 | return
80 | }
81 | await page.goto(`${PAGE}/?c=DwfgUEA`);
82 | // select version
83 | const input = page.locator('#select-input-php')
84 | await input.fill(v)
85 | await page.keyboard.down("Tab");
86 |
87 | const editor = page.getByRole('code')
88 | // focus editor
89 | await editor.click()
90 | // display code in editor
91 | await expect(page.getByRole('presentation')).toHaveText('')
92 | // try 1+1
93 | await page.keyboard.type(' declare(strict_types=1);echo(1+1);')
94 | // display code in editor
95 | await expect(page.getByRole('presentation')).toHaveText(' declare(strict_types=1);echo(1+1);')
96 | // run and result is 2
97 | await page.getByTestId('checkbox-format').uncheck()
98 | await expect(await page.getByTestId('preview-console')).toHaveText('2')
99 | })
100 | test(`not compute text`, async ({page}) => {
101 | await page.goto(`${PAGE}/?c=DwQgtBYHxA`);
102 | // select version
103 | const input = page.locator('#select-input-php')
104 | await input.fill(v)
105 | await page.keyboard.down("Tab");
106 |
107 | const editor = page.getByRole('code')
108 | // focus editor
109 | await editor.click()
110 | // display code in editor
111 | await expect(page.getByRole('presentation')).toHaveText('')
112 | // try 1+1
113 | await page.keyboard.type('Hello, World')
114 | // display code in editor
115 | await expect(page.getByRole('presentation')).toHaveText('Hello, World')
116 | // run and result is 2
117 | await page.getByTestId('checkbox-format').uncheck()
118 | await expect(await page.getByTestId('preview-console')).toHaveText('Hello, World')
119 | })
120 | test(`include compute text`, async ({page}) => {
121 | await page.goto(`${PAGE}/?c=DwQgtBYHxA`); //
122 | // select version
123 | const input = page.locator('#select-input-php')
124 | await input.fill(v)
125 | await page.keyboard.down("Tab");
126 |
127 | const editor = page.getByRole('code')
128 | // focus editor
129 | await editor.click()
130 | // display code in editor
131 | await expect(page.getByRole('presentation')).toHaveText('')
132 | // try 1+1
133 | await page.keyboard.type('
')
134 | // display code in editor
135 | await expect(page.getByRole('presentation')).toHaveText('')
136 | // run and result is 2
137 | await page.getByTestId('checkbox-format').uncheck()
138 | await expect(await page.getByTestId('preview-console')).toHaveText('xyz')
139 | })
140 | })
141 | })
142 | })
143 |
144 |
145 |
146 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 | PHP Playground
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "php-playground",
3 | "version": "0.1.0",
4 | "engines": {
5 | "node": "22.4.0"
6 | },
7 | "type": "module",
8 | "private": true,
9 | "dependencies": {
10 | "@chakra-ui/icons": "2.1.0",
11 | "@chakra-ui/react": "2.8.0",
12 | "@codemirror/language": "6.11.0",
13 | "@codesandbox/sandpack-react": "2.19.9",
14 | "@emotion/react": "11.13.3",
15 | "@emotion/styled": "11.13.0",
16 | "@monaco-editor/react": "4.6.0",
17 | "@testing-library/jest-dom": "6.5.0",
18 | "@testing-library/user-event": "14.5.2",
19 | "@types/jest": "29.5.14",
20 | "@types/lz-string": "1.5.0",
21 | "@types/node": "20.12.8",
22 | "@types/react": "18.3.3",
23 | "@types/react-dom": "18.3.1",
24 | "debounce": "2.0.0",
25 | "framer-motion": "11.5.4",
26 | "lz-string": "1.5.0",
27 | "npm-run-all": "4.1.5",
28 | "prettier": "3.5.3",
29 | "react": "18.3.1",
30 | "react-dom": "18.3.1",
31 | "react-icons": "5.0.1",
32 | "react-router-dom": "6.26.2",
33 | "react-select": "5.9.0",
34 | "typescript": "5.6.2",
35 | "web-vitals": "4.2.4"
36 | },
37 | "scripts": {
38 | "dev": "vite",
39 | "build": "vite build",
40 | "preview": "vite build && vite preview --port 8888",
41 | "build:types": "npm run clean:types; npm-run-all --parallel build:types:*",
42 | "build:types:general": "tsc -p ./tsconfig.json",
43 | "clean": "npm-run-all --parallel clean:*",
44 | "clean:all": "rm -rf build/* ./build-*/*",
45 | "clean:types": "rm -rf build-types/* *.tsbuildinfo",
46 | "format": "prettier --write src",
47 | "lint:js": "eslint \"./src/**/*.{js,mjs,ts}\"",
48 | "lint:js:fix": "npm run lint:js -- --fix",
49 | "test": "vitest",
50 | "test:ci": "vitest run",
51 | "test:e2e": "playwright test",
52 | "test:e2e:report": "playwright show-report"
53 | },
54 | "eslintConfig": {
55 | "extends": [
56 | "react-app",
57 | "react-app/jest"
58 | ]
59 | },
60 | "browserslist": {
61 | "production": [
62 | ">0.2%",
63 | "not dead",
64 | "not op_mini all"
65 | ],
66 | "development": [
67 | "last 1 chrome version",
68 | "last 1 firefox version",
69 | "last 1 safari version"
70 | ]
71 | },
72 | "devDependencies": {
73 | "@playwright/test": "1.51.1",
74 | "@testing-library/react": "16.0.1",
75 | "@types/debounce": "1.2.4",
76 | "@typescript-eslint/eslint-plugin": "7.16.0",
77 | "@vitejs/plugin-react": "4.3.4",
78 | "esbuild": "0.25.1",
79 | "eslint": "8.57.0",
80 | "eslint-plugin-react": "7.35.0",
81 | "jsdom": "^25.0.1",
82 | "node-fetch": "3.3.2",
83 | "vi-fetch": "0.8.0",
84 | "vite": "6.3.3",
85 | "vitest": "3.0.9"
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/playwright.config.ts:
--------------------------------------------------------------------------------
1 | import { defineConfig, devices } from '@playwright/test';
2 |
3 | const projects = [
4 | {
5 | name: 'chromium',
6 | use: { ...devices['Desktop Chrome'] },
7 | },
8 | ]
9 | if (process.env.CI) {
10 | projects.push({
11 | name: 'firefox',
12 | use: { ...devices['Desktop Firefox'] },
13 | })
14 | projects.push({
15 | name: 'webkit',
16 | use: { ...devices['Desktop Safari'] },
17 | })
18 | }
19 |
20 |
21 | /**
22 | * Read environment variables from file.
23 | * https://github.com/motdotla/dotenv
24 | */
25 | // import dotenv from 'dotenv';
26 | // dotenv.config({ path: path.resolve(__dirname, '.env') });
27 |
28 | /**
29 | * See https://playwright.dev/docs/test-configuration.
30 | */
31 | export default defineConfig({
32 | testDir: './e2e',
33 | /* Run tests in files in parallel */
34 | fullyParallel: true,
35 | /* Fail the build on CI if you accidentally left test.only in the source code. */
36 | forbidOnly: !!process.env.CI,
37 | /* Retry on CI only */
38 | retries: 2,
39 | /* Opt out of parallel tests on CI. */
40 | workers: 4,
41 | /* Reporter to use. See https://playwright.dev/docs/test-reporters */
42 | reporter: 'html',
43 | /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
44 | use: {
45 | /* Base URL to use in actions like `await page.goto('/')`. */
46 | // baseURL: 'http://127.0.0.1:3000',
47 |
48 | /* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
49 | trace: 'on-first-retry',
50 | },
51 | timeout: 5 * 60 * 1000,
52 | expect: {
53 | timeout: 1000 * 10,
54 | },
55 |
56 | /* Configure projects for major browsers */
57 | projects: projects,
58 |
59 | /* Test against mobile viewports. */
60 | // {
61 | // name: 'Mobile Chrome',
62 | // use: { ...devices['Pixel 5'] },
63 | // },
64 | // {
65 | // name: 'Mobile Safari',
66 | // use: { ...devices['iPhone 12'] },
67 | // },
68 |
69 | /* Test against branded browsers. */
70 | // {
71 | // name: 'Microsoft Edge',
72 | // use: { ...devices['Desktop Edge'], channel: 'msedge' },
73 | // },
74 | // {
75 | // name: 'Google Chrome',
76 | // use: { ...devices['Desktop Chrome'], channel: 'chrome' },
77 | // },
78 |
79 | /* Run your local dev server before starting the tests */
80 | webServer: {
81 | command: 'npm run dev',
82 | url: 'http://127.0.0.1:18888',
83 | reuseExistingServer: !process.env.CI,
84 | timeout: 1000 * 60,
85 | stdout: 'pipe',
86 | stderr: 'pipe',
87 | },
88 | });
89 |
--------------------------------------------------------------------------------
/src/__test__/php.spec.ts:
--------------------------------------------------------------------------------
1 | import { expect, it } from 'vitest';
2 | import { usePHP } from '../php';
3 | // @ts-ignore
4 | import { mockFetch } from 'vi-fetch';
5 | // @ts-ignore
6 | import 'vi-fetch/setup';
7 | import * as fs from 'fs';
8 | import { renderHook } from '@testing-library/react';
9 |
10 | mockFetch.setOptions({
11 | baseUrl: '',
12 | });
13 | it.skip('should increment counter', async () => {
14 | const v = '8.3';
15 | const code = ' echo(1);';
16 |
17 | const data = fs.readFileSync(`assets/php-${v}.wasm`);
18 | const pattern = `php-${v}.wasm?.+`;
19 | mockFetch('GET', new RegExp(pattern)).willResolve(data.buffer);
20 | // When running on jsdom, it does not work well because it depends on the dom.
21 | // Runtime error occurs.
22 | const { result } = renderHook(() => usePHP(v, code));
23 | const [loading, value] = result.current;
24 | expect(loading).toBe(true);
25 | expect(value).toBe('');
26 | });
27 |
--------------------------------------------------------------------------------
/src/__test__/php.test.ts:
--------------------------------------------------------------------------------
1 | import { expect, it, describe } from 'vitest';
2 | import {convertCodeToPhpPlayground, initPHP, runPHP} from '../php';
3 | // @ts-ignore
4 | import { mockFetch } from 'vi-fetch';
5 | // @ts-ignore
6 | import 'vi-fetch/setup';
7 | import * as fs from 'fs';
8 | import { versions } from '../php-wasm/php';
9 |
10 | mockFetch.setOptions({
11 | baseUrl: '',
12 | });
13 |
14 | describe('load wasm files', async function () {
15 | versions.forEach(function (v) {
16 | it(`version: ${v} should echo 1.`, async function () {
17 | const data = fs.readFileSync(`assets/php-${v}.wasm`);
18 | const pattern = `php-${v}.wasm?.+`;
19 | mockFetch('GET', new RegExp(pattern)).willResolve(data.buffer);
20 | // Runtime error occurs, but you can ignore it because it is a problem with the way wasm is loaded.
21 | const sut = await initPHP(v);
22 | expect(sut.version).toBe(v);
23 | const actual = await runPHP(sut, 'echo(1);');
24 | expect(actual).toBe('1');
25 | });
26 | });
27 | });
28 |
29 | describe('show phpinfo()', async function () {
30 | versions.forEach(function (v) {
31 | it(`version: ${v} run phpinfo().`, async function () {
32 | const data = fs.readFileSync(`assets/php-${v}.wasm`);
33 | const pattern = `php-${v}.wasm?.+`;
34 | mockFetch('GET', new RegExp(pattern)).willResolve(data.buffer);
35 | // Runtime error occurs, but you can ignore it because it is a problem with the way wasm is loaded.
36 | const sut = await initPHP(v);
37 | expect(sut.version).toBe(v);
38 | let actual = await runPHP(sut, 'phpinfo();');
39 | // Shrink the request time
40 | actual = actual.replace(
41 | /(.+?REQUEST_TIME_FLOAT.+?)([\d.]+)(<\/td><\/tr>)/g,
42 | '$1--$3'
43 | );
44 | actual = actual.replace(
45 | /(.+?REQUEST_TIME.+?)([\d.]+)(<\/td><\/tr>)/g,
46 | '$1--$3'
47 | );
48 | expect(actual).toMatchSnapshot();
49 | });
50 | });
51 | });
52 |
53 | describe('convert code to php code for wasm', async function () {
54 |
55 | const testCases = [
56 | {"input": " echo(1);", "expected": "echo(1);"},
57 | {"input": "Hello, World"},
61 | {"input": "", "expected": "?>"},
62 | {"input": " declare(strict_types=1); echo 1;", "expected": "declare(strict_types=1); echo 1;"},
63 | {"input": " declare(ticks=1); echo 1+1?>", "expected": "?> declare(ticks=1); echo 1+1?>"},
64 | ]
65 |
66 | it.each(testCases)('input: %s to %s', async function (testCase) {
67 | const actual = convertCodeToPhpPlayground(testCase.input);
68 | expect(actual).toBe(testCase.expected);
69 | })
70 | })
71 |
--------------------------------------------------------------------------------
/src/app.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import { useEffect } from 'react';
3 | import {
4 | Flex,
5 | Box,
6 | Spacer,
7 | Text,
8 | Link,
9 | Center,
10 | Button,
11 | Switch,
12 | useColorMode,
13 | } from '@chakra-ui/react';
14 | import { useSearchParams } from 'react-router-dom';
15 | import * as lzstring from 'lz-string';
16 |
17 | import { Version, asVersion } from './php-wasm/php';
18 | import SelectPHP from './select';
19 | import { Editor } from './editor';
20 | import { BellIcon } from '@chakra-ui/icons';
21 | import { Format, SelectFormat } from './format';
22 |
23 | type UrlState = {
24 | v: Version;
25 | c: string;
26 | f: Format;
27 | };
28 |
29 | export default function App() {
30 | const [searchParams, setSearchParams] = useSearchParams();
31 | const initCode =
32 | lzstring.decompressFromEncodedURIComponent(
33 | searchParams.get('c') ?? ''
34 | ) ?? '
98 |
99 |
100 |
104 |
105 |
114 |
121 | < Request and Report
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | }
131 | href="https://github.com/sponsors/glassmonkey"
132 | as="a"
133 | colorScheme="green"
134 | >
135 | Donate
136 |
137 |
138 |
144 | Version:
145 |
146 |
150 |
151 | UI Theme:
152 |
160 |
161 |
165 |
166 |
167 |
175 |
176 | );
177 | }
178 |
--------------------------------------------------------------------------------
/src/editor.tsx:
--------------------------------------------------------------------------------
1 | import type { Version } from './php-wasm/php';
2 | import {
3 | SandpackLayout,
4 | SandpackProvider,
5 | useActiveCode,
6 | useSandpack,
7 | } from '@codesandbox/sandpack-react';
8 | import { usePHP } from './php';
9 | import { Box, Center, Flex, Spinner, useColorMode } from '@chakra-ui/react';
10 | import type { ReactElement } from 'react';
11 | import * as React from 'react';
12 | import MonacoEditor, { type OnChange } from '@monaco-editor/react';
13 | import { Format } from './format';
14 | import debounce from 'debounce';
15 |
16 | function LoadSpinner() {
17 | return (
18 |
19 |
20 |
21 | );
22 | }
23 |
24 | function PhpEditor() {
25 | const { code, updateCode } = useActiveCode();
26 | const { sandpack } = useSandpack();
27 | const { colorMode } = useColorMode();
28 |
29 | const onChangeCode: OnChange = debounce((value) => {
30 | updateCode(value || '');
31 | }, 300);
32 |
33 | return (
34 | }
43 | options={{
44 | minimap: {
45 | enabled: false,
46 | },
47 | }}
48 | />
49 | );
50 | }
51 |
52 | function PhpPreview(params: { version: Version; format: Format }) {
53 | const { sandpack } = useSandpack();
54 | const { files, activeFile } = sandpack;
55 | const code = files[activeFile].code;
56 | const [loading, result] = usePHP(params.version, code);
57 |
58 | if (loading) {
59 | return ;
60 | }
61 | if (params.format === 'console') {
62 | return (
63 |
72 | {result}
73 |
74 | );
75 | }
76 |
77 | return (
78 |
85 | );
86 | }
87 |
88 | function PhpCodeCallback(params: { onChangeCode: (code: string) => void }) {
89 | const { sandpack } = useSandpack();
90 | const { files, activeFile } = sandpack;
91 | const code = files[activeFile].code;
92 | params.onChangeCode(code);
93 | return <>>;
94 | }
95 |
96 | function EditorLayout(params: { Editor: ReactElement; Preview: ReactElement }) {
97 | return (
98 |
99 |
106 |
112 |
120 | {params.Editor}
121 |
122 |
123 |
130 | {params.Preview}
131 |
132 |
133 |
134 | );
135 | }
136 |
137 | export function Editor(params: {
138 | initCode: string;
139 | version: Version;
140 | format: Format;
141 | onChangeCode: (code: string) => void;
142 | }) {
143 | return (
144 |
152 | }
154 | Preview={
155 |
159 | }
160 | />
161 |
162 |
163 | );
164 | }
165 |
--------------------------------------------------------------------------------
/src/footer.tsx:
--------------------------------------------------------------------------------
1 | import { Flex, HStack, Text } from '@chakra-ui/react';
2 | import * as React from 'react';
3 |
4 | export default function Footer() {
5 | return (
6 |
7 |
8 |
9 |
10 | Privacy Policy
11 |
12 |
13 |
14 |
19 | Contact
20 |
21 |
22 |
23 |
24 | © 2023{' '}
25 |
30 | @glassmonekey
31 |
32 |
33 |
34 | );
35 | }
36 |
--------------------------------------------------------------------------------
/src/format.tsx:
--------------------------------------------------------------------------------
1 | import { Checkbox } from '@chakra-ui/react';
2 | import * as React from 'react';
3 | import { useState } from 'react';
4 |
5 | export type Format = 'html' | 'console';
6 |
7 | export function SelectFormat({
8 | format,
9 | updateFormat,
10 | }: {
11 | format: Format;
12 | updateFormat: (f: Format) => void;
13 | }) {
14 | const [isHtml, setIsHtml] = useState(format === 'html');
15 |
16 | return (
17 | {
21 | updateFormat(e.target.checked ? 'html' : 'console');
22 | setIsHtml(e.target.checked);
23 | }}
24 | >
25 | HTML Preview
26 |
27 | );
28 | }
29 |
--------------------------------------------------------------------------------
/src/header.tsx:
--------------------------------------------------------------------------------
1 | import { Heading, Text, Flex, Center } from '@chakra-ui/react';
2 | import * as React from 'react';
3 |
4 | export default function Header() {
5 | return (
6 |
7 |
8 | PHP Playground
9 |
10 |
11 | PHP Playground let you to execute basic PHP code in real time
12 | using WebAssembly technology.
13 |
14 |
15 |
16 |
17 | About PHP Playground?
18 |
19 |
20 |
21 |
22 | );
23 | }
24 |
--------------------------------------------------------------------------------
/src/index.tsx:
--------------------------------------------------------------------------------
1 | import * as React from 'react';
2 | import * as ReactDOM from 'react-dom/client';
3 | import { ChakraProvider, Center, Box, ColorModeScript } from '@chakra-ui/react';
4 | import App from './app';
5 | import { createBrowserRouter, RouterProvider } from 'react-router-dom';
6 | import Header from './header';
7 | import Footer from './footer';
8 | import Manual from './manual';
9 | import theme from './theme';
10 |
11 | const router = createBrowserRouter([
12 | {
13 | path: '*',
14 | element: ,
15 | },
16 | ]);
17 |
18 | const root = ReactDOM.createRoot(document.getElementById('app')!);
19 | root.render(
20 | <>
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | >
35 | );
36 |
--------------------------------------------------------------------------------
/src/manual.tsx:
--------------------------------------------------------------------------------
1 | import { Box, Heading, Link, Text, Flex } from '@chakra-ui/react';
2 | import React from 'react';
3 |
4 | export default function Manual() {
5 | return (
6 |
7 |
8 | About PHP Playground
9 |
10 |
11 | Description
12 |
13 |
14 | The Playground let you to execute basic{' '}
15 |
16 | PHP
17 | {' '}
18 | code in real time using WebAssembly technology.
19 |
20 |
21 | The code you write can be immediately shared with your
22 | friends via URL.
23 |
24 |
25 |
26 |
27 |
28 | Usage
29 |
30 |
31 | Simply enter the PHP code into the form. The result of
32 | the execution output will be displayed in Iframe as
33 | HTML.
34 |
35 |
36 | Additionally, by selecting a different PHP version from
37 | the select box, you can switch between versions without
38 | having to change the currently running PHP execution
39 | code. This allows you to experience the differences in
40 | PHP execution between different versions.
41 |
42 |
43 | The URL parameter is saved with the status when the code
44 | is entered, and can be bookmarked or referred to a
45 | friend if necessary. Please use it to share snippets of
46 | your code review.
47 |
48 |
49 |
50 |
51 | Security
52 |
53 |
54 | PHP code is very secure because it is executed only
55 | within the browser using WebAssembly technology.
56 |
57 |
58 | In addition, the results of the execution are output to
59 | an iframe using an empty{' '}
60 |
64 | sandbox attribute
65 |
66 | , so no JavaScript or other code will run.{' '}
67 |
68 |
69 |
70 |
71 |
72 | Request & Report
73 |
74 |
75 | If you have any problems or feature requests, please
76 | contact{' '}
77 |
81 | Issue
82 | {' '}
83 | or{' '}
84 |
88 | DM
89 |
90 | .
91 |
92 |
93 |
94 |
95 | );
96 | }
97 |
--------------------------------------------------------------------------------
/src/php-wasm/__tests__/utils.ts:
--------------------------------------------------------------------------------
1 | // Shim the browser's file class
2 | export class File {
3 | data;
4 | name;
5 |
6 | constructor(data, name) {
7 | this.data = data;
8 | this.name = name;
9 | }
10 |
11 | get size() {
12 | return this.data.length;
13 | }
14 |
15 | get type() {
16 | return 'text/plain';
17 | }
18 |
19 | arrayBuffer() {
20 | return new ArrayBuffer(toUint8Array(this.data));
21 | }
22 | }
23 |
24 | function toUint8Array(data) {
25 | if (typeof data === 'string') {
26 | return new TextEncoder().encode(data).buffer;
27 | } else if (data instanceof ArrayBuffer) {
28 | data = new Uint8Array(data);
29 | } else if (Array.isArray(data)) {
30 | if (data[0] instanceof Number) {
31 | return new Uint8Array(data);
32 | }
33 | return toUint8Array(data[0]);
34 | } else if (data instanceof Uint8Array) {
35 | return data.buffer;
36 | } else {
37 | throw new Error('Unsupported data type');
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/src/php-wasm/index.ts:
--------------------------------------------------------------------------------
1 | export { PHP, startPHP } from './php';
2 | export type {
3 | PHPOutput,
4 | PHPRequest,
5 | PHPResponse,
6 | JavascriptRuntime,
7 | ErrnoError,
8 | } from './php';
9 |
10 | import PHPServer from './php-server';
11 | export { PHPServer };
12 | export type { PHPServerConfigation, PHPServerRequest } from './php-server';
13 |
14 | import PHPBrowser from './php-browser';
15 | export { PHPBrowser };
16 |
17 | export { DEFAULT_BASE_URL, getPathQueryFragment } from '../php-wasm/utils';
18 |
--------------------------------------------------------------------------------
/src/php-wasm/php-browser.ts:
--------------------------------------------------------------------------------
1 | import type PHPServer from './php-server';
2 | import type { PHPServerRequest } from './php-server';
3 | import type { PHPResponse } from './php';
4 |
5 | /**
6 | * A fake web browser that handles PHPServer's cookies and redirects
7 | * internally without exposing them to the consumer.
8 | *
9 | * @public
10 | */
11 | export class PHPBrowser {
12 | #cookies;
13 | #config;
14 |
15 | server: PHPServer;
16 |
17 | /**
18 | * @param server - The PHP server to browse.
19 | * @param config - The browser configuration.
20 | */
21 | constructor(server: PHPServer, config: PHPBrowserConfiguration = {}) {
22 | this.server = server;
23 | this.#cookies = {};
24 | this.#config = {
25 | handleRedirects: false,
26 | maxRedirects: 4,
27 | ...config,
28 | };
29 | }
30 |
31 | /**
32 | * Sends the request to the server.
33 | *
34 | * When cookies are present in the response, this method stores
35 | * them and sends them with any subsequent requests.
36 | *
37 | * When a redirection is present in the response, this method
38 | * follows it by discarding a response and sending a subsequent
39 | * request.
40 | *
41 | * @param request - The request.
42 | * @param redirects - Internal. The number of redirects handled so far.
43 | * @returns PHPServer response.
44 | */
45 | async request(
46 | request: PHPServerRequest,
47 | redirects = 0
48 | ): Promise {
49 | const response = await this.server.request({
50 | ...request,
51 | headers: {
52 | ...request.headers,
53 | cookie: this.#serializeCookies(),
54 | },
55 | });
56 |
57 | if (response.headers['set-cookie']) {
58 | this.#setCookies(response.headers['set-cookie']);
59 | }
60 |
61 | if (
62 | this.#config.handleRedirects &&
63 | response.headers.location &&
64 | redirects < this.#config.maxRedirects
65 | ) {
66 | const redirectUrl = new URL(
67 | response.headers.location[0],
68 | this.server.absoluteUrl
69 | );
70 | return this.request(
71 | {
72 | absoluteUrl: redirectUrl.toString(),
73 | method: 'GET',
74 | headers: {},
75 | },
76 | redirects + 1
77 | );
78 | }
79 |
80 | return response;
81 | }
82 |
83 | #setCookies(cookies) {
84 | for (const cookie of cookies) {
85 | try {
86 | if (!cookie.includes('=')) {
87 | continue;
88 | }
89 | const equalsIndex = cookie.indexOf('=');
90 | const name = cookie.substring(0, equalsIndex);
91 | const value = cookie.substring(equalsIndex + 1).split(';')[0];
92 | this.#cookies[name] = value;
93 | } catch (e) {
94 | console.error(e);
95 | }
96 | }
97 | }
98 |
99 | #serializeCookies() {
100 | const cookiesArray: string[] = [];
101 | for (const name in this.#cookies) {
102 | cookiesArray.push(`${name}=${this.#cookies[name]}`);
103 | }
104 | return cookiesArray.join('; ');
105 | }
106 | }
107 |
108 | interface PHPBrowserConfiguration {
109 | /**
110 | * Should handle redirects internally?
111 | */
112 | handleRedirects?: boolean;
113 | /**
114 | * The maximum number of redirects to follow internally. Once
115 | * exceeded, request() will return the redirecting response.
116 | */
117 | maxRedirects?: number;
118 | }
119 |
120 | export default PHPBrowser;
121 |
--------------------------------------------------------------------------------
/src/php-wasm/php-server.ts:
--------------------------------------------------------------------------------
1 | import {
2 | ensurePathPrefix,
3 | getPathQueryFragment,
4 | removePathPrefix,
5 | } from './utils';
6 | import type { FileInfo, PHP, PHPRequest, PHPResponse } from './php';
7 |
8 | export type PHPServerRequest = Pick<
9 | PHPRequest,
10 | 'method' | 'headers' | 'body'
11 | > & {
12 | absoluteUrl: string;
13 | files?: Record;
14 | };
15 |
16 | /**
17 | * A fake PHP server that handles HTTP requests but does not
18 | * bind to any port.
19 | *
20 | * @public
21 | * @example
22 | * ```js
23 | * import { createPHP, PHPServer } from 'php-wasm';
24 | *
25 | * const PHPLoaderModule = await import('/php.js');
26 | * const php = await createPHP(PHPLoaderModule);
27 | *
28 | * // Create a file to serve:
29 | * php.mkdirTree('/www');
30 | * php.writeFile('/www/index.php', ' boolean;
61 |
62 | /**
63 | * @param php - The PHP instance.
64 | * @param config - Server configuration.
65 | */
66 | constructor(php: PHP, config: PHPServerConfigation) {
67 | const {
68 | documentRoot = '/var/www/',
69 | absoluteUrl,
70 | isStaticFilePath = () => false,
71 | } = config;
72 | this.php = php;
73 | this.#DOCROOT = documentRoot;
74 | this.#isStaticFilePath = isStaticFilePath;
75 |
76 | const url = new URL(absoluteUrl);
77 | this.#HOSTNAME = url.hostname;
78 | this.#PORT = url.port
79 | ? Number(url.port)
80 | : url.protocol === 'https:'
81 | ? 443
82 | : 80;
83 | this.#PROTOCOL = (url.protocol || '').replace(':', '');
84 | const isNonStandardPort = this.#PORT !== 443 && this.#PORT !== 80;
85 | this.#HOST = [
86 | this.#HOSTNAME,
87 | isNonStandardPort ? `:${this.#PORT}` : '',
88 | ].join('');
89 | this.#PATHNAME = url.pathname.replace(/\/+$/, '');
90 | this.#ABSOLUTE_URL = [
91 | `${this.#PROTOCOL}://`,
92 | this.#HOST,
93 | this.#PATHNAME,
94 | ].join('');
95 | }
96 |
97 | /**
98 | * The absolute URL of this PHPServer instance.
99 | */
100 | get absoluteUrl() {
101 | return this.#ABSOLUTE_URL;
102 | }
103 |
104 | /**
105 | * Serves the request – either by serving a static file, or by
106 | * dispatching it to the PHP runtime.
107 | *
108 | * @param request - The request.
109 | * @returns The response.
110 | */
111 | async request(request: PHPServerRequest): Promise {
112 | const serverPath = removePathPrefix(
113 | new URL(request.absoluteUrl).pathname,
114 | this.#PATHNAME
115 | );
116 | if (this.#isStaticFilePath(serverPath)) {
117 | return this.#serveStaticFile(serverPath);
118 | }
119 | return await this.#dispatchToPHP(request);
120 | }
121 |
122 | /**
123 | * Serves a static file from the PHP filesystem.
124 | *
125 | * @param path - The requested static file path.
126 | * @returns The response.
127 | */
128 | #serveStaticFile(path: string): PHPResponse {
129 | const fsPath = `${this.#DOCROOT}${path}`;
130 |
131 | if (!this.php.fileExists(fsPath)) {
132 | return {
133 | body: new TextEncoder().encode('404 File not found'),
134 | headers: {},
135 | httpStatusCode: 404,
136 | exitCode: 0,
137 | errors: '',
138 | };
139 | }
140 | const arrayBuffer = this.php.readFileAsBuffer(fsPath);
141 | return {
142 | body: arrayBuffer,
143 | headers: {
144 | 'content-length': `${arrayBuffer.byteLength}`,
145 | // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
146 | // The code below won't return the correct mime-type if the extension
147 | // was tampered with.
148 | 'content-type': inferMimeType(fsPath),
149 | 'accept-ranges': 'bytes',
150 | 'cache-control': 'public, max-age=0',
151 | },
152 | httpStatusCode: 200,
153 | exitCode: 0,
154 | errors: '',
155 | };
156 | }
157 |
158 | /**
159 | * Runs the requested PHP file with all the request and $_SERVER
160 | * superglobals populated.
161 | *
162 | * @param request - The request.
163 | * @returns The response.
164 | */
165 | async #dispatchToPHP(request: PHPServerRequest): Promise {
166 | this.php.addServerGlobalEntry('DOCUMENT_ROOT', this.#DOCROOT);
167 | this.php.addServerGlobalEntry(
168 | 'HTTPS',
169 | this.#ABSOLUTE_URL.startsWith('https://') ? 'on' : ''
170 | );
171 |
172 | const fileInfos: FileInfo[] = [];
173 | if (request.files) {
174 | for (const key in request.files) {
175 | const file: File = request.files[key];
176 | fileInfos.push({
177 | key,
178 | name: file.name,
179 | type: file.type,
180 | data: new Uint8Array(await file.arrayBuffer()),
181 | });
182 | }
183 | }
184 |
185 | const requestedUrl = new URL(request.absoluteUrl);
186 | return this.php.run({
187 | relativeUri: ensurePathPrefix(
188 | getPathQueryFragment(requestedUrl),
189 | this.#PATHNAME
190 | ),
191 | protocol: this.#PROTOCOL,
192 | method: request.method,
193 | body: request.body,
194 | fileInfos,
195 | scriptPath: this.#resolvePHPFilePath(requestedUrl.pathname),
196 | headers: {
197 | ...(request.headers || {}),
198 | host: this.#HOST,
199 | },
200 | });
201 | }
202 |
203 | /**
204 | * Resolve the requested path to the filesystem path of the requested PHP file.
205 | *
206 | * Fall back to index.php as if there was a url rewriting rule in place.
207 | *
208 | * @param requestedPath - The requested pathname.
209 | * @returns The resolved filesystem path.
210 | */
211 | #resolvePHPFilePath(requestedPath: string): string {
212 | let filePath = removePathPrefix(requestedPath, this.#PATHNAME);
213 |
214 | // If the path mentions a .php extension, that's our file's path.
215 | if (filePath.includes('.php')) {
216 | filePath = filePath.split('.php')[0] + '.php';
217 | } else {
218 | // Otherwise, let's assume the file is $request_path/index.php
219 | if (!filePath.endsWith('/')) {
220 | filePath += '/';
221 | }
222 | if (!filePath.endsWith('index.php')) {
223 | filePath += 'index.php';
224 | }
225 | }
226 |
227 | const resolvedFsPath = `${this.#DOCROOT}${filePath}`;
228 | if (this.php.fileExists(resolvedFsPath)) {
229 | return resolvedFsPath;
230 | }
231 | return `${this.#DOCROOT}/index.php`;
232 | }
233 | }
234 |
235 | /**
236 | * Naively infer a file mime type from its path.
237 | *
238 | * @todo Infer the mime type based on the file contents.
239 | * A naive function like this one can be inaccurate
240 | * and potentially have negative security consequences.
241 | *
242 | * @param path - The file path
243 | * @returns The inferred mime type.
244 | */
245 | function inferMimeType(path: string): string {
246 | const extension = path.split('.').pop();
247 | switch (extension) {
248 | case 'css':
249 | return 'text/css';
250 | case 'js':
251 | return 'application/javascript';
252 | case 'png':
253 | return 'image/png';
254 | case 'jpg':
255 | case 'jpeg':
256 | return 'image/jpeg';
257 | case 'gif':
258 | return 'image/gif';
259 | case 'svg':
260 | return 'image/svg+xml';
261 | case 'woff':
262 | return 'font/woff';
263 | case 'woff2':
264 | return 'font/woff2';
265 | case 'ttf':
266 | return 'font/ttf';
267 | case 'otf':
268 | return 'font/otf';
269 | case 'eot':
270 | return 'font/eot';
271 | case 'ico':
272 | return 'image/x-icon';
273 | case 'html':
274 | return 'text/html';
275 | case 'json':
276 | return 'application/json';
277 | case 'xml':
278 | return 'application/xml';
279 | case 'txt':
280 | case 'md':
281 | return 'text/plain';
282 | default:
283 | return 'application-octet-stream';
284 | }
285 | }
286 |
287 | export interface PHPServerConfigation {
288 | /**
289 | * The directory in the PHP filesystem where the server will look
290 | * for the files to serve. Default: `/var/www`.
291 | */
292 | documentRoot: string;
293 | /**
294 | * Server URL. Used to populate $_SERVER details like HTTP_HOST.
295 | */
296 | absoluteUrl: string;
297 | /**
298 | * Callback used by the PHPServer to decide whether
299 | * the requested path refers to a PHP file or a static file.
300 | */
301 | isStaticFilePath?: (path: string) => boolean;
302 | }
303 |
304 | export default PHPServer;
305 |
--------------------------------------------------------------------------------
/src/php-wasm/utils.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * The default base used to convert a path into the URL object.
3 | */
4 | export const DEFAULT_BASE_URL = 'http://example.com';
5 |
6 | /**
7 | * Returns a string representing the path, query, and
8 | * fragment of the given URL.
9 | *
10 | * @example
11 | * ```js
12 | * const url = new URL('http://example.com/foo/bar?baz=qux#quux');
13 | * getPathQueryFragment(url); // '/foo/bar?baz=qux#quux'
14 | * ```
15 | *
16 | * @param url The URL.
17 | * @returns The path, query, and fragment.
18 | */
19 | export function getPathQueryFragment(url: URL): string {
20 | return url.toString().substring(url.origin.length);
21 | }
22 |
23 | /**
24 | * Removes the given prefix from the given path.
25 | *
26 | * @example
27 | * ```js
28 | * removePathPrefix('/foo/bar', '/foo'); // '/bar'
29 | * removePathPrefix('/bar', '/foo'); // '/bar'
30 | * ```
31 | *
32 | * @param path The path to remove the prefix from.
33 | * @param prefix The prefix to remove.
34 | * @returns Path with the prefix removed.
35 | */
36 | export function removePathPrefix(path: string, prefix: string): string {
37 | if (!prefix || !path.startsWith(prefix)) {
38 | return path;
39 | }
40 | return path.substring(prefix.length);
41 | }
42 |
43 | /**
44 | * Ensures the given path has the given prefix.
45 | *
46 | * @example
47 | * ```js
48 | * ensurePathPrefix('/bar', '/foo'); // '/foo/bar'
49 | * ensurePathPrefix('/foo/bar', '/foo'); // '/foo/bar'
50 | * ```
51 | *
52 | * @param path
53 | * @param prefix
54 | * @returns Path with the prefix added.
55 | */
56 | export function ensurePathPrefix(path: string, prefix: string): string {
57 | if (!prefix || path.startsWith(prefix)) {
58 | return path;
59 | }
60 | return prefix + path;
61 | }
62 |
--------------------------------------------------------------------------------
/src/php.ts:
--------------------------------------------------------------------------------
1 | import { PHP, startPHP, Version } from './php-wasm/php';
2 | import { useEffect, useState } from 'react';
3 |
4 | async function loadPHPLoaderModule(v: Version) {
5 | switch (v) {
6 | case '5.6':
7 | // @ts-ignore
8 | return import('./wasm-assets/php-5.6.js');
9 | case '7.0':
10 | // @ts-ignore
11 | return import('./wasm-assets/php-7.0.js');
12 | case '7.1':
13 | // @ts-ignore
14 | return import('./wasm-assets/php-7.1.js');
15 | case '7.2':
16 | // @ts-ignore
17 | return import('./wasm-assets/php-7.2.js');
18 | case '7.3':
19 | // @ts-ignore
20 | return import('./wasm-assets/php-7.3.js');
21 | case '7.4':
22 | // @ts-ignore
23 | return import('./wasm-assets/php-7.4.js');
24 | case '8.0':
25 | // @ts-ignore
26 | return import('./wasm-assets/php-8.0.js');
27 | case '8.1':
28 | // @ts-ignore
29 | return import('./wasm-assets/php-8.1.js');
30 | case '8.2':
31 | // @ts-ignore
32 | return import('./wasm-assets/php-8.2.js');
33 | case '8.3':
34 | // @ts-ignore
35 | return import('./wasm-assets/php-8.3.js');
36 | case '8.4':
37 | // @ts-ignore
38 | return import('./wasm-assets/php-8.4.js');
39 | default:
40 | /* eslint no-case-declarations: 0 */
41 | /* eslint @typescript-eslint/no-unused-vars: 0 */
42 | const x: never = v;
43 | throw Error('not defined version');
44 | }
45 | }
46 |
47 | export async function initPHP(v: Version) {
48 | // todo handling when load failed
49 | const PHPLoaderModule = await loadPHPLoaderModule(v);
50 | return startPHP(v, PHPLoaderModule, 'WEB', {});
51 | }
52 |
53 | export async function runPHP(php: PHP, code: string) {
54 | const output = php.run({
55 | code: code,
56 | });
57 | return new TextDecoder().decode(output.body);
58 | }
59 |
60 | // Convert code to PHP code
61 | export function convertCodeToPhpPlayground(code: string) {
62 | const phpPrefixPattern = /^<\?(php)?\s+/g;
63 |
64 | const hasPhpPrefix = code.match(phpPrefixPattern);
65 | let phpCode = code.replace(phpPrefixPattern, '');
66 | // Add PHP tag if not exists
67 | if (!hasPhpPrefix) {
68 | phpCode = '?>' + phpCode;
69 | }
70 | return phpCode;
71 | }
72 |
73 | export function usePHP(version: Version, code: string): [boolean, string] {
74 | const [php, setPHP] = useState(null);
75 | const [loading, setLoading] = useState(false);
76 | const [internalCode, setInternalCode] = useState('');
77 | const [result, setResult] = useState('');
78 |
79 | const phpCode = convertCodeToPhpPlayground(code);
80 |
81 | useEffect(
82 | function () {
83 | if (php?.version != version) {
84 | setLoading(true);
85 | queueMicrotask(async function () {
86 | setPHP(await initPHP(version));
87 | });
88 | return;
89 | }
90 |
91 | if (internalCode != phpCode) {
92 | setLoading(true);
93 |
94 | setInternalCode(phpCode);
95 | return;
96 | }
97 | if (!loading) {
98 | return;
99 | }
100 |
101 | if (internalCode == '') {
102 | setResult('empty data');
103 | setLoading(false);
104 | return;
105 | }
106 |
107 | setTimeout(async function () {
108 | const info = await runPHP(php, internalCode);
109 | setResult(info);
110 | setLoading(false);
111 | }, 15);
112 | },
113 | [php, code, internalCode, loading, version]
114 | );
115 |
116 | return [loading, result];
117 | }
118 |
--------------------------------------------------------------------------------
/src/select.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import Select from 'react-select';
3 | import { Version, versions } from './php-wasm/php';
4 |
5 | const phpOptions = versions.map((v) => ({
6 | value: v,
7 | label: v,
8 | }));
9 |
10 | export default function SelectPHP({
11 | version,
12 | onChange,
13 | }: {
14 | version: Version;
15 | onChange: (version: Version) => void;
16 | }) {
17 | const versionIndex = versions.findIndex((v) => v == version);
18 | const currentPhpOption = phpOptions[versionIndex];
19 |
20 | return (
21 | ({
26 | ...baseStyles,
27 | color: 'black',
28 | fontSize: '14px',
29 | }),
30 | control: (baseStyles) => ({
31 | ...baseStyles,
32 | color: 'black',
33 | fontSize: '14px',
34 | }),
35 | }}
36 | options={phpOptions}
37 | defaultValue={currentPhpOption}
38 | onChange={(option) => {
39 | if (option !== currentPhpOption) {
40 | onChange(option?.value ?? currentPhpOption.value);
41 | }
42 | }}
43 | />
44 | );
45 | }
46 |
--------------------------------------------------------------------------------
/src/switch.tsx:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 | import { HiMoon, HiSun } from 'react-icons/hi';
3 | import { switchAnatomy } from '@chakra-ui/anatomy';
4 | import { createMultiStyleConfigHelpers } from '@chakra-ui/react';
5 | import ReactDOMServer from 'react-dom/server';
6 |
7 | function extendSwitchTheme() {
8 | const { definePartsStyle, defineMultiStyleConfig } =
9 | createMultiStyleConfigHelpers(switchAnatomy.keys);
10 |
11 | const darkModeIcon = ReactDOMServer.renderToString( );
12 |
13 | const lightModeIcon = ReactDOMServer.renderToString( );
14 |
15 | const template = 'data:image/svg+xml;utf8,$';
16 |
17 | const colormodeSwitcher = definePartsStyle({
18 | track: {
19 | background: '#f1bf5a', // yellow
20 | _dark: {
21 | background: '#51555E', // grey
22 | },
23 | },
24 | thumb: {
25 | bg: 'transparent',
26 | backgroundImage: template.replaceAll('$', lightModeIcon),
27 | _dark: {
28 | backgroundImage: template.replaceAll('$', darkModeIcon),
29 | },
30 | backgroundRepeat: 'no-repeat',
31 | marginTop: '8.5%',
32 | marginLeft: '9.5%',
33 | color: 'white',
34 | },
35 | });
36 |
37 | return defineMultiStyleConfig({ variants: { colormodeSwitcher } });
38 | }
39 |
40 | export const switchTheme = extendSwitchTheme();
41 |
--------------------------------------------------------------------------------
/src/theme.tsx:
--------------------------------------------------------------------------------
1 | import { extendTheme, type ThemeConfig } from '@chakra-ui/react';
2 | import { switchTheme } from './switch';
3 |
4 | const config: ThemeConfig = {
5 | initialColorMode: 'system',
6 | useSystemColorMode: true,
7 | };
8 |
9 | const theme = extendTheme({
10 | config,
11 | components: { Switch: switchTheme },
12 | });
13 |
14 | export default theme;
15 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/bison27.patch:
--------------------------------------------------------------------------------
1 | Subject: Use Bison 2.7 to compile PHP 5.6
2 |
3 | This workaround enables building Bison 2.7 on arm64 architecture
4 | so that it can be used to compile PHP 5.6.
5 |
6 | Derived from the OpenWRT project:
7 |
8 | https://github.com/rdslw/openwrt/blob/e5d47f32131849a69a9267de51a30d6be1f0d0ac/tools/bison/patches/110-glibc-change-work-around.patch
9 |
10 | --- a/lib/stdio-impl.h
11 | +++ b/lib/stdio-impl.h
12 | @@ -18,6 +18,12 @@
13 | the same implementation of stdio extension API, except that some fields
14 | have different naming conventions, or their access requires some casts. */
15 |
16 | +/* Glibc 2.28 made _IO_IN_BACKUP private. For now, work around this
17 | + problem by defining it ourselves. FIXME: Do not rely on glibc
18 | + internals. */
19 | +#if !defined _IO_IN_BACKUP && defined _IO_EOF_SEEN
20 | +# define _IO_IN_BACKUP 0x100
21 | +#endif
22 |
23 | /* BSD stdio derived implementations. */
24 |
25 | --- a/lib/fseterr.c
26 | +++ b/lib/fseterr.c
27 | @@ -29,7 +29,7 @@
28 | /* Most systems provide FILE as a struct and the necessary bitmask in
29 | , because they need it for implementing getc() and putc() as
30 | fast macros. */
31 | -#if defined _IO_ftrylockfile || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
32 | +#if defined _IO_EOF_SEEN || __GNU_LIBRARY__ == 1 /* GNU libc, BeOS, Haiku, Linux libc5 */
33 | fp->_flags |= _IO_ERR_SEEN;
34 | #elif defined __sferror || defined __DragonFly__ /* FreeBSD, NetBSD, OpenBSD, DragonFly, Mac OS X, Cygwin */
35 | fp_->_flags |= __SERR;
36 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/ncurses.patch:
--------------------------------------------------------------------------------
1 | diff --git a/ncurses/Makefile.in b/ncurses/Makefile.in
2 | --- a/ncurses/Makefile.in
3 | +++ b/ncurses/Makefile.in
4 | @@ -229,42 +229,24 @@
5 | ./lib_gen.c : $(base)/MKlib_gen.sh ../include/curses.h
6 | $(SHELL) -e $(base)/MKlib_gen.sh "$(CPP) $(CPPFLAGS)" "$(AWK)" generated <../include/curses.h >$@
7 |
8 | -init_keytry.h: make_keys$(BUILD_EXEEXT) keys.list
9 | - ./make_keys$(BUILD_EXEEXT) keys.list > $@
10 | +init_keytry.h: make_keys_x86$(BUILD_EXEEXT) keys.list
11 | + ./make_keys_x86$(BUILD_EXEEXT) keys.list > $@
12 |
13 | keys.list : $(tinfo)/MKkeys_list.sh
14 | AWK=$(AWK) $(SHELL) $(tinfo)/MKkeys_list.sh $(CAPLIST) | LC_ALL=C sort >$@
15 |
16 | -make_keys$(BUILD_EXEEXT) : \
17 | - build.priv.h \
18 | - $(tinfo)/make_keys.c \
19 | - names.c
20 | - $(BUILD_CC) -o $@ $(BUILD_CPPFLAGS) $(BUILD_CCFLAGS) $(tinfo)/make_keys.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
21 | -
22 | -make_hash$(BUILD_EXEEXT) : \
23 | - build.priv.h \
24 | - $(tinfo)/make_hash.c \
25 | - ../include/hashsize.h
26 | - $(BUILD_CC) -o $@ $(BUILD_CPPFLAGS) $(BUILD_CCFLAGS) $(tinfo)/make_hash.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
27 | -
28 | -report_offsets$(BUILD_EXEEXT) : \
29 | - $(srcdir)/curses.priv.h \
30 | - $(srcdir)/report_offsets.c
31 | - $(BUILD_CC) -o $@ $(BUILD_CPPFLAGS) $(BUILD_CCFLAGS) $(srcdir)/report_offsets.c $(BUILD_LDFLAGS) $(BUILD_LIBS)
32 | - ./report_offsets$(BUILD_EXEEXT)
33 | -
34 | ./expanded.c : $(srcdir)/curses.priv.h $(serial)/MKexpanded.sh
35 | $(SHELL) -e $(serial)/MKexpanded.sh "$(CPP)" $(CPPFLAGS) > $@
36 |
37 | ./comp_captab.c: \
38 | - make_hash$(BUILD_EXEEXT) \
39 | + make_hash_x86$(BUILD_EXEEXT) \
40 | ../include/hashsize.h \
41 | $(tinfo)/MKcaptab.sh \
42 | $(tinfo)/MKcaptab.awk
43 | $(SHELL) -e $(tinfo)/MKcaptab.sh $(AWK) $(USE_BIG_STRINGS) $(tinfo)/MKcaptab.awk $(CAPLIST) > $@
44 |
45 | ./comp_userdefs.c: \
46 | - make_hash$(BUILD_EXEEXT) \
47 | + make_hash_x86$(BUILD_EXEEXT) \
48 | ../include/hashsize.h \
49 | $(tinfo)/MKuserdefs.sh
50 | $(SHELL) -e $(tinfo)/MKuserdefs.sh $(AWK) $(USE_BIG_STRINGS) $(CAPLIST) > $@
51 | @@ -294,9 +276,6 @@
52 |
53 | clean :: mostlyclean
54 | -rm -f $(AUTO_SRC)
55 | - -rm -f make_keys$(BUILD_EXEEXT)
56 | - -rm -f make_hash$(BUILD_EXEEXT)
57 | - -rm -f report_offsets$(BUILD_EXEEXT)
58 | -rm -rf .libs *.dSYM *.map
59 |
60 | distclean :: clean
61 | --- a/ncurses/tinfo/MKcaptab.sh 2023-01-27 10:29:09.342505012 +0000
62 | +++ b/ncurses/tinfo/MKcaptab.sh 2020-02-02 23:34:34.000000000 +0000
63 | @@ -71,8 +71,8 @@
64 | /* *INDENT-OFF* */
65 | EOF
66 |
67 | -cat "$@" |./make_hash 1 info $OPT1
68 | -cat "$@" |./make_hash 3 cap $OPT1
69 | +cat "$@" |./make_hash_x86 1 info $OPT1
70 | +cat "$@" |./make_hash_x86 3 cap $OPT1
71 |
72 | cat "$@" |$AWK -f $OPT2 bigstrings=$OPT1 tablename=capalias
73 |
74 | --- a/ncurses/tinfo/MKuserdefs.sh 2023-01-27 10:29:59.298519008 +0000
75 | +++ b/ncurses/tinfo/MKuserdefs.sh 2020-02-02 23:34:34.000000000 +0000
76 | @@ -51,7 +51,7 @@
77 | #if NCURSES_XNAMES
78 | EOF
79 |
80 | -cat "$@" | ./make_hash 1 user $OPT1
81 | +cat "$@" | ./make_hash_x86 1 user $OPT1
82 |
83 | cat <driver_data;
12 | if (!S->stmt) {
13 |
14 |
15 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
16 | --- a/php-src/ext/standard/file.c
17 | +++ b/php-src/ext/standard/file.c
18 | @@ -1691,18 +1691,32 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
19 | php_stream *srcstream = NULL, *deststream = NULL;
20 | int ret = FAILURE;
21 | php_stream_statbuf src_s, dest_s;
22 |
23 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
24 | case -1:
25 | /* non-statable stream */
26 | goto safe_to_copy;
27 | break;
28 | case 0:
29 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
30 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
31 | + // runtime.
32 | + // Solution: Avoid copying empty files. Just create create an empty
33 | + // destination file and return.
34 | + if (src_s.sb.st_size == 0) {
35 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
36 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
37 | + if (stream) {
38 | + php_stream_close(stream);
39 | + return SUCCESS;
40 | + }
41 | + return FAILURE;
42 | + }
43 | break;
44 | default: /* failed to stat file, does not exist? */
45 | return ret;
46 | }
47 | if (S_ISDIR(src_s.sb.st_mode)) {
48 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
49 | return FAILURE;
50 | }
51 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
52 | --- a/php-src/main/streams/cast.c
53 | +++ b/php-src/main/streams/cast.c
54 | @@ -113,10 +113,10 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
55 | return 0;
56 | }
57 | # else
58 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
59 | +static int stream_cookie_seeker(void *cookie, long long *position, int whence)
60 | {
61 |
62 | - return php_stream_seek((php_stream *)cookie, position, whence);
63 | + return php_stream_seek((php_stream *)cookie, *position, whence);
64 | }
65 | # endif
66 |
67 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php7.1.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
2 | --- a/php-src/ext/pdo_sqlite/sqlite_statement.c
3 | +++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
4 | @@ -299,7 +299,7 @@ static int pdo_sqlite_stmt_describe(pdo_stmt_t *stmt, int colno)
5 | return 1;
6 | }
7 |
8 | -static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees)
9 | +static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees)
10 | {
11 | pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
12 | if (!S->stmt) {
13 |
14 |
15 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
16 | --- a/php-src/ext/standard/file.c
17 | +++ b/php-src/ext/standard/file.c
18 | @@ -1691,18 +1691,32 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
19 | php_stream *srcstream = NULL, *deststream = NULL;
20 | int ret = FAILURE;
21 | php_stream_statbuf src_s, dest_s;
22 |
23 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
24 | case -1:
25 | /* non-statable stream */
26 | goto safe_to_copy;
27 | break;
28 | case 0:
29 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
30 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
31 | + // runtime.
32 | + // Solution: Avoid copying empty files. Just create create an empty
33 | + // destination file and return.
34 | + if (src_s.sb.st_size == 0) {
35 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
36 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
37 | + if (stream) {
38 | + php_stream_close(stream);
39 | + return SUCCESS;
40 | + }
41 | + return FAILURE;
42 | + }
43 | break;
44 | default: /* failed to stat file, does not exist? */
45 | return ret;
46 | }
47 | if (S_ISDIR(src_s.sb.st_mode)) {
48 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
49 | return FAILURE;
50 | }
51 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
52 | --- a/php-src/main/streams/cast.c
53 | +++ b/php-src/main/streams/cast.c
54 | @@ -113,10 +113,10 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
55 | return 0;
56 | }
57 | # else
58 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
59 | +static int stream_cookie_seeker(void *cookie, long long *position, int whence)
60 | {
61 |
62 | - return php_stream_seek((php_stream *)cookie, position, whence);
63 | + return php_stream_seek((php_stream *)cookie, *position, whence);
64 | }
65 | # endif
66 |
67 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php7.2.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
2 | --- a/php-src/ext/pdo_sqlite/sqlite_statement.c
3 | +++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
4 | @@ -299,7 +299,7 @@ static int pdo_sqlite_stmt_describe(pdo_stmt_t *stmt, int colno)
5 | return 1;
6 | }
7 |
8 | -static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees)
9 | +static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees)
10 | {
11 | pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
12 | if (!S->stmt) {
13 |
14 |
15 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
16 | --- a/php-src/ext/standard/file.c
17 | +++ b/php-src/ext/standard/file.c
18 | @@ -1691,18 +1691,32 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
19 | php_stream *srcstream = NULL, *deststream = NULL;
20 | int ret = FAILURE;
21 | php_stream_statbuf src_s, dest_s;
22 |
23 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
24 | case -1:
25 | /* non-statable stream */
26 | goto safe_to_copy;
27 | break;
28 | case 0:
29 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
30 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
31 | + // runtime.
32 | + // Solution: Avoid copying empty files. Just create create an empty
33 | + // destination file and return.
34 | + if (src_s.sb.st_size == 0) {
35 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
36 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
37 | + if (stream) {
38 | + php_stream_close(stream);
39 | + return SUCCESS;
40 | + }
41 | + return FAILURE;
42 | + }
43 | break;
44 | default: /* failed to stat file, does not exist? */
45 | return ret;
46 | }
47 | if (S_ISDIR(src_s.sb.st_mode)) {
48 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
49 | return FAILURE;
50 | }
51 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
52 | --- a/php-src/main/streams/cast.c
53 | +++ b/php-src/main/streams/cast.c
54 | @@ -113,10 +113,10 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
55 | return 0;
56 | }
57 | # else
58 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
59 | +static int stream_cookie_seeker(void *cookie, long long *position, int whence)
60 | {
61 |
62 | - return php_stream_seek((php_stream *)cookie, position, whence);
63 | + return php_stream_seek((php_stream *)cookie, *position, whence);
64 | }
65 | # endif
66 |
67 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php7.3.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
2 | --- a/php-src/ext/pdo_sqlite/sqlite_statement.c
3 | +++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
4 | @@ -299,7 +299,7 @@ static int pdo_sqlite_stmt_describe(pdo_stmt_t *stmt, int colno)
5 | return 1;
6 | }
7 |
8 | -static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, zend_ulong *len, int *caller_frees)
9 | +static int pdo_sqlite_stmt_get_col(pdo_stmt_t *stmt, int colno, char **ptr, size_t *len, int *caller_frees)
10 | {
11 | pdo_sqlite_stmt *S = (pdo_sqlite_stmt*)stmt->driver_data;
12 | if (!S->stmt) {
13 |
14 |
15 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
16 | --- a/php-src/ext/standard/file.c
17 | +++ b/php-src/ext/standard/file.c
18 | @@ -1691,18 +1691,32 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
19 | php_stream *srcstream = NULL, *deststream = NULL;
20 | int ret = FAILURE;
21 | php_stream_statbuf src_s, dest_s;
22 |
23 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
24 | case -1:
25 | /* non-statable stream */
26 | goto safe_to_copy;
27 | break;
28 | case 0:
29 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
30 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
31 | + // runtime.
32 | + // Solution: Avoid copying empty files. Just create create an empty
33 | + // destination file and return.
34 | + if (src_s.sb.st_size == 0) {
35 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
36 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
37 | + if (stream) {
38 | + php_stream_close(stream);
39 | + return SUCCESS;
40 | + }
41 | + return FAILURE;
42 | + }
43 | break;
44 | default: /* failed to stat file, does not exist? */
45 | return ret;
46 | }
47 | if (S_ISDIR(src_s.sb.st_mode)) {
48 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
49 | return FAILURE;
50 | }
51 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
52 | --- a/php-src/main/streams/cast.c
53 | +++ b/php-src/main/streams/cast.c
54 | @@ -113,10 +113,10 @@ static int stream_cookie_seeker(void *cookie, __off64_t *position, int whence)
55 | return 0;
56 | }
57 | # else
58 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
59 | +static int stream_cookie_seeker(void *cookie, long long *position, int whence)
60 | {
61 |
62 | - return php_stream_seek((php_stream *)cookie, position, whence);
63 | + return php_stream_seek((php_stream *)cookie, *position, whence);
64 | }
65 | # endif
66 |
67 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php7.4.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
2 | --- a/php-src/ext/standard/file.c
3 | +++ b/php-src/ext/standard/file.c
4 | @@ -1691,20 +1691,34 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
5 | php_stream *srcstream = NULL, *deststream = NULL;
6 | int ret = FAILURE;
7 | php_stream_statbuf src_s, dest_s;
8 |
9 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
10 | case -1:
11 | /* non-statable stream */
12 | goto safe_to_copy;
13 | break;
14 | case 0:
15 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
16 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
17 | + // runtime.
18 | + // Solution: Avoid copying empty files. Just create create an empty
19 | + // destination file and return.
20 | + if (src_s.sb.st_size == 0) {
21 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
22 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
23 | + if (stream) {
24 | + php_stream_close(stream);
25 | + return SUCCESS;
26 | + }
27 | + return FAILURE;
28 | + }
29 | break;
30 | default: /* failed to stat file, does not exist? */
31 | return ret;
32 | }
33 | if (S_ISDIR(src_s.sb.st_mode)) {
34 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
35 | return FAILURE;
36 | }
37 |
38 | switch (php_stream_stat_path_ex(dest, PHP_STREAM_URL_STAT_QUIET | PHP_STREAM_URL_STAT_NOCACHE, &dest_s, ctx)) {
39 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
40 | index 2109239eff..c42e7c8f34 100644
41 | --- a/php-src/main/streams/cast.c
42 | +++ b/php-src/main/streams/cast.c
43 | @@ -102,8 +102,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz
44 | return php_stream_write(((php_stream *)cookie), (char *)buffer, size);
45 | }
46 |
47 | -# ifdef COOKIE_SEEKER_USES_OFF64_T
48 | -static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
49 | +static int stream_cookie_seeker(void *cookie, off_t *position, int whence)
50 | {
51 |
52 | *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence);
53 | @@ -113,13 +112,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
54 | }
55 | return 0;
56 | }
57 | -# else
58 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
59 | -{
60 | -
61 | - return php_stream_seek((php_stream *)cookie, position, whence);
62 | -}
63 | -# endif
64 |
65 | static int stream_cookie_closer(void *cookie)
66 | {
67 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php8.0.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
2 | --- a/php-src/ext/standard/file.c
3 | +++ b/php-src/ext/standard/file.c
4 | @@ -1691,18 +1691,32 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
5 | php_stream *srcstream = NULL, *deststream = NULL;
6 | int ret = FAILURE;
7 | php_stream_statbuf src_s, dest_s;
8 |
9 | switch (php_stream_stat_path_ex(src, 0, &src_s, ctx)) {
10 | case -1:
11 | /* non-statable stream */
12 | goto safe_to_copy;
13 | break;
14 | case 0:
15 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
16 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
17 | + // runtime.
18 | + // Solution: Avoid copying empty files. Just create create an empty
19 | + // destination file and return.
20 | + if (src_s.sb.st_size == 0) {
21 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
22 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
23 | + if (stream) {
24 | + php_stream_close(stream);
25 | + return SUCCESS;
26 | + }
27 | + return FAILURE;
28 | + }
29 | break;
30 | default: /* failed to stat file, does not exist? */
31 | return ret;
32 | }
33 | if (S_ISDIR(src_s.sb.st_mode)) {
34 | php_error_docref(NULL, E_WARNING, "The first argument to copy() function cannot be a directory");
35 | return FAILURE;
36 | }
37 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
38 | index 0978ca4d7f..4321d5ca54 100644
39 | --- a/php-src/main/streams/cast.c
40 | +++ b/php-src/main/streams/cast.c
41 | @@ -100,8 +100,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz
42 | return php_stream_write(((php_stream *)cookie), (char *)buffer, size);
43 | }
44 |
45 | -# ifdef COOKIE_SEEKER_USES_OFF64_T
46 | -static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
47 | +static int stream_cookie_seeker(void *cookie, off_t *position, int whence)
48 | {
49 |
50 | *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence);
51 | @@ -111,13 +110,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
52 | }
53 | return 0;
54 | }
55 | -# else
56 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
57 | -{
58 | -
59 | - return php_stream_seek((php_stream *)cookie, position, whence);
60 | -}
61 | -# endif
62 |
63 | static int stream_cookie_closer(void *cookie)
64 | {
65 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php8.1.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/sapi/embed/php_embed.c b/php-src/sapi/embed/php_embed.c
2 | --- a/php-src/sapi/embed/php_embed.c
3 | +++ b/php-src/sapi/embed/php_embed.c
4 | @@ -246,8 +246,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)
5 | return FAILURE;
6 | }
7 |
8 | - SG(headers_sent) = 1;
9 | - SG(request_info).no_headers = 1;
10 | + SG(headers_sent) = 0;
11 | + SG(request_info).no_headers = 0;
12 | php_register_variable("PHP_SELF", "-", NULL);
13 |
14 | return SUCCESS;
15 |
16 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
17 | --- a/php-src/ext/standard/file.c
18 | +++ b/php-src/ext/standard/file.c
19 | @@ -1677,6 +1677,20 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
20 | goto safe_to_copy;
21 | break;
22 | case 0:
23 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
24 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
25 | + // runtime.
26 | + // Solution: Avoid copying empty files. Just create create an empty
27 | + // destination file and return.
28 | + if (src_s.sb.st_size == 0) {
29 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
30 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
31 | + if (stream) {
32 | + php_stream_close(stream);
33 | + return SUCCESS;
34 | + }
35 | + return FAILURE;
36 | + }
37 | break;
38 | default: /* failed to stat file, does not exist? */
39 | return ret;
40 | diff --git a/php-src/main/streams/cast.c b/php-src/main/streams/cast.c
41 | index db0f039eae..8bfc968cec 100644
42 | --- a/php-src/main/streams/cast.c
43 | +++ b/php-src/main/streams/cast.c
44 | @@ -100,8 +100,7 @@ static ssize_t stream_cookie_writer(void *cookie, const char *buffer, size_t siz
45 | return php_stream_write(((php_stream *)cookie), (char *)buffer, size);
46 | }
47 |
48 | -# ifdef COOKIE_SEEKER_USES_OFF64_T
49 | -static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
50 | +static int stream_cookie_seeker(void *cookie, off_t *position, int whence)
51 | {
52 |
53 | *position = php_stream_seek((php_stream *)cookie, (zend_off_t)*position, whence);
54 | @@ -111,13 +110,6 @@ static int stream_cookie_seeker(void *cookie, off64_t *position, int whence)
55 | }
56 | return 0;
57 | }
58 | -# else
59 | -static int stream_cookie_seeker(void *cookie, zend_off_t position, int whence)
60 | -{
61 | -
62 | - return php_stream_seek((php_stream *)cookie, position, whence);
63 | -}
64 | -# endif
65 |
66 | static int stream_cookie_closer(void *cookie)
67 | {
68 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php8.2.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo/config.m4 b/php-src/ext/pdo/config.m4
2 | --- a/php-src/ext/pdo/config.m4
3 | +++ b/php-src/ext/pdo/config.m4
4 | @@ -4,15 +4,14 @@ PHP_ARG_ENABLE([pdo],
5 | [Disable PHP Data Objects support])],
6 | [yes])
7 |
8 | -if test "$PHP_PDO" != "no"; then
9 | -
10 | - dnl Make sure $PHP_PDO is 'yes' when it's not 'no' :)
11 | - PHP_PDO=yes
12 | +dnl Make sure $PHP_PDO is 'yes' when it's not 'no' :)
13 | +PHP_PDO=yes
14 |
15 | +if test "$PHP_PDO" != "no"; then
16 | + dnl so we always include the known-good working hack.
17 | PHP_NEW_EXTENSION(pdo, pdo.c pdo_dbh.c pdo_stmt.c pdo_sql_parser.c pdo_sqlstate.c, $ext_shared)
18 | PHP_ADD_EXTENSION_DEP(pdo, spl, true)
19 | PHP_INSTALL_HEADERS(ext/pdo, [php_pdo.h php_pdo_driver.h php_pdo_error.h])
20 |
21 | - dnl so we always include the known-good working hack.
22 | PHP_ADD_MAKEFILE_FRAGMENT
23 | fi
24 | diff --git a/php-src/ext/pdo_sqlite/config.m4 b/php-src/ext/pdo_sqlite/config.m4
25 | --- a/php-src/ext/pdo_sqlite/config.m4
26 | +++ b/php-src/ext/pdo_sqlite/config.m4
27 | @@ -10,25 +10,7 @@ if test "$PHP_PDO_SQLITE" != "no"; then
28 | AC_MSG_ERROR([PDO is not enabled! Add --enable-pdo to your configure line.])
29 | fi
30 |
31 | - PHP_CHECK_PDO_INCLUDES
32 | -
33 | - PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.7])
34 | -
35 | - PHP_EVAL_INCLINE($SQLITE_CFLAGS)
36 | - PHP_EVAL_LIBLINE($SQLITE_LIBS, PDO_SQLITE_SHARED_LIBADD)
37 | - AC_DEFINE(HAVE_PDO_SQLITELIB, 1, [Define to 1 if you have the pdo_sqlite extension enabled.])
38 | -
39 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_close_v2, [
40 | - AC_DEFINE(HAVE_SQLITE3_CLOSE_V2, 1, [have sqlite3_close_v2])
41 | - ], [], [$PDO_SQLITE_SHARED_LIBADD])
42 | -
43 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_column_table_name, [
44 | - AC_DEFINE(HAVE_SQLITE3_COLUMN_TABLE_NAME, 1, [have sqlite3_column_table_name])
45 | - ], [], [$PDO_SQLITE_SHARED_LIBADD])
46 | -
47 | - PHP_SUBST(PDO_SQLITE_SHARED_LIBADD)
48 | PHP_NEW_EXTENSION(pdo_sqlite, pdo_sqlite.c sqlite_driver.c sqlite_statement.c,
49 | - $ext_shared,,-I$pdo_cv_inc_path)
50 | -
51 | + $ext_shared,,-I$pdo_cv_inc_path)
52 | PHP_ADD_EXTENSION_DEP(pdo_sqlite, pdo)
53 | fi
54 | diff --git a/php-src/ext/pdo_sqlite/pdo_sqlite.c b/php-src/ext/pdo_sqlite/pdo_sqlite.c
55 | --- a/php-src/ext/pdo_sqlite/pdo_sqlite.c
56 | +++ b/php-src/ext/pdo_sqlite/pdo_sqlite.c
57 | @@ -23,8 +23,8 @@
58 | #include "php.h"
59 | #include "php_ini.h"
60 | #include "ext/standard/info.h"
61 | -#include "pdo/php_pdo.h"
62 | -#include "pdo/php_pdo_driver.h"
63 | +#include "../pdo/php_pdo.h"
64 | +#include "../pdo/php_pdo_driver.h"
65 | #include "php_pdo_sqlite.h"
66 | #include "php_pdo_sqlite_int.h"
67 | #include "zend_exceptions.h"
68 | diff --git a/php-src/ext/pdo_sqlite/sqlite_driver.c b/php-src/ext/pdo_sqlite/sqlite_driver.c
69 | --- a/php-src/ext/pdo_sqlite/sqlite_driver.c
70 | +++ b/php-src/ext/pdo_sqlite/sqlite_driver.c
71 | @@ -23,8 +23,8 @@
72 | #include "php.h"
73 | #include "php_ini.h"
74 | #include "ext/standard/info.h"
75 | -#include "pdo/php_pdo.h"
76 | -#include "pdo/php_pdo_driver.h"
77 | +#include "../pdo/php_pdo.h"
78 | +#include "../pdo/php_pdo_driver.h"
79 | #include "php_pdo_sqlite.h"
80 | #include "php_pdo_sqlite_int.h"
81 | #include "zend_exceptions.h"
82 | diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
83 | --- a/php-src/ext/pdo_sqlite/sqlite_statement.c
84 | +++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
85 | @@ -23,8 +23,8 @@
86 | #include "php.h"
87 | #include "php_ini.h"
88 | #include "ext/standard/info.h"
89 | -#include "pdo/php_pdo.h"
90 | -#include "pdo/php_pdo_driver.h"
91 | +#include "../pdo/php_pdo.h"
92 | +#include "../pdo/php_pdo_driver.h"
93 | #include "php_pdo_sqlite.h"
94 | #include "php_pdo_sqlite_int.h"
95 |
96 | diff --git a/php-src/ext/sqlite3/config0.m4 b/php-src/ext/sqlite3/config0.m4
97 | --- a/php-src/ext/sqlite3/config0.m4
98 | +++ b/php-src/ext/sqlite3/config0.m4
99 | @@ -5,26 +5,6 @@ PHP_ARG_WITH([sqlite3],
100 | [yes])
101 |
102 | if test $PHP_SQLITE3 != "no"; then
103 | - PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.7])
104 | -
105 | - PHP_EVAL_INCLINE($SQLITE_CFLAGS)
106 | - PHP_EVAL_LIBLINE($SQLITE_LIBS, SQLITE3_SHARED_LIBADD)
107 | - AC_DEFINE(HAVE_SQLITE3, 1, [Define to 1 if you have the sqlite3 extension enabled.])
108 | -
109 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_errstr, [
110 | - AC_DEFINE(HAVE_SQLITE3_ERRSTR, 1, [have sqlite3_errstr function])
111 | - ], [], [$SQLITE3_SHARED_LIBADD])
112 | -
113 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_expanded_sql, [
114 | - AC_DEFINE(HAVE_SQLITE3_EXPANDED_SQL, 1, [have sqlite3_expanded_sql function])
115 | - ], [], [$SQLITE3_SHARED_LIBADD])
116 | -
117 | - PHP_CHECK_LIBRARY(sqlite3,sqlite3_load_extension,
118 | - [],
119 | - [AC_DEFINE(SQLITE_OMIT_LOAD_EXTENSION, 1, [have sqlite3 with extension support])],
120 | - [$SQLITE3_SHARED_LIBADD]
121 | - )
122 | -
123 | PHP_NEW_EXTENSION(sqlite3, sqlite3.c, $ext_shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
124 | PHP_SUBST(SQLITE3_SHARED_LIBADD)
125 | fi
126 | diff --git a/php-src/sapi/embed/php_embed.c b/php-src/sapi/embed/php_embed.c
127 | --- a/php-src/sapi/embed/php_embed.c
128 | +++ b/php-src/sapi/embed/php_embed.c
129 | @@ -246,8 +246,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)
130 | return FAILURE;
131 | }
132 |
133 | - SG(headers_sent) = 1;
134 | - SG(request_info).no_headers = 1;
135 | + SG(headers_sent) = 0;
136 | + SG(request_info).no_headers = 0;
137 | php_register_variable("PHP_SELF", "-", NULL);
138 |
139 | return SUCCESS;
140 |
141 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
142 | --- a/php-src/ext/standard/file.c
143 | +++ b/php-src/ext/standard/file.c
144 | @@ -1547,6 +1547,20 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
145 | goto safe_to_copy;
146 | break;
147 | case 0:
148 | + // Fix for https://github.com/WordPress/wordpress-playground/issues/54:
149 | + // Problem: Calling copy() on an empty source file crashes the JavaScript
150 | + // runtime.
151 | + // Solution: Avoid copying empty files. Just create create an empty
152 | + // destination file and return.
153 | + if (src_s.sb.st_size == 0) {
154 | + zend_string *opened_path = zend_string_init("", strlen(""), 0);
155 | + php_stream *stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
156 | + if (stream) {
157 | + php_stream_close(stream);
158 | + return SUCCESS;
159 | + }
160 | + return FAILURE;
161 | + }
162 | break;
163 | default: /* failed to stat file, does not exist? */
164 | return ret;
165 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php8.3.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo/config.m4 b/php-src/ext/pdo/config.m4
2 | index 9b9a3e36df..f2ea3d6a6c 100644
3 | --- a/php-src/ext/pdo/config.m4
4 | +++ b/php-src/ext/pdo/config.m4
5 | @@ -5,14 +5,10 @@ PHP_ARG_ENABLE([pdo],
6 | [yes])
7 |
8 | if test "$PHP_PDO" != "no"; then
9 | -
10 | - dnl Make sure $PHP_PDO is 'yes' when it's not 'no' :)
11 | - PHP_PDO=yes
12 | -
13 | + dnl so we always include the known-good working hack.
14 | PHP_NEW_EXTENSION(pdo, pdo.c pdo_dbh.c pdo_stmt.c pdo_sql_parser.c pdo_sqlstate.c, $ext_shared)
15 | PHP_ADD_EXTENSION_DEP(pdo, spl, true)
16 | PHP_INSTALL_HEADERS(ext/pdo, [php_pdo.h php_pdo_driver.h php_pdo_error.h])
17 |
18 | - dnl so we always include the known-good working hack.
19 | PHP_ADD_MAKEFILE_FRAGMENT
20 | fi
21 | diff --git a/php-src/ext/pdo_sqlite/config.m4 b/php-src/ext/pdo_sqlite/config.m4
22 | index 64311eaa64..1748822016 100644
23 | --- a/php-src/ext/pdo_sqlite/config.m4
24 | +++ b/php-src/ext/pdo_sqlite/config.m4
25 | @@ -10,25 +10,6 @@ if test "$PHP_PDO_SQLITE" != "no"; then
26 | AC_MSG_ERROR([PDO is not enabled! Add --enable-pdo to your configure line.])
27 | fi
28 |
29 | - PHP_CHECK_PDO_INCLUDES
30 | -
31 | - PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.7])
32 | -
33 | - PHP_EVAL_INCLINE($SQLITE_CFLAGS)
34 | - PHP_EVAL_LIBLINE($SQLITE_LIBS, PDO_SQLITE_SHARED_LIBADD)
35 | - AC_DEFINE(HAVE_PDO_SQLITELIB, 1, [Define to 1 if you have the pdo_sqlite extension enabled.])
36 | -
37 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_close_v2, [
38 | - AC_DEFINE(HAVE_SQLITE3_CLOSE_V2, 1, [have sqlite3_close_v2])
39 | - ], [], [$PDO_SQLITE_SHARED_LIBADD])
40 | -
41 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_column_table_name, [
42 | - AC_DEFINE(HAVE_SQLITE3_COLUMN_TABLE_NAME, 1, [have sqlite3_column_table_name])
43 | - ], [], [$PDO_SQLITE_SHARED_LIBADD])
44 | -
45 | - PHP_SUBST(PDO_SQLITE_SHARED_LIBADD)
46 | - PHP_NEW_EXTENSION(pdo_sqlite, pdo_sqlite.c sqlite_driver.c sqlite_statement.c,
47 | - $ext_shared,,-I$pdo_cv_inc_path)
48 | -
49 | + $ext_shared,,-I$pdo_cv_inc_path)
50 | PHP_ADD_EXTENSION_DEP(pdo_sqlite, pdo)
51 | fi
52 | diff --git a/php-src/ext/pdo_sqlite/pdo_sqlite.c b/php-src/ext/pdo_sqlite/pdo_sqlite.c
53 | index 6da7708576..0d53a33182 100644
54 | --- a/php-src/ext/pdo_sqlite/pdo_sqlite.c
55 | +++ b/php-src/ext/pdo_sqlite/pdo_sqlite.c
56 | @@ -21,8 +21,8 @@
57 | #include "php.h"
58 | #include "php_ini.h"
59 | #include "ext/standard/info.h"
60 | -#include "pdo/php_pdo.h"
61 | -#include "pdo/php_pdo_driver.h"
62 | +#include "../pdo/php_pdo.h"
63 | +#include "../pdo/php_pdo_driver.h"
64 | #include "php_pdo_sqlite.h"
65 | #include "php_pdo_sqlite_int.h"
66 | #include "zend_exceptions.h"
67 | diff --git a/php-src/ext/pdo_sqlite/sqlite_statement.c b/php-src/ext/pdo_sqlite/sqlite_statement.c
68 | index c6b907f6fc..c0804c8c2b 100644
69 | --- a/php-src/ext/pdo_sqlite/sqlite_statement.c
70 | +++ b/php-src/ext/pdo_sqlite/sqlite_statement.c
71 | @@ -21,8 +21,8 @@
72 | #include "php.h"
73 | #include "php_ini.h"
74 | #include "ext/standard/info.h"
75 | -#include "pdo/php_pdo.h"
76 | -#include "pdo/php_pdo_driver.h"
77 | +#include "../pdo/php_pdo.h"
78 | +#include "../pdo/php_pdo_driver.h"
79 | #include "php_pdo_sqlite.h"
80 | #include "php_pdo_sqlite_int.h"
81 |
82 | diff --git a/php-src/ext/sqlite3/config0.m4 b/php-src/ext/sqlite3/config0.m4
83 | index 2373d13d30..ee79b8430d 100644
84 | --- a/php-src/ext/sqlite3/config0.m4
85 | +++ b/php-src/ext/sqlite3/config0.m4
86 | @@ -5,25 +5,6 @@ PHP_ARG_WITH([sqlite3],
87 | [yes])
88 |
89 | if test $PHP_SQLITE3 != "no"; then
90 | - PKG_CHECK_MODULES([SQLITE], [sqlite3 >= 3.7.7])
91 | -
92 | - PHP_EVAL_INCLINE($SQLITE_CFLAGS)
93 | - PHP_EVAL_LIBLINE($SQLITE_LIBS, SQLITE3_SHARED_LIBADD)
94 | - AC_DEFINE(HAVE_SQLITE3, 1, [Define to 1 if you have the sqlite3 extension enabled.])
95 | -
96 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_errstr, [
97 | - AC_DEFINE(HAVE_SQLITE3_ERRSTR, 1, [have sqlite3_errstr function])
98 | - ], [], [$SQLITE3_SHARED_LIBADD])
99 | -
100 | - PHP_CHECK_LIBRARY(sqlite3, sqlite3_expanded_sql, [
101 | - AC_DEFINE(HAVE_SQLITE3_EXPANDED_SQL, 1, [have sqlite3_expanded_sql function])
102 | - ], [], [$SQLITE3_SHARED_LIBADD])
103 | -
104 | - PHP_CHECK_LIBRARY(sqlite3,sqlite3_load_extension,
105 | - [],
106 | - [AC_DEFINE(SQLITE_OMIT_LOAD_EXTENSION, 1, [have sqlite3 with extension support])],
107 | - [$SQLITE3_SHARED_LIBADD]
108 | - )
109 |
110 | PHP_NEW_EXTENSION(sqlite3, sqlite3.c, $ext_shared,,-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
111 | PHP_SUBST(SQLITE3_SHARED_LIBADD)
112 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
113 | index 5f6452e23d..ac223f884c 100644
114 | --- a/php-src/ext/standard/file.c
115 | +++ b/php-src/ext/standard/file.c
116 | @@ -1547,6 +1547,15 @@ PHPAPI int php_copy_file_ctx(const char *src, const char *dest, int src_flg, php
117 | goto safe_to_copy;
118 | break;
119 | case 0:
120 | + if (src_s.sb.st_size == 0) {
121 | + zend_string * opened_path = zend_string_init("", strlen(""), 0);
122 | + php_stream * stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
123 | + if (stream) {
124 | + php_stream_close(stream);
125 | + return SUCCESS;
126 | + }
127 | + return FAILURE;
128 | + }
129 | break;
130 | default: /* failed to stat file, does not exist? */
131 | return ret;
132 | diff --git a/php-src/sapi/embed/php_embed.c b/php-src/sapi/embed/php_embed.c
133 | index 4626451f9f..577c2ab001 100644
134 | --- a/php-src/sapi/embed/php_embed.c
135 | +++ b/php-src/sapi/embed/php_embed.c
136 | @@ -242,8 +242,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)
137 | return FAILURE;
138 | }
139 |
140 | - SG(headers_sent) = 1;
141 | - SG(request_info).no_headers = 1;
142 | + SG(headers_sent) = 0;
143 | + SG(request_info).no_headers = 0;
144 | php_register_variable("PHP_SELF", "-", NULL);
145 |
146 | return SUCCESS;
147 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/php8.4.patch:
--------------------------------------------------------------------------------
1 | diff --git a/php-src/ext/pdo/config.m4 b/php-src/ext/pdo/config.m4
2 | index dccf898785..41c4295b0a 100644
3 | --- a/php-src/ext/pdo/config.m4
4 | +++ b/php-src/ext/pdo/config.m4
5 | @@ -4,10 +4,10 @@ PHP_ARG_ENABLE([pdo],
6 | [Disable PHP Data Objects support])],
7 | [yes])
8 |
9 | -if test "$PHP_PDO" != "no"; then
10 | - dnl Make sure $PHP_PDO is 'yes' when it's not 'no' :)
11 | - PHP_PDO=yes
12 | +dnl so we always include the known-good working hack.
13 | +PHP_PDO=yes
14 |
15 | +if test "$PHP_PDO" != "no"; then
16 | PHP_NEW_EXTENSION([pdo],
17 | [pdo.c pdo_dbh.c pdo_stmt.c pdo_sql_parser.c pdo_sqlstate.c],
18 | [$ext_shared])
19 | diff --git a/php-src/ext/pdo_sqlite/config.m4 b/php-src/ext/pdo_sqlite/config.m4
20 | index eaaee6182b..40cca323cf 100644
21 | --- a/php-src/ext/pdo_sqlite/config.m4
22 | +++ b/php-src/ext/pdo_sqlite/config.m4
23 | @@ -5,38 +5,6 @@ PHP_ARG_WITH([pdo-sqlite],
24 | [$PHP_PDO])
25 |
26 | if test "$PHP_PDO_SQLITE" != "no"; then
27 | - PHP_CHECK_PDO_INCLUDES
28 | -
29 | - PHP_SETUP_SQLITE([PDO_SQLITE_SHARED_LIBADD])
30 | -
31 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_close_v2],
32 | - [AC_DEFINE([HAVE_SQLITE3_CLOSE_V2], [1],
33 | - [Define to 1 if SQLite library has the 'sqlite3_close_v2' function.])],
34 | - [],
35 | - [$PDO_SQLITE_SHARED_LIBADD])
36 | -
37 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_column_table_name],
38 | - [AC_DEFINE([HAVE_SQLITE3_COLUMN_TABLE_NAME], [1],
39 | - [Define to 1 if SQLite library was compiled with the
40 | - SQLITE_ENABLE_COLUMN_METADATA and has the 'sqlite3_column_table_name'
41 | - function.])],
42 | - [],
43 | - [$PDO_SQLITE_SHARED_LIBADD])
44 | -
45 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_load_extension],
46 | - [],
47 | - [AC_DEFINE([PDO_SQLITE_OMIT_LOAD_EXTENSION], [1],
48 | - [Define to 1 if SQLite library was compiled with the
49 | - SQLITE_OMIT_LOAD_EXTENSION and does not have the extension support with
50 | - the 'sqlite3_load_extension' function. For usage in the pdo_sqlite. See
51 | - https://www.sqlite.org/compile.html.])],
52 | - [$PDO_SQLITE_SHARED_LIBADD])
53 | -
54 | - PHP_SUBST([PDO_SQLITE_SHARED_LIBADD])
55 | - PHP_NEW_EXTENSION([pdo_sqlite],
56 | - [pdo_sqlite.c sqlite_driver.c sqlite_statement.c sqlite_sql_parser.c],
57 | - [$ext_shared])
58 | -
59 | PHP_ADD_EXTENSION_DEP(pdo_sqlite, pdo)
60 | PHP_ADD_MAKEFILE_FRAGMENT
61 | fi
62 | diff --git a/php-src/ext/sqlite3/config0.m4 b/php-src/ext/sqlite3/config0.m4
63 | index 453108f692..460ff27b11 100644
64 | --- a/php-src/ext/sqlite3/config0.m4
65 | +++ b/php-src/ext/sqlite3/config0.m4
66 | @@ -5,31 +5,6 @@ PHP_ARG_WITH([sqlite3],
67 | [yes])
68 |
69 | if test $PHP_SQLITE3 != "no"; then
70 | - PHP_SETUP_SQLITE([SQLITE3_SHARED_LIBADD])
71 | - AC_DEFINE([HAVE_SQLITE3], [1],
72 | - [Define to 1 if the PHP extension 'sqlite3' is available.])
73 | -
74 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_errstr],
75 | - [AC_DEFINE([HAVE_SQLITE3_ERRSTR], [1],
76 | - [Define to 1 if SQLite library has the 'sqlite3_errstr' function.])],
77 | - [],
78 | - [$SQLITE3_SHARED_LIBADD])
79 | -
80 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_expanded_sql],
81 | - [AC_DEFINE([HAVE_SQLITE3_EXPANDED_SQL], [1],
82 | - [Define to 1 if SQLite library has the 'sqlite3_expanded_sql' function.])],
83 | - [],
84 | - [$SQLITE3_SHARED_LIBADD])
85 | -
86 | - PHP_CHECK_LIBRARY([sqlite3], [sqlite3_load_extension],
87 | - [],
88 | - [AC_DEFINE([SQLITE_OMIT_LOAD_EXTENSION], [1],
89 | - [Define to 1 if SQLite library was compiled with the
90 | - SQLITE_OMIT_LOAD_EXTENSION and does not have the extension support with
91 | - the 'sqlite3_load_extension' function. For usage in the sqlite3 PHP
92 | - extension. See https://www.sqlite.org/compile.html.])],
93 | - [$SQLITE3_SHARED_LIBADD])
94 | -
95 | PHP_NEW_EXTENSION([sqlite3],
96 | [sqlite3.c],
97 | [$ext_shared],,
98 | diff --git a/php-src/ext/standard/file.c b/php-src/ext/standard/file.c
99 | index 01f49640e4..62cd9918e7 100644
100 | --- a/php-src/ext/standard/file.c
101 | +++ b/php-src/ext/standard/file.c
102 | @@ -1507,6 +1507,15 @@ PHPAPI zend_result php_copy_file_ctx(const char *src, const char *dest, int src_
103 | goto safe_to_copy;
104 | break;
105 | case 0:
106 | + if (src_s.sb.st_size == 0) {
107 | + zend_string * opened_path = zend_string_init("", strlen(""), 0);
108 | + php_stream * stream = php_stream_open_wrapper(dest, "w", REPORT_ERRORS, &opened_path);
109 | + if (stream) {
110 | + php_stream_close(stream);
111 | + return SUCCESS;
112 | + }
113 | + return FAILURE;
114 | + }
115 | break;
116 | default: /* failed to stat file, does not exist? */
117 | return ret;
118 | diff --git a/php-src/sapi/embed/php_embed.c b/php-src/sapi/embed/php_embed.c
119 | index c18480d07d..787687f326 100644
120 | --- a/php-src/sapi/embed/php_embed.c
121 | +++ b/php-src/sapi/embed/php_embed.c
122 | @@ -242,8 +242,8 @@ EMBED_SAPI_API int php_embed_init(int argc, char **argv)
123 | return FAILURE;
124 | }
125 |
126 | - SG(headers_sent) = 1;
127 | - SG(request_info).no_headers = 1;
128 | + SG(headers_sent) = 0;
129 | + SG(request_info).no_headers = 0;
130 | php_register_variable("PHP_SELF", "-", NULL);
131 |
132 | return SUCCESS;
133 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/replace.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # This script is used to replace strings in files and exit with a non-zero status if the string is not found.
4 | # use strict;
5 |
6 | perl -pi.bak -e "$1" "$2"
7 | if cmp --silent -- "$2" "$2.bak"; then
8 | echo "No matches found for $1 in file $2 - exiting with non-zero status"
9 | exit 1
10 | fi
11 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 2.4.4)
2 | set(CMAKE_ALLOW_LOOSE_LOOP_CONSTRUCTS ON)
3 |
4 | project(zlib C)
5 |
6 | if(NOT DEFINED BUILD_SHARED_LIBS)
7 | option(BUILD_SHARED_LIBS "Build a shared library form of zlib" ON)
8 | endif()
9 |
10 | include(CheckTypeSize)
11 | include(CheckFunctionExists)
12 | include(CheckIncludeFile)
13 | include(CheckCSourceCompiles)
14 | enable_testing()
15 |
16 | check_include_file(sys/types.h HAVE_SYS_TYPES_H)
17 | check_include_file(stdint.h HAVE_STDINT_H)
18 | check_include_file(stddef.h HAVE_STDDEF_H)
19 |
20 | #
21 | # Check to see if we have large file support
22 | #
23 | set(CMAKE_REQUIRED_DEFINITIONS -D_LARGEFILE64_SOURCE=1)
24 | # We add these other definitions here because CheckTypeSize.cmake
25 | # in CMake 2.4.x does not automatically do so and we want
26 | # compatibility with CMake 2.4.x.
27 | if(HAVE_SYS_TYPES_H)
28 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_SYS_TYPES_H)
29 | endif()
30 | if(HAVE_STDINT_H)
31 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDINT_H)
32 | endif()
33 | if(HAVE_STDDEF_H)
34 | list(APPEND CMAKE_REQUIRED_DEFINITIONS -DHAVE_STDDEF_H)
35 | endif()
36 | check_type_size(off64_t OFF64_T)
37 | if(HAVE_OFF64_T)
38 | add_definitions(-D_LARGEFILE64_SOURCE=1)
39 | endif()
40 | set(CMAKE_REQUIRED_DEFINITIONS) # clear variable
41 |
42 | #
43 | # Check for fseeko
44 | #
45 | check_function_exists(fseeko HAVE_FSEEKO)
46 | if(NOT HAVE_FSEEKO)
47 | add_definitions(-DNO_FSEEKO)
48 | endif()
49 |
50 | #
51 | # Check for unistd.h
52 | #
53 | check_include_file(unistd.h Z_HAVE_UNISTD_H)
54 |
55 | if(MSVC)
56 | set(CMAKE_DEBUG_POSTFIX "d")
57 | add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
58 | add_definitions(-D_CRT_NONSTDC_NO_DEPRECATE)
59 | endif()
60 |
61 | if(NOT CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR)
62 | # If we're doing an out of source build and the user has a zconf.h
63 | # in their source tree...
64 | if(EXISTS zconf.h)
65 | message(FATAL_ERROR
66 | "You must remove ${CMAKE_CURRENT_SOURCE_DIR}/zconf.h "
67 | "from the source tree. This file is included with zlib "
68 | "but CMake generates this file for you automatically "
69 | "in the build directory.")
70 | endif()
71 | endif()
72 |
73 | configure_file(zconf.h.cmakein
74 | ${CMAKE_CURRENT_BINARY_DIR}/zconf.h @ONLY)
75 | include_directories(${CMAKE_CURRENT_BINARY_DIR})
76 |
77 |
78 | #============================================================================
79 | # zlib
80 | #============================================================================
81 |
82 | set(ZLIB_PUBLIC_HDRS
83 | ${CMAKE_CURRENT_BINARY_DIR}/zconf.h
84 | zlib.h
85 | )
86 | set(ZLIB_PRIVATE_HDRS
87 | crc32.h
88 | deflate.h
89 | gzguts.h
90 | inffast.h
91 | inffixed.h
92 | inflate.h
93 | inftrees.h
94 | trees.h
95 | zutil.h
96 | )
97 | set(ZLIB_SRCS
98 | adler32.c
99 | compress.c
100 | crc32.c
101 | deflate.c
102 | gzclose.c
103 | gzlib.c
104 | gzread.c
105 | gzwrite.c
106 | inflate.c
107 | infback.c
108 | inftrees.c
109 | inffast.c
110 | trees.c
111 | uncompr.c
112 | zutil.c
113 | # win32/zlib1.rc XXX Emscripten remove the Windows resource file from build, not needed and not included in source tree.
114 | )
115 |
116 | # parse the full version number from zlib.h and include in ZLIB_FULL_VERSION
117 | file(READ zlib.h _zlib_h_contents)
118 | string(REGEX REPLACE ".*#define[ \t]+ZLIB_VERSION[ \t]+\"([0-9A-Za-z.]+)\".*"
119 | "\\1" ZLIB_FULL_VERSION ${_zlib_h_contents})
120 |
121 | if(MINGW)
122 | # This gets us DLL resource information when compiling on MinGW.
123 | add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
124 | COMMAND windres.exe
125 | -D GCC_WINDRES
126 | -I .
127 | -I ${CMAKE_CURRENT_BINARY_DIR}
128 | -o ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj
129 | -i ${CMAKE_CURRENT_SOURCE_DIR}/win32/zlib1.rc)
130 | set(ZLIB_SRCS ${ZLIB_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/zlib1rc.obj)
131 | endif(MINGW)
132 |
133 | add_library(zlib ${ZLIB_SRCS} ${ZLIB_PUBLIC_HDRS} ${ZLIB_PRIVATE_HDRS})
134 | set_target_properties(zlib PROPERTIES DEFINE_SYMBOL ZLIB_DLL)
135 |
136 | set_target_properties(zlib PROPERTIES SOVERSION 1)
137 |
138 | if(NOT CYGWIN)
139 | # This property causes shared libraries on Linux to have the full version
140 | # encoded into their final filename. We disable this on Cygwin because
141 | # it causes cygz-${ZLIB_FULL_VERSION}.dll to be created when cygz.dll
142 | # seems to be the default.
143 | #
144 | # This has no effect with MSVC, on that platform the version info for
145 | # the DLL comes from the resource file win32/zlib1.rc
146 | set_target_properties(zlib PROPERTIES VERSION ${ZLIB_FULL_VERSION})
147 | endif()
148 |
149 | if(UNIX)
150 | # On unix-like platforms the library is almost always called libz
151 | set_target_properties(zlib PROPERTIES OUTPUT_NAME z)
152 | elseif(BUILD_SHARED_LIBS AND WIN32)
153 | # Creates zlib1.dll when building shared library version
154 | set_target_properties(zlib PROPERTIES SUFFIX "1.dll")
155 | endif()
156 |
157 | if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL )
158 | install(TARGETS zlib
159 | RUNTIME DESTINATION bin
160 | ARCHIVE DESTINATION lib
161 | LIBRARY DESTINATION lib )
162 | endif()
163 | if(NOT SKIP_INSTALL_HEADERS AND NOT SKIP_INSTALL_ALL )
164 | install(FILES ${ZLIB_PUBLIC_HDRS} DESTINATION include)
165 | endif()
166 | if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL )
167 | install(FILES zlib.3 DESTINATION share/man/man3)
168 | endif()
169 |
170 | #============================================================================
171 | # Example binaries
172 | #============================================================================
173 |
174 | add_executable(example example.c)
175 | target_link_libraries(example zlib)
176 | add_test(example example)
177 |
178 | add_executable(minigzip minigzip.c)
179 | target_link_libraries(minigzip zlib)
180 |
181 | if(HAVE_OFF64_T)
182 | add_executable(example64 example.c)
183 | target_link_libraries(example64 zlib)
184 | set_target_properties(example64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
185 | add_test(example64 example64)
186 |
187 | add_executable(minigzip64 minigzip.c)
188 | target_link_libraries(minigzip64 zlib)
189 | set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
190 | endif()
191 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/Makefile.in:
--------------------------------------------------------------------------------
1 | # Makefile for zlib
2 | # Copyright (C) 1995-2010 Jean-loup Gailly.
3 | # For conditions of distribution and use, see copyright notice in zlib.h
4 |
5 | # To compile and test, type:
6 | # ./configure; make test
7 | # Normally configure builds both a static and a shared library.
8 | # If you want to build just a static library, use: ./configure --static
9 |
10 | # To use the asm code, type:
11 | # cp contrib/asm?86/match.S ./match.S
12 | # make LOC=-DASMV OBJA=match.o
13 |
14 | # To install /usr/local/lib/libz.* and /usr/local/include/zlib.h, type:
15 | # make install
16 | # To install in $HOME instead of /usr/local, use:
17 | # make install prefix=$HOME
18 |
19 | CC=cc
20 |
21 | CFLAGS=-O
22 | #CFLAGS=-O -DMAX_WBITS=14 -DMAX_MEM_LEVEL=7
23 | #CFLAGS=-g -DDEBUG
24 | #CFLAGS=-O3 -Wall -Wwrite-strings -Wpointer-arith -Wconversion \
25 | # -Wstrict-prototypes -Wmissing-prototypes
26 |
27 | SFLAGS=-O
28 | LDFLAGS=
29 | TEST_LDFLAGS=-L. libz.a
30 | LDSHARED=$(CC)
31 | CPP=$(CC) -E
32 |
33 | STATICLIB=libz.a
34 | SHAREDLIB=libz.so
35 | SHAREDLIBV=libz.so.1.2.5
36 | SHAREDLIBM=libz.so.1
37 | LIBS=$(STATICLIB) $(SHAREDLIBV)
38 |
39 | AR=ar rc
40 | RANLIB=ranlib
41 | LDCONFIG=ldconfig
42 | LDSHAREDLIBC=-lc
43 | TAR=tar
44 | SHELL=/bin/sh
45 | EXE=
46 |
47 | prefix = /usr/local
48 | exec_prefix = ${prefix}
49 | libdir = ${exec_prefix}/lib
50 | sharedlibdir = ${libdir}
51 | includedir = ${prefix}/include
52 | mandir = ${prefix}/share/man
53 | man3dir = ${mandir}/man3
54 | pkgconfigdir = ${libdir}/pkgconfig
55 |
56 | OBJC = adler32.o compress.o crc32.o deflate.o gzclose.o gzlib.o gzread.o \
57 | gzwrite.o infback.o inffast.o inflate.o inftrees.o trees.o uncompr.o zutil.o
58 |
59 | PIC_OBJC = adler32.lo compress.lo crc32.lo deflate.lo gzclose.lo gzlib.lo gzread.lo \
60 | gzwrite.lo infback.lo inffast.lo inflate.lo inftrees.lo trees.lo uncompr.lo zutil.lo
61 |
62 | # to use the asm code: make OBJA=match.o, PIC_OBJA=match.lo
63 | OBJA =
64 | PIC_OBJA =
65 |
66 | OBJS = $(OBJC) $(OBJA)
67 |
68 | PIC_OBJS = $(PIC_OBJC) $(PIC_OBJA)
69 |
70 | all: static shared
71 |
72 | static: example$(EXE) minigzip$(EXE)
73 |
74 | shared: examplesh$(EXE) minigzipsh$(EXE)
75 |
76 | all64: example64$(EXE) minigzip64$(EXE)
77 |
78 | check: test
79 |
80 | test: all teststatic testshared
81 |
82 | teststatic: static
83 | @if echo hello world | ./minigzip | ./minigzip -d && ./example; then \
84 | echo ' *** zlib test OK ***'; \
85 | else \
86 | echo ' *** zlib test FAILED ***'; false; \
87 | fi
88 | -@rm -f foo.gz
89 |
90 | testshared: shared
91 | @LD_LIBRARY_PATH=`pwd`:$(LD_LIBRARY_PATH) ; export LD_LIBRARY_PATH; \
92 | LD_LIBRARYN32_PATH=`pwd`:$(LD_LIBRARYN32_PATH) ; export LD_LIBRARYN32_PATH; \
93 | DYLD_LIBRARY_PATH=`pwd`:$(DYLD_LIBRARY_PATH) ; export DYLD_LIBRARY_PATH; \
94 | SHLIB_PATH=`pwd`:$(SHLIB_PATH) ; export SHLIB_PATH; \
95 | if echo hello world | ./minigzipsh | ./minigzipsh -d && ./examplesh; then \
96 | echo ' *** zlib shared test OK ***'; \
97 | else \
98 | echo ' *** zlib shared test FAILED ***'; false; \
99 | fi
100 | -@rm -f foo.gz
101 |
102 | test64: all64
103 | @if echo hello world | ./minigzip64 | ./minigzip64 -d && ./example64; then \
104 | echo ' *** zlib 64-bit test OK ***'; \
105 | else \
106 | echo ' *** zlib 64-bit test FAILED ***'; false; \
107 | fi
108 | -@rm -f foo.gz
109 |
110 | libz.a: $(OBJS)
111 | $(AR) $@ $(OBJS)
112 | -@ ($(RANLIB) $@ || true) >/dev/null 2>&1
113 |
114 | match.o: match.S
115 | $(CPP) match.S > _match.s
116 | $(CC) -c _match.s
117 | mv _match.o match.o
118 | rm -f _match.s
119 |
120 | match.lo: match.S
121 | $(CPP) match.S > _match.s
122 | $(CC) -c -fPIC _match.s
123 | mv _match.o match.lo
124 | rm -f _match.s
125 |
126 | example64.o: example.c zlib.h zconf.h
127 | $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ example.c
128 |
129 | minigzip64.o: minigzip.c zlib.h zconf.h
130 | $(CC) $(CFLAGS) -D_FILE_OFFSET_BITS=64 -c -o $@ minigzip.c
131 |
132 | .SUFFIXES: .lo
133 |
134 | .c.lo:
135 | -@mkdir objs 2>/dev/null || test -d objs
136 | $(CC) $(SFLAGS) -DPIC -c -o objs/$*.o $<
137 | -@mv objs/$*.o $@
138 |
139 | $(SHAREDLIBV): $(PIC_OBJS)
140 | $(LDSHARED) $(SFLAGS) -o $@ $(PIC_OBJS) $(LDSHAREDLIBC) $(LDFLAGS)
141 | rm -f $(SHAREDLIB) $(SHAREDLIBM)
142 | ln -s $@ $(SHAREDLIB)
143 | ln -s $@ $(SHAREDLIBM)
144 | -@rmdir objs
145 |
146 | example$(EXE): example.o $(STATICLIB)
147 | $(CC) $(CFLAGS) -o $@ example.o $(TEST_LDFLAGS)
148 |
149 | minigzip$(EXE): minigzip.o $(STATICLIB)
150 | $(CC) $(CFLAGS) -o $@ minigzip.o $(TEST_LDFLAGS)
151 |
152 | examplesh$(EXE): example.o $(SHAREDLIBV)
153 | $(CC) $(CFLAGS) -o $@ example.o -L. $(SHAREDLIBV)
154 |
155 | minigzipsh$(EXE): minigzip.o $(SHAREDLIBV)
156 | $(CC) $(CFLAGS) -o $@ minigzip.o -L. $(SHAREDLIBV)
157 |
158 | example64$(EXE): example64.o $(STATICLIB)
159 | $(CC) $(CFLAGS) -o $@ example64.o $(TEST_LDFLAGS)
160 |
161 | minigzip64$(EXE): minigzip64.o $(STATICLIB)
162 | $(CC) $(CFLAGS) -o $@ minigzip64.o $(TEST_LDFLAGS)
163 |
164 | install-libs: $(LIBS)
165 | -@if [ ! -d $(DESTDIR)$(exec_prefix) ]; then mkdir -p $(DESTDIR)$(exec_prefix); fi
166 | -@if [ ! -d $(DESTDIR)$(libdir) ]; then mkdir -p $(DESTDIR)$(libdir); fi
167 | -@if [ ! -d $(DESTDIR)$(sharedlibdir) ]; then mkdir -p $(DESTDIR)$(sharedlibdir); fi
168 | -@if [ ! -d $(DESTDIR)$(man3dir) ]; then mkdir -p $(DESTDIR)$(man3dir); fi
169 | -@if [ ! -d $(DESTDIR)$(pkgconfigdir) ]; then mkdir -p $(DESTDIR)$(pkgconfigdir); fi
170 | cp $(STATICLIB) $(DESTDIR)$(libdir)
171 | cd $(DESTDIR)$(libdir); chmod u=rw,go=r $(STATICLIB)
172 | -@(cd $(DESTDIR)$(libdir); $(RANLIB) libz.a || true) >/dev/null 2>&1
173 | -@cd $(DESTDIR)$(sharedlibdir); if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
174 | chmod 755 $(SHAREDLIBV); \
175 | rm -f $(SHAREDLIB) $(SHAREDLIBM); \
176 | ln -s $(SHAREDLIBV) $(SHAREDLIB); \
177 | ln -s $(SHAREDLIBV) $(SHAREDLIBM); \
178 | ($(LDCONFIG) || true) >/dev/null 2>&1; \
179 | fi
180 | cp zlib.3 $(DESTDIR)$(man3dir)
181 | chmod 644 $(DESTDIR)$(man3dir)/zlib.3
182 | cp zlib.pc $(DESTDIR)$(pkgconfigdir)
183 | chmod 644 $(DESTDIR)$(pkgconfigdir)/zlib.pc
184 | # The ranlib in install is needed on NeXTSTEP which checks file times
185 | # ldconfig is for Linux
186 |
187 | install: install-libs
188 | -@if [ ! -d $(DESTDIR)$(includedir) ]; then mkdir -p $(DESTDIR)$(includedir); fi
189 | cp zlib.h zconf.h $(DESTDIR)$(includedir)
190 | chmod 644 $(DESTDIR)$(includedir)/zlib.h $(DESTDIR)$(includedir)/zconf.h
191 |
192 | uninstall:
193 | cd $(DESTDIR)$(includedir); rm -f zlib.h zconf.h
194 | cd $(DESTDIR)$(libdir); rm -f libz.a; \
195 | if test "$(SHAREDLIBV)" -a -f $(SHAREDLIBV); then \
196 | rm -f $(SHAREDLIBV) $(SHAREDLIB) $(SHAREDLIBM); \
197 | fi
198 | cd $(DESTDIR)$(man3dir); rm -f zlib.3
199 | cd $(DESTDIR)$(pkgconfigdir); rm -f zlib.pc
200 |
201 | docs: zlib.3.pdf
202 |
203 | zlib.3.pdf: zlib.3
204 | groff -mandoc -f H -T ps zlib.3 | ps2pdf - zlib.3.pdf
205 |
206 | zconf.h.in: zconf.h.cmakein
207 | sed "/^#cmakedefine/D" < zconf.h.cmakein > zconf.h.in
208 | touch -r zconf.h.cmakein zconf.h.in
209 |
210 | zconf: zconf.h.in
211 | cp -p zconf.h.in zconf.h
212 |
213 | mostlyclean: clean
214 | clean:
215 | rm -f *.o *.lo *~ \
216 | example$(EXE) minigzip$(EXE) examplesh$(EXE) minigzipsh$(EXE) \
217 | example64$(EXE) minigzip64$(EXE) \
218 | libz.* foo.gz so_locations \
219 | _match.s maketree contrib/infback9/*.o
220 | rm -rf objs
221 |
222 | maintainer-clean: distclean
223 | distclean: clean zconf docs
224 | rm -f Makefile zlib.pc
225 | -@rm -f .DS_Store
226 | -@printf 'all:\n\t-@echo "Please use ./configure first. Thank you."\n' > Makefile
227 | -@printf '\ndistclean:\n\tmake -f Makefile.in distclean\n' >> Makefile
228 | -@touch -r Makefile.in Makefile
229 |
230 | tags:
231 | etags *.[ch]
232 |
233 | depend:
234 | makedepend -- $(CFLAGS) -- *.[ch]
235 |
236 | # DO NOT DELETE THIS LINE -- make depend depends on it.
237 |
238 | adler32.o zutil.o: zutil.h zlib.h zconf.h
239 | gzclose.o gzlib.o gzread.o gzwrite.o: zlib.h zconf.h gzguts.h
240 | compress.o example.o minigzip.o uncompr.o: zlib.h zconf.h
241 | crc32.o: zutil.h zlib.h zconf.h crc32.h
242 | deflate.o: deflate.h zutil.h zlib.h zconf.h
243 | infback.o inflate.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
244 | inffast.o: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
245 | inftrees.o: zutil.h zlib.h zconf.h inftrees.h
246 | trees.o: deflate.h zutil.h zlib.h zconf.h trees.h
247 |
248 | adler32.lo zutil.lo: zutil.h zlib.h zconf.h
249 | gzclose.lo gzlib.lo gzread.lo gzwrite.lo: zlib.h zconf.h gzguts.h
250 | compress.lo example.lo minigzip.lo uncompr.lo: zlib.h zconf.h
251 | crc32.lo: zutil.h zlib.h zconf.h crc32.h
252 | deflate.lo: deflate.h zutil.h zlib.h zconf.h
253 | infback.lo inflate.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h inffixed.h
254 | inffast.lo: zutil.h zlib.h zconf.h inftrees.h inflate.h inffast.h
255 | inftrees.lo: zutil.h zlib.h zconf.h inftrees.h
256 | trees.lo: deflate.h zutil.h zlib.h zconf.h trees.h
257 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/README:
--------------------------------------------------------------------------------
1 | ZLIB DATA COMPRESSION LIBRARY
2 |
3 | zlib 1.2.5 is a general purpose data compression library. All the code is
4 | thread safe. The data format used by the zlib library is described by RFCs
5 | (Request for Comments) 1950 to 1952 in the files
6 | http://www.ietf.org/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format)
7 | and rfc1952.txt (gzip format).
8 |
9 | All functions of the compression library are documented in the file zlib.h
10 | (volunteer to write man pages welcome, contact zlib@gzip.org). A usage example
11 | of the library is given in the file example.c which also tests that the library
12 | is working correctly. Another example is given in the file minigzip.c. The
13 | compression library itself is composed of all source files except example.c and
14 | minigzip.c.
15 |
16 | To compile all files and run the test program, follow the instructions given at
17 | the top of Makefile.in. In short "./configure; make test", and if that goes
18 | well, "make install" should work for most flavors of Unix. For Windows, use one
19 | of the special makefiles in win32/ or contrib/vstudio/ . For VMS, use
20 | make_vms.com.
21 |
22 | Questions about zlib should be sent to , or to Gilles Vollant
23 | for the Windows DLL version. The zlib home page is
24 | http://zlib.net/ . Before reporting a problem, please check this site to
25 | verify that you have the latest version of zlib; otherwise get the latest
26 | version and check whether the problem still exists or not.
27 |
28 | PLEASE read the zlib FAQ http://zlib.net/zlib_faq.html before asking for help.
29 |
30 | Mark Nelson wrote an article about zlib for the Jan. 1997
31 | issue of Dr. Dobb's Journal; a copy of the article is available at
32 | http://marknelson.us/1997/01/01/zlib-engine/ .
33 |
34 | The changes made in version 1.2.5 are documented in the file ChangeLog.
35 |
36 | Unsupported third party contributions are provided in directory contrib/ .
37 |
38 | zlib is available in Java using the java.util.zip package, documented at
39 | http://java.sun.com/developer/technicalArticles/Programming/compression/ .
40 |
41 | A Perl interface to zlib written by Paul Marquess is available
42 | at CPAN (Comprehensive Perl Archive Network) sites, including
43 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/ .
44 |
45 | A Python interface to zlib written by A.M. Kuchling is
46 | available in Python 1.5 and later versions, see
47 | http://www.python.org/doc/lib/module-zlib.html .
48 |
49 | zlib is built into tcl: http://wiki.tcl.tk/4610 .
50 |
51 | An experimental package to read and write files in .zip format, written on top
52 | of zlib by Gilles Vollant , is available in the
53 | contrib/minizip directory of zlib.
54 |
55 | Notes for some targets:
56 |
57 | - For Windows DLL versions, please see win32/DLL_FAQ.txt
58 |
59 | - For 64-bit Irix, deflate.c must be compiled without any optimization. With
60 | -O, one libpng test fails. The test works in 32 bit mode (with the -n32
61 | compiler flag). The compiler bug has been reported to SGI.
62 |
63 | - zlib doesn't work with gcc 2.6.3 on a DEC 3000/300LX under OSF/1 2.1 it works
64 | when compiled with cc.
65 |
66 | - On Digital Unix 4.0D (formely OSF/1) on AlphaServer, the cc option -std1 is
67 | necessary to get gzprintf working correctly. This is done by configure.
68 |
69 | - zlib doesn't work on HP-UX 9.05 with some versions of /bin/cc. It works with
70 | other compilers. Use "make test" to check your compiler.
71 |
72 | - gzdopen is not supported on RISCOS or BEOS.
73 |
74 | - For PalmOs, see http://palmzlib.sourceforge.net/
75 |
76 | Acknowledgments:
77 |
78 | The deflate format used by zlib was defined by Phil Katz. The deflate and
79 | zlib specifications were written by L. Peter Deutsch. Thanks to all the
80 | people who reported problems and suggested various improvements in zlib; they
81 | are too numerous to cite here.
82 |
83 | Copyright notice:
84 |
85 | (C) 1995-2010 Jean-loup Gailly and Mark Adler
86 |
87 | This software is provided 'as-is', without any express or implied
88 | warranty. In no event will the authors be held liable for any damages
89 | arising from the use of this software.
90 |
91 | Permission is granted to anyone to use this software for any purpose,
92 | including commercial applications, and to alter it and redistribute it
93 | freely, subject to the following restrictions:
94 |
95 | 1. The origin of this software must not be misrepresented; you must not
96 | claim that you wrote the original software. If you use this software
97 | in a product, an acknowledgment in the product documentation would be
98 | appreciated but is not required.
99 | 2. Altered source versions must be plainly marked as such, and must not be
100 | misrepresented as being the original software.
101 | 3. This notice may not be removed or altered from any source distribution.
102 |
103 | Jean-loup Gailly Mark Adler
104 | jloup@gzip.org madler@alumni.caltech.edu
105 |
106 | If you use the zlib library in a product, we would appreciate _not_ receiving
107 | lengthy legal documents to sign. The sources are provided for free but without
108 | warranty of any kind. The library has been entirely written by Jean-loup
109 | Gailly and Mark Adler; it does not include third-party code.
110 |
111 | If you redistribute modified sources, we would appreciate that you include in
112 | the file ChangeLog history information documenting your changes. Please read
113 | the FAQ for more information on the distribution of modified source versions.
114 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/adler32.c:
--------------------------------------------------------------------------------
1 | /* adler32.c -- compute the Adler-32 checksum of a data stream
2 | * Copyright (C) 1995-2007 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "zutil.h"
9 |
10 | #define local static
11 |
12 | local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2);
13 |
14 | #define BASE 65521UL /* largest prime smaller than 65536 */
15 | #define NMAX 5552
16 | /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
17 |
18 | #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
19 | #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
20 | #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
21 | #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
22 | #define DO16(buf) DO8(buf,0); DO8(buf,8);
23 |
24 | /* use NO_DIVIDE if your processor does not do division in hardware */
25 | #ifdef NO_DIVIDE
26 | # define MOD(a) \
27 | do { \
28 | if (a >= (BASE << 16)) a -= (BASE << 16); \
29 | if (a >= (BASE << 15)) a -= (BASE << 15); \
30 | if (a >= (BASE << 14)) a -= (BASE << 14); \
31 | if (a >= (BASE << 13)) a -= (BASE << 13); \
32 | if (a >= (BASE << 12)) a -= (BASE << 12); \
33 | if (a >= (BASE << 11)) a -= (BASE << 11); \
34 | if (a >= (BASE << 10)) a -= (BASE << 10); \
35 | if (a >= (BASE << 9)) a -= (BASE << 9); \
36 | if (a >= (BASE << 8)) a -= (BASE << 8); \
37 | if (a >= (BASE << 7)) a -= (BASE << 7); \
38 | if (a >= (BASE << 6)) a -= (BASE << 6); \
39 | if (a >= (BASE << 5)) a -= (BASE << 5); \
40 | if (a >= (BASE << 4)) a -= (BASE << 4); \
41 | if (a >= (BASE << 3)) a -= (BASE << 3); \
42 | if (a >= (BASE << 2)) a -= (BASE << 2); \
43 | if (a >= (BASE << 1)) a -= (BASE << 1); \
44 | if (a >= BASE) a -= BASE; \
45 | } while (0)
46 | # define MOD4(a) \
47 | do { \
48 | if (a >= (BASE << 4)) a -= (BASE << 4); \
49 | if (a >= (BASE << 3)) a -= (BASE << 3); \
50 | if (a >= (BASE << 2)) a -= (BASE << 2); \
51 | if (a >= (BASE << 1)) a -= (BASE << 1); \
52 | if (a >= BASE) a -= BASE; \
53 | } while (0)
54 | #else
55 | # define MOD(a) a %= BASE
56 | # define MOD4(a) a %= BASE
57 | #endif
58 |
59 | /* ========================================================================= */
60 | uLong ZEXPORT adler32(adler, buf, len)
61 | uLong adler;
62 | const Bytef *buf;
63 | uInt len;
64 | {
65 | unsigned long sum2;
66 | unsigned n;
67 |
68 | /* split Adler-32 into component sums */
69 | sum2 = (adler >> 16) & 0xffff;
70 | adler &= 0xffff;
71 |
72 | /* in case user likes doing a byte at a time, keep it fast */
73 | if (len == 1) {
74 | adler += buf[0];
75 | if (adler >= BASE)
76 | adler -= BASE;
77 | sum2 += adler;
78 | if (sum2 >= BASE)
79 | sum2 -= BASE;
80 | return adler | (sum2 << 16);
81 | }
82 |
83 | /* initial Adler-32 value (deferred check for len == 1 speed) */
84 | if (buf == Z_NULL)
85 | return 1L;
86 |
87 | /* in case short lengths are provided, keep it somewhat fast */
88 | if (len < 16) {
89 | while (len--) {
90 | adler += *buf++;
91 | sum2 += adler;
92 | }
93 | if (adler >= BASE)
94 | adler -= BASE;
95 | MOD4(sum2); /* only added so many BASE's */
96 | return adler | (sum2 << 16);
97 | }
98 |
99 | /* do length NMAX blocks -- requires just one modulo operation */
100 | while (len >= NMAX) {
101 | len -= NMAX;
102 | n = NMAX / 16; /* NMAX is divisible by 16 */
103 | do {
104 | DO16(buf); /* 16 sums unrolled */
105 | buf += 16;
106 | } while (--n);
107 | MOD(adler);
108 | MOD(sum2);
109 | }
110 |
111 | /* do remaining bytes (less than NMAX, still just one modulo) */
112 | if (len) { /* avoid modulos if none remaining */
113 | while (len >= 16) {
114 | len -= 16;
115 | DO16(buf);
116 | buf += 16;
117 | }
118 | while (len--) {
119 | adler += *buf++;
120 | sum2 += adler;
121 | }
122 | MOD(adler);
123 | MOD(sum2);
124 | }
125 |
126 | /* return recombined sums */
127 | return adler | (sum2 << 16);
128 | }
129 |
130 | /* ========================================================================= */
131 | local uLong adler32_combine_(adler1, adler2, len2)
132 | uLong adler1;
133 | uLong adler2;
134 | z_off64_t len2;
135 | {
136 | unsigned long sum1;
137 | unsigned long sum2;
138 | unsigned rem;
139 |
140 | /* the derivation of this formula is left as an exercise for the reader */
141 | rem = (unsigned)(len2 % BASE);
142 | sum1 = adler1 & 0xffff;
143 | sum2 = rem * sum1;
144 | MOD(sum2);
145 | sum1 += (adler2 & 0xffff) + BASE - 1;
146 | sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
147 | if (sum1 >= BASE) sum1 -= BASE;
148 | if (sum1 >= BASE) sum1 -= BASE;
149 | if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1);
150 | if (sum2 >= BASE) sum2 -= BASE;
151 | return sum1 | (sum2 << 16);
152 | }
153 |
154 | /* ========================================================================= */
155 | uLong ZEXPORT adler32_combine(adler1, adler2, len2)
156 | uLong adler1;
157 | uLong adler2;
158 | z_off_t len2;
159 | {
160 | return adler32_combine_(adler1, adler2, len2);
161 | }
162 |
163 | uLong ZEXPORT adler32_combine64(adler1, adler2, len2)
164 | uLong adler1;
165 | uLong adler2;
166 | z_off64_t len2;
167 | {
168 | return adler32_combine_(adler1, adler2, len2);
169 | }
170 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/benchmark.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 The Emscripten Authors. All rights reserved.
3 | * Emscripten is available under two separate licenses, the MIT license and the
4 | * University of Illinois/NCSA Open Source License. Both these licenses can be
5 | * found in the LICENSE file.
6 | */
7 |
8 | #include "zlib.h"
9 | #include
10 | #include
11 | #include
12 | #include
13 |
14 |
15 | // don't inline, to be friendly to js engine osr
16 | void __attribute__ ((noinline)) doit(unsigned char *buffer, int size, int i) {
17 | static unsigned char *buffer2 = NULL;
18 | static unsigned char *buffer3 = NULL;
19 |
20 | unsigned long maxCompressedSize = compressBound(size);
21 |
22 | if (!buffer2) buffer2 = (unsigned char*)malloc(maxCompressedSize);
23 | if (!buffer3) buffer3 = (unsigned char*)malloc(size);
24 |
25 | unsigned long compressedSize = maxCompressedSize;
26 | compress(buffer2, &compressedSize, buffer, size);
27 | if (i == 0) printf("sizes: %d,%d\n", size, (int)compressedSize);
28 |
29 | unsigned long decompressedSize = size;
30 | uncompress(buffer3, &decompressedSize, buffer2, (int)compressedSize);
31 | assert(decompressedSize == size);
32 | if (i == 0) assert(strcmp((char*)buffer, (char*)buffer3) == 0);
33 | }
34 |
35 | int main(int argc, char **argv) {
36 | int size, iters;
37 | int arg = argc > 1 ? argv[1][0] - '0' : 3;
38 | switch(arg) {
39 | case 0: return 0; break;
40 | case 1: size = 100000; iters = 60; break;
41 | case 2: size = 100000; iters = 250; break;
42 | case 3: size = 100000; iters = 500; break;
43 | case 4: size = 100000; iters = 5*500; break;
44 | case 5: size = 100000; iters = 10*500; break;
45 | default: printf("error: %d\\n", arg); return -1;
46 | }
47 |
48 | unsigned char *buffer = (unsigned char*)malloc(size);
49 |
50 | int i = 0;
51 | int run = 0;
52 | char runChar = 17;
53 | while (i < size) {
54 | if (run > 0) {
55 | run--;
56 | } else {
57 | if ((i & 7) == 0) {
58 | runChar = i & 7;
59 | run = i & 31;
60 | } else {
61 | runChar = (i*i) % 6714;
62 | }
63 | }
64 | buffer[i] = runChar;
65 | i++;
66 | }
67 |
68 | for (i = 0; i < iters; i++) {
69 | doit(buffer, size, i);
70 | }
71 |
72 | printf("ok.\n");
73 |
74 | return 0;
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/compress.c:
--------------------------------------------------------------------------------
1 | /* compress.c -- compress a memory buffer
2 | * Copyright (C) 1995-2005 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #define ZLIB_INTERNAL
9 | #include "zlib.h"
10 |
11 | /* ===========================================================================
12 | Compresses the source buffer into the destination buffer. The level
13 | parameter has the same meaning as in deflateInit. sourceLen is the byte
14 | length of the source buffer. Upon entry, destLen is the total size of the
15 | destination buffer, which must be at least 0.1% larger than sourceLen plus
16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer.
17 |
18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer,
20 | Z_STREAM_ERROR if the level parameter is invalid.
21 | */
22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level)
23 | Bytef *dest;
24 | uLongf *destLen;
25 | const Bytef *source;
26 | uLong sourceLen;
27 | int level;
28 | {
29 | z_stream stream;
30 | int err;
31 |
32 | stream.next_in = (Bytef*)source;
33 | stream.avail_in = (uInt)sourceLen;
34 | #ifdef MAXSEG_64K
35 | /* Check for source > 64K on 16-bit machine: */
36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37 | #endif
38 | stream.next_out = dest;
39 | stream.avail_out = (uInt)*destLen;
40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
41 |
42 | stream.zalloc = (alloc_func)0;
43 | stream.zfree = (free_func)0;
44 | stream.opaque = (voidpf)0;
45 |
46 | err = deflateInit(&stream, level);
47 | if (err != Z_OK) return err;
48 |
49 | err = deflate(&stream, Z_FINISH);
50 | if (err != Z_STREAM_END) {
51 | deflateEnd(&stream);
52 | return err == Z_OK ? Z_BUF_ERROR : err;
53 | }
54 | *destLen = stream.total_out;
55 |
56 | err = deflateEnd(&stream);
57 | return err;
58 | }
59 |
60 | /* ===========================================================================
61 | */
62 | int ZEXPORT compress (dest, destLen, source, sourceLen)
63 | Bytef *dest;
64 | uLongf *destLen;
65 | const Bytef *source;
66 | uLong sourceLen;
67 | {
68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
69 | }
70 |
71 | /* ===========================================================================
72 | If the default memLevel or windowBits for deflateInit() is changed, then
73 | this function needs to be updated.
74 | */
75 | uLong ZEXPORT compressBound (sourceLen)
76 | uLong sourceLen;
77 | {
78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
79 | (sourceLen >> 25) + 13;
80 | }
81 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/gzclose.c:
--------------------------------------------------------------------------------
1 | /* gzclose.c -- zlib gzclose() function
2 | * Copyright (C) 2004, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #include "gzguts.h"
7 |
8 | /* gzclose() is in a separate file so that it is linked in only if it is used.
9 | That way the other gzclose functions can be used instead to avoid linking in
10 | unneeded compression or decompression routines. */
11 | int ZEXPORT gzclose(file)
12 | gzFile file;
13 | {
14 | #ifndef NO_GZCOMPRESS
15 | gz_statep state;
16 |
17 | if (file == NULL)
18 | return Z_STREAM_ERROR;
19 | state = (gz_statep)file;
20 |
21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file);
22 | #else
23 | return gzclose_r(file);
24 | #endif
25 | }
26 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/gzguts.h:
--------------------------------------------------------------------------------
1 | /* gzguts.h -- zlib internal header definitions for gz* operations
2 | * Copyright (C) 2004, 2005, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | #ifdef _LARGEFILE64_SOURCE
7 | # ifndef _LARGEFILE_SOURCE
8 | # define _LARGEFILE_SOURCE 1
9 | # endif
10 | # ifdef _FILE_OFFSET_BITS
11 | # undef _FILE_OFFSET_BITS
12 | # endif
13 | #endif
14 |
15 | #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
16 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
17 | #else
18 | # define ZLIB_INTERNAL
19 | #endif
20 |
21 | #include
22 | #include "zlib.h"
23 | #ifdef STDC
24 | # include
25 | # include
26 | # include
27 | #endif
28 | #include
29 |
30 | #ifdef __unix__
31 | #include
32 | #endif
33 |
34 | #ifdef NO_DEFLATE /* for compatibility with old definition */
35 | # define NO_GZCOMPRESS
36 | #endif
37 |
38 | #ifdef _MSC_VER
39 | # include
40 | # define vsnprintf _vsnprintf
41 | #endif
42 |
43 | #ifndef local
44 | # define local static
45 | #endif
46 | /* compile with -Dlocal if your debugger can't find static symbols */
47 |
48 | /* gz* functions always use library allocation functions */
49 | #ifndef STDC
50 | extern voidp malloc OF((uInt size));
51 | extern void free OF((voidpf ptr));
52 | #endif
53 |
54 | /* get errno and strerror definition */
55 | #if defined UNDER_CE
56 | # include
57 | # define zstrerror() gz_strwinerror((DWORD)GetLastError())
58 | #else
59 | # ifdef STDC
60 | # include
61 | # define zstrerror() strerror(errno)
62 | # else
63 | # define zstrerror() "stdio error (consult errno)"
64 | # endif
65 | #endif
66 |
67 | /* provide prototypes for these when building zlib without LFS */
68 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
69 | ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *));
70 | ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int));
71 | ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile));
72 | ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile));
73 | #endif
74 |
75 | /* default i/o buffer size -- double this for output when reading */
76 | #define GZBUFSIZE 8192
77 |
78 | /* gzip modes, also provide a little integrity check on the passed structure */
79 | #define GZ_NONE 0
80 | #define GZ_READ 7247
81 | #define GZ_WRITE 31153
82 | #define GZ_APPEND 1 /* mode set to GZ_WRITE after the file is opened */
83 |
84 | /* values for gz_state how */
85 | #define LOOK 0 /* look for a gzip header */
86 | #define COPY 1 /* copy input directly */
87 | #define GZIP 2 /* decompress a gzip stream */
88 |
89 | /* internal gzip file state data structure */
90 | typedef struct {
91 | /* used for both reading and writing */
92 | int mode; /* see gzip modes above */
93 | int fd; /* file descriptor */
94 | char *path; /* path or fd for error messages */
95 | z_off64_t pos; /* current position in uncompressed data */
96 | unsigned size; /* buffer size, zero if not allocated yet */
97 | unsigned want; /* requested buffer size, default is GZBUFSIZE */
98 | unsigned char *in; /* input buffer */
99 | unsigned char *out; /* output buffer (double-sized when reading) */
100 | unsigned char *next; /* next output data to deliver or write */
101 | /* just for reading */
102 | unsigned have; /* amount of output data unused at next */
103 | int eof; /* true if end of input file reached */
104 | z_off64_t start; /* where the gzip data started, for rewinding */
105 | z_off64_t raw; /* where the raw data started, for seeking */
106 | int how; /* 0: get header, 1: copy, 2: decompress */
107 | int direct; /* true if last read direct, false if gzip */
108 | /* just for writing */
109 | int level; /* compression level */
110 | int strategy; /* compression strategy */
111 | /* seek request */
112 | z_off64_t skip; /* amount to skip (already rewound if backwards) */
113 | int seek; /* true if seek request pending */
114 | /* error information */
115 | int err; /* error code */
116 | char *msg; /* error message */
117 | /* zlib inflate or deflate stream */
118 | z_stream strm; /* stream structure in-place (not a pointer) */
119 | } gz_state;
120 | typedef gz_state FAR *gz_statep;
121 |
122 | /* shared functions */
123 | void ZLIB_INTERNAL gz_error OF((gz_statep, int, const char *));
124 | #if defined UNDER_CE
125 | char ZLIB_INTERNAL *gz_strwinerror OF((DWORD error));
126 | #endif
127 |
128 | /* GT_OFF(x), where x is an unsigned value, is true if x > maximum z_off64_t
129 | value -- needed when comparing unsigned to z_off64_t, which is signed
130 | (possible z_off64_t types off_t, off64_t, and long are all signed) */
131 | #ifdef INT_MAX
132 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > INT_MAX)
133 | #else
134 | unsigned ZLIB_INTERNAL gz_intmax OF((void));
135 | # define GT_OFF(x) (sizeof(int) == sizeof(z_off64_t) && (x) > gz_intmax())
136 | #endif
137 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/inffast.h:
--------------------------------------------------------------------------------
1 | /* inffast.h -- header to use inffast.c
2 | * Copyright (C) 1995-2003, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start));
12 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/inffixed.h:
--------------------------------------------------------------------------------
1 | /* inffixed.h -- table for decoding fixed codes
2 | * Generated automatically by makefixed().
3 | */
4 |
5 | /* WARNING: this file should *not* be used by applications. It
6 | is part of the implementation of the compression library and
7 | is subject to change. Applications should only use zlib.h.
8 | */
9 |
10 | static const code lenfix[512] = {
11 | {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
12 | {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
13 | {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
14 | {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
15 | {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
16 | {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
17 | {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
18 | {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
19 | {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
20 | {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
21 | {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
22 | {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
23 | {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
24 | {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
25 | {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
26 | {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
27 | {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
28 | {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
29 | {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
30 | {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
31 | {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
32 | {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
33 | {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
34 | {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
35 | {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
36 | {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
37 | {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
38 | {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
39 | {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
40 | {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
41 | {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
42 | {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
43 | {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
44 | {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
45 | {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
46 | {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
47 | {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
48 | {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
49 | {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
50 | {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
51 | {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
52 | {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
53 | {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
54 | {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
55 | {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
56 | {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
57 | {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
58 | {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
59 | {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
60 | {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
61 | {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
62 | {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
63 | {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
64 | {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
65 | {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
66 | {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
67 | {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
68 | {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
69 | {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
70 | {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
71 | {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
72 | {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
73 | {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
74 | {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
75 | {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
76 | {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
77 | {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
78 | {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
79 | {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
80 | {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
81 | {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
82 | {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
83 | {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
84 | {0,9,255}
85 | };
86 |
87 | static const code distfix[32] = {
88 | {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
89 | {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
90 | {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
91 | {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
92 | {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
93 | {22,5,193},{64,5,0}
94 | };
95 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/inflate.h:
--------------------------------------------------------------------------------
1 | /* inflate.h -- internal inflate state definition
2 | * Copyright (C) 1995-2009 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* define NO_GZIP when compiling if you want to disable gzip header and
12 | trailer decoding by inflate(). NO_GZIP would be used to avoid linking in
13 | the crc code when it is not needed. For shared libraries, gzip decoding
14 | should be left enabled. */
15 | #ifndef NO_GZIP
16 | # define GUNZIP
17 | #endif
18 |
19 | /* Possible inflate modes between inflate() calls */
20 | typedef enum {
21 | HEAD, /* i: waiting for magic header */
22 | FLAGS, /* i: waiting for method and flags (gzip) */
23 | TIME, /* i: waiting for modification time (gzip) */
24 | OS, /* i: waiting for extra flags and operating system (gzip) */
25 | EXLEN, /* i: waiting for extra length (gzip) */
26 | EXTRA, /* i: waiting for extra bytes (gzip) */
27 | NAME, /* i: waiting for end of file name (gzip) */
28 | COMMENT, /* i: waiting for end of comment (gzip) */
29 | HCRC, /* i: waiting for header crc (gzip) */
30 | DICTID, /* i: waiting for dictionary check value */
31 | DICT, /* waiting for inflateSetDictionary() call */
32 | TYPE, /* i: waiting for type bits, including last-flag bit */
33 | TYPEDO, /* i: same, but skip check to exit inflate on new block */
34 | STORED, /* i: waiting for stored size (length and complement) */
35 | COPY_, /* i/o: same as COPY below, but only first time in */
36 | COPY, /* i/o: waiting for input or output to copy stored block */
37 | TABLE, /* i: waiting for dynamic block table lengths */
38 | LENLENS, /* i: waiting for code length code lengths */
39 | CODELENS, /* i: waiting for length/lit and distance code lengths */
40 | LEN_, /* i: same as LEN below, but only first time in */
41 | LEN, /* i: waiting for length/lit/eob code */
42 | LENEXT, /* i: waiting for length extra bits */
43 | DIST, /* i: waiting for distance code */
44 | DISTEXT, /* i: waiting for distance extra bits */
45 | MATCH, /* o: waiting for output space to copy string */
46 | LIT, /* o: waiting for output space to write literal */
47 | CHECK, /* i: waiting for 32-bit check value */
48 | LENGTH, /* i: waiting for 32-bit length (gzip) */
49 | DONE, /* finished check, done -- remain here until reset */
50 | BAD, /* got a data error -- remain here until reset */
51 | MEM, /* got an inflate() memory error -- remain here until reset */
52 | SYNC /* looking for synchronization bytes to restart inflate() */
53 | } inflate_mode;
54 |
55 | /*
56 | State transitions between above modes -
57 |
58 | (most modes can go to BAD or MEM on error -- not shown for clarity)
59 |
60 | Process header:
61 | HEAD -> (gzip) or (zlib) or (raw)
62 | (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT ->
63 | HCRC -> TYPE
64 | (zlib) -> DICTID or TYPE
65 | DICTID -> DICT -> TYPE
66 | (raw) -> TYPEDO
67 | Read deflate blocks:
68 | TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK
69 | STORED -> COPY_ -> COPY -> TYPE
70 | TABLE -> LENLENS -> CODELENS -> LEN_
71 | LEN_ -> LEN
72 | Read deflate codes in fixed or dynamic block:
73 | LEN -> LENEXT or LIT or TYPE
74 | LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
75 | LIT -> LEN
76 | Process trailer:
77 | CHECK -> LENGTH -> DONE
78 | */
79 |
80 | /* state maintained between inflate() calls. Approximately 10K bytes. */
81 | struct inflate_state {
82 | inflate_mode mode; /* current inflate mode */
83 | int last; /* true if processing last block */
84 | int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
85 | int havedict; /* true if dictionary provided */
86 | int flags; /* gzip header method and flags (0 if zlib) */
87 | unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
88 | unsigned long check; /* protected copy of check value */
89 | unsigned long total; /* protected copy of output count */
90 | gz_headerp head; /* where to save gzip header information */
91 | /* sliding window */
92 | unsigned wbits; /* log base 2 of requested window size */
93 | unsigned wsize; /* window size or zero if not using window */
94 | unsigned whave; /* valid bytes in the window */
95 | unsigned wnext; /* window write index */
96 | unsigned char FAR *window; /* allocated sliding window, if needed */
97 | /* bit accumulator */
98 | unsigned long hold; /* input bit accumulator */
99 | unsigned bits; /* number of bits in "in" */
100 | /* for string and stored block copying */
101 | unsigned length; /* literal or length of data to copy */
102 | unsigned offset; /* distance back to copy string from */
103 | /* for table and code decoding */
104 | unsigned extra; /* extra bits needed */
105 | /* fixed and dynamic code tables */
106 | code const FAR *lencode; /* starting table for length/literal codes */
107 | code const FAR *distcode; /* starting table for distance codes */
108 | unsigned lenbits; /* index bits for lencode */
109 | unsigned distbits; /* index bits for distcode */
110 | /* dynamic table building */
111 | unsigned ncode; /* number of code length code lengths */
112 | unsigned nlen; /* number of length code lengths */
113 | unsigned ndist; /* number of distance code lengths */
114 | unsigned have; /* number of code lengths in lens[] */
115 | code FAR *next; /* next available space in codes[] */
116 | unsigned short lens[320]; /* temporary storage for code lengths */
117 | unsigned short work[288]; /* work area for code table building */
118 | code codes[ENOUGH]; /* space for code tables */
119 | int sane; /* if false, allow invalid distance too far */
120 | int back; /* bits back of last unprocessed length/lit */
121 | unsigned was; /* initial length of match */
122 | };
123 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/inftrees.h:
--------------------------------------------------------------------------------
1 | /* inftrees.h -- header to use inftrees.c
2 | * Copyright (C) 1995-2005, 2010 Mark Adler
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* Structure for decoding tables. Each entry provides either the
12 | information needed to do the operation requested by the code that
13 | indexed that table entry, or it provides a pointer to another
14 | table that indexes more bits of the code. op indicates whether
15 | the entry is a pointer to another table, a literal, a length or
16 | distance, an end-of-block, or an invalid code. For a table
17 | pointer, the low four bits of op is the number of index bits of
18 | that table. For a length or distance, the low four bits of op
19 | is the number of extra bits to get after the code. bits is
20 | the number of bits in this code or part of the code to drop off
21 | of the bit buffer. val is the actual byte to output in the case
22 | of a literal, the base length or distance, or the offset from
23 | the current table to the next table. Each entry is four bytes. */
24 | typedef struct {
25 | unsigned char op; /* operation, extra bits, table bits */
26 | unsigned char bits; /* bits in this part of the code */
27 | unsigned short val; /* offset in table or code value */
28 | } code;
29 |
30 | /* op values as set by inflate_table():
31 | 00000000 - literal
32 | 0000tttt - table link, tttt != 0 is the number of table index bits
33 | 0001eeee - length or distance, eeee is the number of extra bits
34 | 01100000 - end of block
35 | 01000000 - invalid code
36 | */
37 |
38 | /* Maximum size of the dynamic table. The maximum number of code structures is
39 | 1444, which is the sum of 852 for literal/length codes and 592 for distance
40 | codes. These values were found by exhaustive searches using the program
41 | examples/enough.c found in the zlib distribtution. The arguments to that
42 | program are the number of symbols, the initial root table size, and the
43 | maximum bit length of a code. "enough 286 9 15" for literal/length codes
44 | returns returns 852, and "enough 30 6 15" for distance codes returns 592.
45 | The initial root table size (9 or 6) is found in the fifth argument of the
46 | inflate_table() calls in inflate.c and infback.c. If the root table size is
47 | changed, then these maximum sizes would be need to be recalculated and
48 | updated. */
49 | #define ENOUGH_LENS 852
50 | #define ENOUGH_DISTS 592
51 | #define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS)
52 |
53 | /* Type of code to build for inflate_table() */
54 | typedef enum {
55 | CODES,
56 | LENS,
57 | DISTS
58 | } codetype;
59 |
60 | int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens,
61 | unsigned codes, code FAR * FAR *table,
62 | unsigned FAR *bits, unsigned short FAR *work));
63 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/readme.txt:
--------------------------------------------------------------------------------
1 | This is zlib 1.2.5. See README for licensing info.
2 |
3 | Changes for emscripten:
4 |
5 | deflate.c: Initialize match_start to 0, to prevent a SAFE_HEAP notification
6 | Initialize s->prev's buffer (in 2 places) to 0, same reasons
7 |
8 | example.c: Use %d instead of %x in version number printout
9 | Comment out gzio test
10 |
11 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/ref.txt:
--------------------------------------------------------------------------------
1 | uncompress(): hello, hello!
2 | inflate(): hello, hello!
3 | large_inflate(): OK
4 | after inflateSync(): hello, hello!
5 | inflate with dictionary: hello, hello!
6 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/trees.h:
--------------------------------------------------------------------------------
1 | /* header created automatically with -DGEN_TREES_H */
2 |
3 | local const ct_data static_ltree[L_CODES+2] = {
4 | {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
5 | {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
6 | {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
7 | {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
8 | {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
9 | {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
10 | {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
11 | {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
12 | {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
13 | {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
14 | {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
15 | {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
16 | {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
17 | {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
18 | {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
19 | {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
20 | {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
21 | {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
22 | {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
23 | {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
24 | {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
25 | {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
26 | {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
27 | {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
28 | {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
29 | {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
30 | {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
31 | {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
32 | {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
33 | {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
34 | {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
35 | {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
36 | {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
37 | {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
38 | {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
39 | {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
40 | {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
41 | {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
42 | {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
43 | {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
44 | {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
45 | {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
46 | {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
47 | {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
48 | {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
49 | {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
50 | {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
51 | {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
52 | {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
53 | {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
54 | {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
55 | {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
56 | {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
57 | {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
58 | {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
59 | {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
60 | {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
61 | {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
62 | };
63 |
64 | local const ct_data static_dtree[D_CODES] = {
65 | {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
66 | {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
67 | {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
68 | {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
69 | {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
70 | {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
71 | };
72 |
73 | const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {
74 | 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
75 | 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
76 | 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
77 | 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
78 | 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
79 | 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
80 | 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
81 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
82 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
83 | 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
84 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
85 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
86 | 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
87 | 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
88 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
89 | 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
90 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
91 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
92 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
93 | 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
94 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
95 | 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
96 | 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
97 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
98 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
99 | 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
100 | };
101 |
102 | const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {
103 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
104 | 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
105 | 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
106 | 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
107 | 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
108 | 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
109 | 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
110 | 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
111 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
112 | 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
113 | 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
114 | 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
115 | 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
116 | };
117 |
118 | local const int base_length[LENGTH_CODES] = {
119 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
120 | 64, 80, 96, 112, 128, 160, 192, 224, 0
121 | };
122 |
123 | local const int base_dist[D_CODES] = {
124 | 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
125 | 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
126 | 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
127 | };
128 |
129 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/uncompr.c:
--------------------------------------------------------------------------------
1 | /* uncompr.c -- decompress a memory buffer
2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #define ZLIB_INTERNAL
9 | #include "zlib.h"
10 |
11 | /* ===========================================================================
12 | Decompresses the source buffer into the destination buffer. sourceLen is
13 | the byte length of the source buffer. Upon entry, destLen is the total
14 | size of the destination buffer, which must be large enough to hold the
15 | entire uncompressed data. (The size of the uncompressed data must have
16 | been saved previously by the compressor and transmitted to the decompressor
17 | by some mechanism outside the scope of this compression library.)
18 | Upon exit, destLen is the actual size of the compressed buffer.
19 |
20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not
21 | enough memory, Z_BUF_ERROR if there was not enough room in the output
22 | buffer, or Z_DATA_ERROR if the input data was corrupted.
23 | */
24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen)
25 | Bytef *dest;
26 | uLongf *destLen;
27 | const Bytef *source;
28 | uLong sourceLen;
29 | {
30 | z_stream stream;
31 | int err;
32 |
33 | stream.next_in = (Bytef*)source;
34 | stream.avail_in = (uInt)sourceLen;
35 | /* Check for source > 64K on 16-bit machine: */
36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
37 |
38 | stream.next_out = dest;
39 | stream.avail_out = (uInt)*destLen;
40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
41 |
42 | stream.zalloc = (alloc_func)0;
43 | stream.zfree = (free_func)0;
44 |
45 | err = inflateInit(&stream);
46 | if (err != Z_OK) return err;
47 |
48 | err = inflate(&stream, Z_FINISH);
49 | if (err != Z_STREAM_END) {
50 | inflateEnd(&stream);
51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0))
52 | return Z_DATA_ERROR;
53 | return err;
54 | }
55 | *destLen = stream.total_out;
56 |
57 | err = inflateEnd(&stream);
58 | return err;
59 | }
60 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zlib.3:
--------------------------------------------------------------------------------
1 | .TH ZLIB 3 "19 Apr 2010"
2 | .SH NAME
3 | zlib \- compression/decompression library
4 | .SH SYNOPSIS
5 | [see
6 | .I zlib.h
7 | for full description]
8 | .SH DESCRIPTION
9 | The
10 | .I zlib
11 | library is a general purpose data compression library.
12 | The code is thread safe, assuming that the standard library functions
13 | used are thread safe, such as memory allocation routines.
14 | It provides in-memory compression and decompression functions,
15 | including integrity checks of the uncompressed data.
16 | This version of the library supports only one compression method (deflation)
17 | but other algorithms may be added later
18 | with the same stream interface.
19 | .LP
20 | Compression can be done in a single step if the buffers are large enough
21 | or can be done by repeated calls of the compression function.
22 | In the latter case,
23 | the application must provide more input and/or consume the output
24 | (providing more output space) before each call.
25 | .LP
26 | The library also supports reading and writing files in
27 | .IR gzip (1)
28 | (.gz) format
29 | with an interface similar to that of stdio.
30 | .LP
31 | The library does not install any signal handler.
32 | The decoder checks the consistency of the compressed data,
33 | so the library should never crash even in the case of corrupted input.
34 | .LP
35 | All functions of the compression library are documented in the file
36 | .IR zlib.h .
37 | The distribution source includes examples of use of the library
38 | in the files
39 | .I example.c
40 | and
41 | .IR minigzip.c,
42 | as well as other examples in the
43 | .IR examples/
44 | directory.
45 | .LP
46 | Changes to this version are documented in the file
47 | .I ChangeLog
48 | that accompanies the source.
49 | .LP
50 | .I zlib
51 | is available in Java using the java.util.zip package:
52 | .IP
53 | http://java.sun.com/developer/technicalArticles/Programming/compression/
54 | .LP
55 | A Perl interface to
56 | .IR zlib ,
57 | written by Paul Marquess (pmqs@cpan.org),
58 | is available at CPAN (Comprehensive Perl Archive Network) sites,
59 | including:
60 | .IP
61 | http://search.cpan.org/~pmqs/IO-Compress-Zlib/
62 | .LP
63 | A Python interface to
64 | .IR zlib ,
65 | written by A.M. Kuchling (amk@magnet.com),
66 | is available in Python 1.5 and later versions:
67 | .IP
68 | http://www.python.org/doc/lib/module-zlib.html
69 | .LP
70 | .I zlib
71 | is built into
72 | .IR tcl:
73 | .IP
74 | http://wiki.tcl.tk/4610
75 | .LP
76 | An experimental package to read and write files in .zip format,
77 | written on top of
78 | .I zlib
79 | by Gilles Vollant (info@winimage.com),
80 | is available at:
81 | .IP
82 | http://www.winimage.com/zLibDll/minizip.html
83 | and also in the
84 | .I contrib/minizip
85 | directory of the main
86 | .I zlib
87 | source distribution.
88 | .SH "SEE ALSO"
89 | The
90 | .I zlib
91 | web site can be found at:
92 | .IP
93 | http://zlib.net/
94 | .LP
95 | The data format used by the zlib library is described by RFC
96 | (Request for Comments) 1950 to 1952 in the files:
97 | .IP
98 | http://www.ietf.org/rfc/rfc1950.txt (for the zlib header and trailer format)
99 | .br
100 | http://www.ietf.org/rfc/rfc1951.txt (for the deflate compressed data format)
101 | .br
102 | http://www.ietf.org/rfc/rfc1952.txt (for the gzip header and trailer format)
103 | .LP
104 | Mark Nelson wrote an article about
105 | .I zlib
106 | for the Jan. 1997 issue of Dr. Dobb's Journal;
107 | a copy of the article is available at:
108 | .IP
109 | http://marknelson.us/1997/01/01/zlib-engine/
110 | .SH "REPORTING PROBLEMS"
111 | Before reporting a problem,
112 | please check the
113 | .I zlib
114 | web site to verify that you have the latest version of
115 | .IR zlib ;
116 | otherwise,
117 | obtain the latest version and see if the problem still exists.
118 | Please read the
119 | .I zlib
120 | FAQ at:
121 | .IP
122 | http://zlib.net/zlib_faq.html
123 | .LP
124 | before asking for help.
125 | Send questions and/or comments to zlib@gzip.org,
126 | or (for the Windows DLL version) to Gilles Vollant (info@winimage.com).
127 | .SH AUTHORS
128 | Version 1.2.5
129 | Copyright (C) 1995-2010 Jean-loup Gailly (jloup@gzip.org)
130 | and Mark Adler (madler@alumni.caltech.edu).
131 | .LP
132 | This software is provided "as-is,"
133 | without any express or implied warranty.
134 | In no event will the authors be held liable for any damages
135 | arising from the use of this software.
136 | See the distribution directory with respect to requirements
137 | governing redistribution.
138 | The deflate format used by
139 | .I zlib
140 | was defined by Phil Katz.
141 | The deflate and
142 | .I zlib
143 | specifications were written by L. Peter Deutsch.
144 | Thanks to all the people who reported problems and suggested various
145 | improvements in
146 | .IR zlib ;
147 | who are too numerous to cite here.
148 | .LP
149 | UNIX manual page by R. P. C. Rodgers,
150 | U.S. National Library of Medicine (rodgers@nlm.nih.gov).
151 | .\" end of man page
152 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zlib.map:
--------------------------------------------------------------------------------
1 | ZLIB_1.2.0 {
2 | global:
3 | compressBound;
4 | deflateBound;
5 | inflateBack;
6 | inflateBackEnd;
7 | inflateBackInit_;
8 | inflateCopy;
9 | local:
10 | deflate_copyright;
11 | inflate_copyright;
12 | inflate_fast;
13 | inflate_table;
14 | zcalloc;
15 | zcfree;
16 | z_errmsg;
17 | gz_error;
18 | gz_intmax;
19 | _*;
20 | };
21 |
22 | ZLIB_1.2.0.2 {
23 | gzclearerr;
24 | gzungetc;
25 | zlibCompileFlags;
26 | } ZLIB_1.2.0;
27 |
28 | ZLIB_1.2.0.8 {
29 | deflatePrime;
30 | } ZLIB_1.2.0.2;
31 |
32 | ZLIB_1.2.2 {
33 | adler32_combine;
34 | crc32_combine;
35 | deflateSetHeader;
36 | inflateGetHeader;
37 | } ZLIB_1.2.0.8;
38 |
39 | ZLIB_1.2.2.3 {
40 | deflateTune;
41 | gzdirect;
42 | } ZLIB_1.2.2;
43 |
44 | ZLIB_1.2.2.4 {
45 | inflatePrime;
46 | } ZLIB_1.2.2.3;
47 |
48 | ZLIB_1.2.3.3 {
49 | adler32_combine64;
50 | crc32_combine64;
51 | gzopen64;
52 | gzseek64;
53 | gztell64;
54 | inflateUndermine;
55 | } ZLIB_1.2.2.4;
56 |
57 | ZLIB_1.2.3.4 {
58 | inflateReset2;
59 | inflateMark;
60 | } ZLIB_1.2.3.3;
61 |
62 | ZLIB_1.2.3.5 {
63 | gzbuffer;
64 | gzoffset;
65 | gzoffset64;
66 | gzclose_r;
67 | gzclose_w;
68 | } ZLIB_1.2.3.4;
69 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zlib.pc:
--------------------------------------------------------------------------------
1 | prefix=/root/lib/
2 | exec_prefix=${prefix}
3 | libdir=${exec_prefix}/lib
4 | sharedlibdir=${libdir}
5 | includedir=${prefix}/include
6 |
7 | Name: zlib
8 | Description: zlib compression library
9 | Version: 1.2.5
10 |
11 | Requires:
12 | Libs: -L${libdir} -L${sharedlibdir} -lz
13 | Cflags: -I${includedir}
14 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zlib.pc.in:
--------------------------------------------------------------------------------
1 | prefix=@prefix@
2 | exec_prefix=@exec_prefix@
3 | libdir=@libdir@
4 | sharedlibdir=@sharedlibdir@
5 | includedir=@includedir@
6 |
7 | Name: zlib
8 | Description: zlib compression library
9 | Version: @VERSION@
10 |
11 | Requires:
12 | Libs: -L${libdir} -L${sharedlibdir} -lz
13 | Cflags: -I${includedir}
14 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zutil.c:
--------------------------------------------------------------------------------
1 | /* zutil.c -- target dependent utility functions for the compression library
2 | * Copyright (C) 1995-2005, 2010 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* @(#) $Id$ */
7 |
8 | #include "zutil.h"
9 |
10 | #ifndef NO_DUMMY_DECL
11 | struct internal_state {int dummy;}; /* for buggy compilers */
12 | #endif
13 |
14 | const char * const z_errmsg[10] = {
15 | "need dictionary", /* Z_NEED_DICT 2 */
16 | "stream end", /* Z_STREAM_END 1 */
17 | "", /* Z_OK 0 */
18 | "file error", /* Z_ERRNO (-1) */
19 | "stream error", /* Z_STREAM_ERROR (-2) */
20 | "data error", /* Z_DATA_ERROR (-3) */
21 | "insufficient memory", /* Z_MEM_ERROR (-4) */
22 | "buffer error", /* Z_BUF_ERROR (-5) */
23 | "incompatible version",/* Z_VERSION_ERROR (-6) */
24 | ""};
25 |
26 |
27 | const char * ZEXPORT zlibVersion()
28 | {
29 | return ZLIB_VERSION;
30 | }
31 |
32 | uLong ZEXPORT zlibCompileFlags()
33 | {
34 | uLong flags;
35 |
36 | flags = 0;
37 | switch ((int)(sizeof(uInt))) {
38 | case 2: break;
39 | case 4: flags += 1; break;
40 | case 8: flags += 2; break;
41 | default: flags += 3;
42 | }
43 | switch ((int)(sizeof(uLong))) {
44 | case 2: break;
45 | case 4: flags += 1 << 2; break;
46 | case 8: flags += 2 << 2; break;
47 | default: flags += 3 << 2;
48 | }
49 | switch ((int)(sizeof(voidpf))) {
50 | case 2: break;
51 | case 4: flags += 1 << 4; break;
52 | case 8: flags += 2 << 4; break;
53 | default: flags += 3 << 4;
54 | }
55 | switch ((int)(sizeof(z_off_t))) {
56 | case 2: break;
57 | case 4: flags += 1 << 6; break;
58 | case 8: flags += 2 << 6; break;
59 | default: flags += 3 << 6;
60 | }
61 | #ifdef DEBUG
62 | flags += 1 << 8;
63 | #endif
64 | #if defined(ASMV) || defined(ASMINF)
65 | flags += 1 << 9;
66 | #endif
67 | #ifdef ZLIB_WINAPI
68 | flags += 1 << 10;
69 | #endif
70 | #ifdef BUILDFIXED
71 | flags += 1 << 12;
72 | #endif
73 | #ifdef DYNAMIC_CRC_TABLE
74 | flags += 1 << 13;
75 | #endif
76 | #ifdef NO_GZCOMPRESS
77 | flags += 1L << 16;
78 | #endif
79 | #ifdef NO_GZIP
80 | flags += 1L << 17;
81 | #endif
82 | #ifdef PKZIP_BUG_WORKAROUND
83 | flags += 1L << 20;
84 | #endif
85 | #ifdef FASTEST
86 | flags += 1L << 21;
87 | #endif
88 | #ifdef STDC
89 | # ifdef NO_vsnprintf
90 | flags += 1L << 25;
91 | # ifdef HAS_vsprintf_void
92 | flags += 1L << 26;
93 | # endif
94 | # else
95 | # ifdef HAS_vsnprintf_void
96 | flags += 1L << 26;
97 | # endif
98 | # endif
99 | #else
100 | flags += 1L << 24;
101 | # ifdef NO_snprintf
102 | flags += 1L << 25;
103 | # ifdef HAS_sprintf_void
104 | flags += 1L << 26;
105 | # endif
106 | # else
107 | # ifdef HAS_snprintf_void
108 | flags += 1L << 26;
109 | # endif
110 | # endif
111 | #endif
112 | return flags;
113 | }
114 |
115 | #ifdef DEBUG
116 |
117 | # ifndef verbose
118 | # define verbose 0
119 | # endif
120 | int ZLIB_INTERNAL z_verbose = verbose;
121 |
122 | void ZLIB_INTERNAL z_error (m)
123 | char *m;
124 | {
125 | fprintf(stderr, "%s\n", m);
126 | exit(1);
127 | }
128 | #endif
129 |
130 | /* exported to allow conversion of error code to string for compress() and
131 | * uncompress()
132 | */
133 | const char * ZEXPORT zError(err)
134 | int err;
135 | {
136 | return ERR_MSG(err);
137 | }
138 |
139 | #if defined(_WIN32_WCE)
140 | /* The Microsoft C Run-Time Library for Windows CE doesn't have
141 | * errno. We define it as a global variable to simplify porting.
142 | * Its value is always 0 and should not be used.
143 | */
144 | int errno = 0;
145 | #endif
146 |
147 | #ifndef HAVE_MEMCPY
148 |
149 | void ZLIB_INTERNAL zmemcpy(dest, source, len)
150 | Bytef* dest;
151 | const Bytef* source;
152 | uInt len;
153 | {
154 | if (len == 0) return;
155 | do {
156 | *dest++ = *source++; /* ??? to be unrolled */
157 | } while (--len != 0);
158 | }
159 |
160 | int ZLIB_INTERNAL zmemcmp(s1, s2, len)
161 | const Bytef* s1;
162 | const Bytef* s2;
163 | uInt len;
164 | {
165 | uInt j;
166 |
167 | for (j = 0; j < len; j++) {
168 | if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
169 | }
170 | return 0;
171 | }
172 |
173 | void ZLIB_INTERNAL zmemzero(dest, len)
174 | Bytef* dest;
175 | uInt len;
176 | {
177 | if (len == 0) return;
178 | do {
179 | *dest++ = 0; /* ??? to be unrolled */
180 | } while (--len != 0);
181 | }
182 | #endif
183 |
184 |
185 | #ifdef SYS16BIT
186 |
187 | #ifdef __TURBOC__
188 | /* Turbo C in 16-bit mode */
189 |
190 | # define MY_ZCALLOC
191 |
192 | /* Turbo C malloc() does not allow dynamic allocation of 64K bytes
193 | * and farmalloc(64K) returns a pointer with an offset of 8, so we
194 | * must fix the pointer. Warning: the pointer must be put back to its
195 | * original form in order to free it, use zcfree().
196 | */
197 |
198 | #define MAX_PTR 10
199 | /* 10*64K = 640K */
200 |
201 | local int next_ptr = 0;
202 |
203 | typedef struct ptr_table_s {
204 | voidpf org_ptr;
205 | voidpf new_ptr;
206 | } ptr_table;
207 |
208 | local ptr_table table[MAX_PTR];
209 | /* This table is used to remember the original form of pointers
210 | * to large buffers (64K). Such pointers are normalized with a zero offset.
211 | * Since MSDOS is not a preemptive multitasking OS, this table is not
212 | * protected from concurrent access. This hack doesn't work anyway on
213 | * a protected system like OS/2. Use Microsoft C instead.
214 | */
215 |
216 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size)
217 | {
218 | voidpf buf = opaque; /* just to make some compilers happy */
219 | ulg bsize = (ulg)items*size;
220 |
221 | /* If we allocate less than 65520 bytes, we assume that farmalloc
222 | * will return a usable pointer which doesn't have to be normalized.
223 | */
224 | if (bsize < 65520L) {
225 | buf = farmalloc(bsize);
226 | if (*(ush*)&buf != 0) return buf;
227 | } else {
228 | buf = farmalloc(bsize + 16L);
229 | }
230 | if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
231 | table[next_ptr].org_ptr = buf;
232 |
233 | /* Normalize the pointer to seg:0 */
234 | *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
235 | *(ush*)&buf = 0;
236 | table[next_ptr++].new_ptr = buf;
237 | return buf;
238 | }
239 |
240 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
241 | {
242 | int n;
243 | if (*(ush*)&ptr != 0) { /* object < 64K */
244 | farfree(ptr);
245 | return;
246 | }
247 | /* Find the original pointer */
248 | for (n = 0; n < next_ptr; n++) {
249 | if (ptr != table[n].new_ptr) continue;
250 |
251 | farfree(table[n].org_ptr);
252 | while (++n < next_ptr) {
253 | table[n-1] = table[n];
254 | }
255 | next_ptr--;
256 | return;
257 | }
258 | ptr = opaque; /* just to make some compilers happy */
259 | Assert(0, "zcfree: ptr not found");
260 | }
261 |
262 | #endif /* __TURBOC__ */
263 |
264 |
265 | #ifdef M_I86
266 | /* Microsoft C in 16-bit mode */
267 |
268 | # define MY_ZCALLOC
269 |
270 | #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
271 | # define _halloc halloc
272 | # define _hfree hfree
273 | #endif
274 |
275 | voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size)
276 | {
277 | if (opaque) opaque = 0; /* to make compiler happy */
278 | return _halloc((long)items, size);
279 | }
280 |
281 | void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr)
282 | {
283 | if (opaque) opaque = 0; /* to make compiler happy */
284 | _hfree(ptr);
285 | }
286 |
287 | #endif /* M_I86 */
288 |
289 | #endif /* SYS16BIT */
290 |
291 |
292 | #ifndef MY_ZCALLOC /* Any system without a special alloc function */
293 |
294 | #ifndef STDC
295 | extern voidp malloc OF((uInt size));
296 | extern voidp calloc OF((uInt items, uInt size));
297 | extern void free OF((voidpf ptr));
298 | #endif
299 |
300 | voidpf ZLIB_INTERNAL zcalloc (opaque, items, size)
301 | voidpf opaque;
302 | unsigned items;
303 | unsigned size;
304 | {
305 | if (opaque) items += size - size; /* make compiler happy */
306 | return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
307 | (voidpf)calloc(items, size);
308 | }
309 |
310 | void ZLIB_INTERNAL zcfree (opaque, ptr)
311 | voidpf opaque;
312 | voidpf ptr;
313 | {
314 | free(ptr);
315 | if (opaque) return; /* make compiler happy */
316 | }
317 |
318 | #endif /* MY_ZCALLOC */
319 |
--------------------------------------------------------------------------------
/src/wasm/build-assets/zlib/zutil.h:
--------------------------------------------------------------------------------
1 | /* zutil.h -- internal interface and configuration of the compression library
2 | * Copyright (C) 1995-2010 Jean-loup Gailly.
3 | * For conditions of distribution and use, see copyright notice in zlib.h
4 | */
5 |
6 | /* WARNING: this file should *not* be used by applications. It is
7 | part of the implementation of the compression library and is
8 | subject to change. Applications should only use zlib.h.
9 | */
10 |
11 | /* @(#) $Id$ */
12 |
13 | #ifndef ZUTIL_H
14 | #define ZUTIL_H
15 |
16 | #if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ)
17 | # define ZLIB_INTERNAL __attribute__((visibility ("hidden")))
18 | #else
19 | # define ZLIB_INTERNAL
20 | #endif
21 |
22 | #include "zlib.h"
23 |
24 | #ifdef STDC
25 | # if !(defined(_WIN32_WCE) && defined(_MSC_VER))
26 | # include
27 | # endif
28 | # include
29 | # include
30 | #endif
31 |
32 | #ifndef local
33 | # define local static
34 | #endif
35 | /* compile with -Dlocal if your debugger can't find static symbols */
36 |
37 | typedef unsigned char uch;
38 | typedef uch FAR uchf;
39 | typedef unsigned short ush;
40 | typedef ush FAR ushf;
41 | typedef unsigned long ulg;
42 |
43 | extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
44 | /* (size given to avoid silly warnings with Visual C++) */
45 |
46 | #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
47 |
48 | #define ERR_RETURN(strm,err) \
49 | return (strm->msg = (char*)ERR_MSG(err), (err))
50 | /* To be used only when the state is known to be valid */
51 |
52 | /* common constants */
53 |
54 | #ifndef DEF_WBITS
55 | # define DEF_WBITS MAX_WBITS
56 | #endif
57 | /* default windowBits for decompression. MAX_WBITS is for compression only */
58 |
59 | #if MAX_MEM_LEVEL >= 8
60 | # define DEF_MEM_LEVEL 8
61 | #else
62 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL
63 | #endif
64 | /* default memLevel */
65 |
66 | #define STORED_BLOCK 0
67 | #define STATIC_TREES 1
68 | #define DYN_TREES 2
69 | /* The three kinds of block type */
70 |
71 | #define MIN_MATCH 3
72 | #define MAX_MATCH 258
73 | /* The minimum and maximum match lengths */
74 |
75 | #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
76 |
77 | /* target dependencies */
78 |
79 | #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
80 | # define OS_CODE 0x00
81 | # if defined(__TURBOC__) || defined(__BORLANDC__)
82 | # if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
83 | /* Allow compilation with ANSI keywords only enabled */
84 | void _Cdecl farfree( void *block );
85 | void *_Cdecl farmalloc( unsigned long nbytes );
86 | # else
87 | # include
88 | # endif
89 | # else /* MSC or DJGPP */
90 | # include
91 | # endif
92 | #endif
93 |
94 | #ifdef AMIGA
95 | # define OS_CODE 0x01
96 | #endif
97 |
98 | #if defined(VAXC) || defined(VMS)
99 | # define OS_CODE 0x02
100 | # define F_OPEN(name, mode) \
101 | fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
102 | #endif
103 |
104 | #if defined(ATARI) || defined(atarist)
105 | # define OS_CODE 0x05
106 | #endif
107 |
108 | #ifdef OS2
109 | # define OS_CODE 0x06
110 | # ifdef M_I86
111 | # include
112 | # endif
113 | #endif
114 |
115 | #if defined(MACOS) || defined(TARGET_OS_MAC)
116 | # define OS_CODE 0x07
117 | # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
118 | # include /* for fdopen */
119 | # else
120 | # ifndef fdopen
121 | # define fdopen(fd,mode) NULL /* No fdopen() */
122 | # endif
123 | # endif
124 | #endif
125 |
126 | #ifdef TOPS20
127 | # define OS_CODE 0x0a
128 | #endif
129 |
130 | #ifdef WIN32
131 | # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
132 | # define OS_CODE 0x0b
133 | # endif
134 | #endif
135 |
136 | #ifdef __50SERIES /* Prime/PRIMOS */
137 | # define OS_CODE 0x0f
138 | #endif
139 |
140 | #if defined(_BEOS_) || defined(RISCOS)
141 | # define fdopen(fd,mode) NULL /* No fdopen() */
142 | #endif
143 |
144 | #if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX
145 | # if defined(_WIN32_WCE)
146 | # define fdopen(fd,mode) NULL /* No fdopen() */
147 | # ifndef _PTRDIFF_T_DEFINED
148 | typedef int ptrdiff_t;
149 | # define _PTRDIFF_T_DEFINED
150 | # endif
151 | # else
152 | # define fdopen(fd,type) _fdopen(fd,type)
153 | # endif
154 | #endif
155 |
156 | #if defined(__BORLANDC__)
157 | #pragma warn -8004
158 | #pragma warn -8008
159 | #pragma warn -8066
160 | #endif
161 |
162 | /* provide prototypes for these when building zlib without LFS */
163 | #if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0
164 | ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t));
165 | ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t));
166 | #endif
167 |
168 | /* common defaults */
169 |
170 | #ifndef OS_CODE
171 | # define OS_CODE 0x03 /* assume Unix */
172 | #endif
173 |
174 | #ifndef F_OPEN
175 | # define F_OPEN(name, mode) fopen((name), (mode))
176 | #endif
177 |
178 | /* functions */
179 |
180 | #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
181 | # ifndef HAVE_VSNPRINTF
182 | # define HAVE_VSNPRINTF
183 | # endif
184 | #endif
185 | #if defined(__CYGWIN__)
186 | # ifndef HAVE_VSNPRINTF
187 | # define HAVE_VSNPRINTF
188 | # endif
189 | #endif
190 | #ifndef HAVE_VSNPRINTF
191 | # ifdef MSDOS
192 | /* vsnprintf may exist on some MS-DOS compilers (DJGPP?),
193 | but for now we just assume it doesn't. */
194 | # define NO_vsnprintf
195 | # endif
196 | # ifdef __TURBOC__
197 | # define NO_vsnprintf
198 | # endif
199 | # ifdef WIN32
200 | /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */
201 | # if !defined(vsnprintf) && !defined(NO_vsnprintf)
202 | # if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 )
203 | # define vsnprintf _vsnprintf
204 | # endif
205 | # endif
206 | # endif
207 | # ifdef __SASC
208 | # define NO_vsnprintf
209 | # endif
210 | #endif
211 | #ifdef VMS
212 | # define NO_vsnprintf
213 | #endif
214 |
215 | #if defined(pyr)
216 | # define NO_MEMCPY
217 | #endif
218 | #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
219 | /* Use our own functions for small and medium model with MSC <= 5.0.
220 | * You may have to use the same strategy for Borland C (untested).
221 | * The __SC__ check is for Symantec.
222 | */
223 | # define NO_MEMCPY
224 | #endif
225 | #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
226 | # define HAVE_MEMCPY
227 | #endif
228 | #ifdef HAVE_MEMCPY
229 | # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
230 | # define zmemcpy _fmemcpy
231 | # define zmemcmp _fmemcmp
232 | # define zmemzero(dest, len) _fmemset(dest, 0, len)
233 | # else
234 | # define zmemcpy memcpy
235 | # define zmemcmp memcmp
236 | # define zmemzero(dest, len) memset(dest, 0, len)
237 | # endif
238 | #else
239 | void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
240 | int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
241 | void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len));
242 | #endif
243 |
244 | /* Diagnostic functions */
245 | #ifdef DEBUG
246 | # include
247 | extern int ZLIB_INTERNAL z_verbose;
248 | extern void ZLIB_INTERNAL z_error OF((char *m));
249 | # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
250 | # define Trace(x) {if (z_verbose>=0) fprintf x ;}
251 | # define Tracev(x) {if (z_verbose>0) fprintf x ;}
252 | # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
253 | # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
254 | # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
255 | #else
256 | # define Assert(cond,msg)
257 | # define Trace(x)
258 | # define Tracev(x)
259 | # define Tracevv(x)
260 | # define Tracec(c,x)
261 | # define Tracecv(c,x)
262 | #endif
263 |
264 |
265 | voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items,
266 | unsigned size));
267 | void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr));
268 |
269 | #define ZALLOC(strm, items, size) \
270 | (*((strm)->zalloc))((strm)->opaque, (items), (size))
271 | #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
272 | #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
273 |
274 | #endif /* ZUTIL_H */
275 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "ES2020",
4 | "allowJs": true,
5 | "checkJs": false,
6 | "allowSyntheticDefaultImports": true,
7 | "jsx": "react",
8 | "declaration": true,
9 | "declarationMap": false,
10 | "composite": true,
11 | "emitDeclarationOnly": true,
12 | "isolatedModules": true,
13 | "removeComments": false,
14 | "skipLibCheck": true,
15 | "strict": true,
16 | "noImplicitAny": false,
17 | "noUnusedLocals": false,
18 | "noUnusedParameters": false,
19 | "noImplicitReturns": true,
20 | "noFallthroughCasesInSwitch": true,
21 | "moduleResolution": "bundler",
22 | "esModuleInterop": false,
23 | "resolveJsonModule": true,
24 | "rootDir": "src",
25 | "declarationDir": "build-types",
26 | "outDir": "build-types",
27 | "baseUrl": ".",
28 | "lib": [
29 | "dom",
30 | "ESNext"
31 | ]
32 | },
33 | "include": [
34 | "src/**/*"
35 | ],
36 | "exclude": [
37 | "src/php-wasm/wasm-assets/**/*",
38 | "src/php-wasm/__tests__/*.ts",
39 | "build/**/*",
40 | "build-*/**/*",
41 | "build-types/**/*",
42 | "src/wasm/**/*"
43 | ]
44 | }
45 |
--------------------------------------------------------------------------------
/vite.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig } from 'vite'
2 | import react from '@vitejs/plugin-react'
3 |
4 | // https://vitejs.dev/config/
5 | export default defineConfig({
6 | server: {
7 | open: true,
8 | host: '127.0.0.1',
9 | port: 18888,
10 | },
11 | publicDir: 'assets',
12 | build: {
13 | outDir: 'public',
14 | assetsDir: '.'
15 | },
16 | plugins: [
17 | react(),
18 | ],
19 | })
20 |
--------------------------------------------------------------------------------
/vitest.config.js:
--------------------------------------------------------------------------------
1 | import { defineConfig, mergeConfig } from "vite";
2 | import react from '@vitejs/plugin-react'
3 | import ViteConfig from "./vite.config";
4 | import {configDefaults} from "vitest/config";
5 |
6 | // https://vitejs.dev/config/
7 | export default mergeConfig(ViteConfig, {
8 | test: {
9 | environmentMatchGlobs: [
10 | ['src/__test__/**.spec.ts', 'jsdom'],
11 | ['src/__test__/**.test.ts', 'node'],
12 | ],
13 | exclude: [...configDefaults.exclude, 'e2e/**',],
14 | },
15 | })
16 |
--------------------------------------------------------------------------------