1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
|
From be799d73a50fba84803a5640f897d71769886860 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Subject: [PATCH] SDL is required
---
package.xml | 8 +++++++-
src/php_sdl_mixer.c | 9 ++++++++-
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/src/php_sdl_mixer.c b/src/php_sdl_mixer.c
index a8a0325..ef58d05 100644
--- a/src/php_sdl_mixer.c
+++ b/src/php_sdl_mixer.c
@@ -41,8 +41,15 @@ PHP_MINFO_FUNCTION(sdl_mixer)
php_info_print_table_end();
}
+static const zend_module_dep ext_deps[] = {
+ ZEND_MOD_REQUIRED("sdl")
+ ZEND_MOD_END
+};
+
zend_module_entry sdl_mixer_module_entry = {
- STANDARD_MODULE_HEADER,
+ STANDARD_MODULE_HEADER_EX,
+ NULL,
+ ext_deps,
"SDL_mixer",
ext_functions,
PHP_MINIT(sdl_mixer),
From 6e4308959dae7179beb9422797e7fb637c62b919 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Sun, 13 Mar 2022 08:12:37 +0100
Subject: [PATCH] check if Mix_HasMusicDecoder is available
---
config.m4 | 4 ++++
src/music.c | 2 ++
src/php_sdl_mixer.stub.php | 7 ++++++-
src/php_sdl_mixer_arginfo.h | 12 ++++++++++--
4 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/config.m4 b/config.m4
index a70426e..2468383 100644
--- a/config.m4
+++ b/config.m4
@@ -30,6 +30,10 @@ if test "$PHP_SDL_MIXER" != "no"; then
AC_MSG_ERROR([libSDL2_mixer not found!])
])
+ AC_CHECK_LIB(SDL2_mixer, Mix_HasMusicDecoder, [
+ AC_DEFINE(HAVE_MIX_HASMUSICDECODER, 1, [ Have sdl_mixer support ])
+ ])
+
AC_DEFINE(HAVE_SDL_MIXER, 1, [ Have sdl_mixer support ])
PHP_SUBST(SDL_MIXER_SHARED_LIBADD)
diff --git a/src/music.c b/src/music.c
index 7f4c178..122dffe 100644
--- a/src/music.c
+++ b/src/music.c
@@ -83,6 +83,7 @@ PHP_FUNCTION(Mix_GetMusicDecoder)
RETURN_STRING(result);
}
+#if defined(HAVE_MIX_HASMUSICDECODER)
PHP_FUNCTION(Mix_HasMusicDecoder)
{
char *name = NULL;
@@ -96,6 +97,7 @@ PHP_FUNCTION(Mix_HasMusicDecoder)
RETURN_BOOL(result == SDL_TRUE);
}
+#endif
PHP_FUNCTION(Mix_PlayMusic)
{
diff --git a/src/php_sdl_mixer.stub.php b/src/php_sdl_mixer.stub.php
index c73689c..0ceef5e 100644
--- a/src/php_sdl_mixer.stub.php
+++ b/src/php_sdl_mixer.stub.php
@@ -1,6 +1,9 @@
<?php
-/** @generate-class-entries */
+/**
+ * @generate-function-entries
+ * @generate-class-entries
+ */
function Mix_Init(int $flags): int {}
function Mix_Quit(): void {}
@@ -42,7 +45,9 @@ function Mix_LoadMUS_RW(SDL_RWops $src, int $freesrc): Mix_Music {}
function Mix_FreeMusic(Mix_Music $music): void {}
function Mix_GetNumMusicDecoders(): int {}
function Mix_GetMusicDecoder(int $index): string {}
+#ifdef HAVE_MIX_HASMUSICDECODER
function Mix_HasMusicDecoder(string $name): bool {}
+#endif
function Mix_PlayMusic(Mix_Music $music, int $loops): int {}
function Mix_FadeInMusic(Mix_Music $music, int $loops, int $ms): int {}
function Mix_FadeInMusicPos(Mix_Music $music, int $loops, int $ms, float $position): int {}
diff --git a/src/php_sdl_mixer_arginfo.h b/src/php_sdl_mixer_arginfo.h
index 848f81a..696df72 100644
--- a/src/php_sdl_mixer_arginfo.h
+++ b/src/php_sdl_mixer_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 1a36e3ed90a9a7c0ff05a89516ad4bcec0ef0d44 */
+ * Stub hash: 0dec727e1d30954b0817f144d4e81e938a9f2d3c */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Mix_Init, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
@@ -168,7 +168,11 @@ ZEND_END_ARG_INFO()
#define arginfo_Mix_GetMusicDecoder arginfo_Mix_GetChunkDecoder
-#define arginfo_Mix_HasMusicDecoder arginfo_Mix_HasChunkDecoder
+#if defined(HAVE_MIX_HASMUSICDECODER)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Mix_HasMusicDecoder, 0, 1, _IS_BOOL, 0)
+ ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+#endif
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Mix_PlayMusic, 0, 2, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, music, Mix_Music, 0)
@@ -292,7 +296,9 @@ ZEND_FUNCTION(Mix_LoadMUS_RW);
ZEND_FUNCTION(Mix_FreeMusic);
ZEND_FUNCTION(Mix_GetNumMusicDecoders);
ZEND_FUNCTION(Mix_GetMusicDecoder);
+#if defined(HAVE_MIX_HASMUSICDECODER)
ZEND_FUNCTION(Mix_HasMusicDecoder);
+#endif
ZEND_FUNCTION(Mix_PlayMusic);
ZEND_FUNCTION(Mix_FadeInMusic);
ZEND_FUNCTION(Mix_FadeInMusicPos);
@@ -359,7 +365,9 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(Mix_FreeMusic, arginfo_Mix_FreeMusic)
ZEND_FE(Mix_GetNumMusicDecoders, arginfo_Mix_GetNumMusicDecoders)
ZEND_FE(Mix_GetMusicDecoder, arginfo_Mix_GetMusicDecoder)
+#if defined(HAVE_MIX_HASMUSICDECODER)
ZEND_FE(Mix_HasMusicDecoder, arginfo_Mix_HasMusicDecoder)
+#endif
ZEND_FE(Mix_PlayMusic, arginfo_Mix_PlayMusic)
ZEND_FE(Mix_FadeInMusic, arginfo_Mix_FadeInMusic)
ZEND_FE(Mix_FadeInMusicPos, arginfo_Mix_FadeInMusicPos)
From 076920930c3cc6b2f347d9f5c860412ced13938d Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Mon, 14 Mar 2022 10:11:00 +0100
Subject: [PATCH 1/2] split stub and arginfo
---
package.xml | 4 ++++
src/Mix_Chunk.c | 1 +
src/Mix_Chunk.stub.php | 8 ++++++++
src/Mix_Chunk_arginfo.h | 20 ++++++++++++++++++++
src/Mix_Music.c | 1 +
src/Mix_Music.stub.php | 8 ++++++++
src/Mix_Music_arginfo.h | 20 ++++++++++++++++++++
src/mixer.c | 5 +----
src/php_sdl_mixer.c | 1 +
src/php_sdl_mixer.h | 1 -
src/php_sdl_mixer.stub.php | 2 --
src/php_sdl_mixer_arginfo.h | 34 +---------------------------------
12 files changed, 65 insertions(+), 40 deletions(-)
create mode 100644 src/Mix_Chunk.stub.php
create mode 100644 src/Mix_Chunk_arginfo.h
create mode 100644 src/Mix_Music.stub.php
create mode 100644 src/Mix_Music_arginfo.h
diff --git a/src/Mix_Chunk.c b/src/Mix_Chunk.c
index 014108c..6fa1a5b 100644
--- a/src/Mix_Chunk.c
+++ b/src/Mix_Chunk.c
@@ -1,4 +1,5 @@
#include "Mix_Chunk.h"
+#include "Mix_Chunk_arginfo.h"
zend_class_entry *mix_chunk_ce = NULL;
zend_object_handlers php_mix_chunk_object_handlers;
diff --git a/src/Mix_Chunk.stub.php b/src/Mix_Chunk.stub.php
new file mode 100644
index 0000000..7814a12
--- /dev/null
+++ b/src/Mix_Chunk.stub.php
@@ -0,0 +1,8 @@
+<?php
+
+/**
+ * @generate-class-entries
+ */
+
+final class Mix_Chunk {}
+
diff --git a/src/Mix_Chunk_arginfo.h b/src/Mix_Chunk_arginfo.h
new file mode 100644
index 0000000..4ba7331
--- /dev/null
+++ b/src/Mix_Chunk_arginfo.h
@@ -0,0 +1,20 @@
+/* This is a generated file, edit the .stub.php file instead.
+ * Stub hash: 4d3739c322fe06235f1b4d21c5ad9a8b3bf45f02 */
+
+
+
+
+static const zend_function_entry class_Mix_Chunk_methods[] = {
+ ZEND_FE_END
+};
+
+static zend_class_entry *register_class_Mix_Chunk(void)
+{
+ zend_class_entry ce, *class_entry;
+
+ INIT_CLASS_ENTRY(ce, "Mix_Chunk", class_Mix_Chunk_methods);
+ class_entry = zend_register_internal_class_ex(&ce, NULL);
+ class_entry->ce_flags |= ZEND_ACC_FINAL;
+
+ return class_entry;
+}
diff --git a/src/Mix_Music.c b/src/Mix_Music.c
index 3c1e3f5..1030404 100644
--- a/src/Mix_Music.c
+++ b/src/Mix_Music.c
@@ -1,4 +1,5 @@
#include "Mix_Music.h"
+#include "Mix_Music_arginfo.h"
zend_class_entry *mix_music_ce = NULL;
zend_object_handlers php_mix_music_object_handlers;
diff --git a/src/Mix_Music.stub.php b/src/Mix_Music.stub.php
new file mode 100644
index 0000000..e1b56cc
--- /dev/null
+++ b/src/Mix_Music.stub.php
@@ -0,0 +1,8 @@
+<?php
+
+/**
+ * @generate-class-entries
+ */
+
+final class Mix_Music {}
+
diff --git a/src/Mix_Music_arginfo.h b/src/Mix_Music_arginfo.h
new file mode 100644
index 0000000..c0fb1e9
--- /dev/null
+++ b/src/Mix_Music_arginfo.h
@@ -0,0 +1,20 @@
+/* This is a generated file, edit the .stub.php file instead.
+ * Stub hash: c6b5d170cc55f739aa2b0cb08eae7d8d2bb45404 */
+
+
+
+
+static const zend_function_entry class_Mix_Music_methods[] = {
+ ZEND_FE_END
+};
+
+static zend_class_entry *register_class_Mix_Music(void)
+{
+ zend_class_entry ce, *class_entry;
+
+ INIT_CLASS_ENTRY(ce, "Mix_Music", class_Mix_Music_methods);
+ class_entry = zend_register_internal_class_ex(&ce, NULL);
+ class_entry->ce_flags |= ZEND_ACC_FINAL;
+
+ return class_entry;
+}
diff --git a/src/mixer.c b/src/mixer.c
index c976351..7c5d69b 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -4,9 +4,6 @@
#include "mixer.h"
-static zend_class_entry *php_mix_chunk_ce;
-static zend_object_handlers php_mix_chunk_handlers;
-
extern zend_class_entry *mix_chunk_ce;
extern zend_class_entry *get_php_sdl_rwops_ce(void);
extern SDL_RWops *zval_to_sdl_rwops(zval *z_val);
@@ -549,4 +546,4 @@ PHP_FUNCTION(Mix_GetError) {
if (error) {
RETURN_STRING(error);
}
-}
\ No newline at end of file
+}
diff --git a/src/php_sdl_mixer.c b/src/php_sdl_mixer.c
index ef58d05..4707e04 100644
--- a/src/php_sdl_mixer.c
+++ b/src/php_sdl_mixer.c
@@ -1,6 +1,7 @@
#include "php_sdl_mixer.h"
#include "mixer.h"
#include "music.h"
+#include "php_sdl_mixer_arginfo.h"
#ifdef COMPILE_DL_SDL_MIXER
ZEND_GET_MODULE(sdl_mixer)
diff --git a/src/php_sdl_mixer.h b/src/php_sdl_mixer.h
index eddf015..c909d33 100644
--- a/src/php_sdl_mixer.h
+++ b/src/php_sdl_mixer.h
@@ -23,7 +23,6 @@ extern "C" {
#include <php.h>
#include <ext/standard/info.h>
#include "SDL_mixer.h"
-#include "php_sdl_mixer_arginfo.h"
#ifdef __cplusplus
} // extern "C"
diff --git a/src/php_sdl_mixer.stub.php b/src/php_sdl_mixer.stub.php
index 0ceef5e..05e5596 100644
--- a/src/php_sdl_mixer.stub.php
+++ b/src/php_sdl_mixer.stub.php
@@ -76,5 +76,3 @@ function Mix_GetError(): string {}
/** @alias SDL_ClearError */
function Mix_ClearError(): string {}
-final class Mix_Chunk {}
-final class Mix_Music {}
diff --git a/src/php_sdl_mixer_arginfo.h b/src/php_sdl_mixer_arginfo.h
index 696df72..5af4cbc 100644
--- a/src/php_sdl_mixer_arginfo.h
+++ b/src/php_sdl_mixer_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 0dec727e1d30954b0817f144d4e81e938a9f2d3c */
+ * Stub hash: 06f9569d612687e9fe0e904dcce9ebd88f9e6997 */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_Mix_Init, 0, 1, IS_LONG, 0)
ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0)
@@ -393,35 +393,3 @@ static const zend_function_entry ext_functions[] = {
ZEND_FALIAS(Mix_ClearError, SDL_ClearError, arginfo_Mix_ClearError)
ZEND_FE_END
};
-
-
-static const zend_function_entry class_Mix_Chunk_methods[] = {
- ZEND_FE_END
-};
-
-
-static const zend_function_entry class_Mix_Music_methods[] = {
- ZEND_FE_END
-};
-
-static zend_class_entry *register_class_Mix_Chunk(void)
-{
- zend_class_entry ce, *class_entry;
-
- INIT_CLASS_ENTRY(ce, "Mix_Chunk", class_Mix_Chunk_methods);
- class_entry = zend_register_internal_class_ex(&ce, NULL);
- class_entry->ce_flags |= ZEND_ACC_FINAL;
-
- return class_entry;
-}
-
-static zend_class_entry *register_class_Mix_Music(void)
-{
- zend_class_entry ce, *class_entry;
-
- INIT_CLASS_ENTRY(ce, "Mix_Music", class_Mix_Music_methods);
- class_entry = zend_register_internal_class_ex(&ce, NULL);
- class_entry->ce_flags |= ZEND_ACC_FINAL;
-
- return class_entry;
-}
From 159a86fb28f2f51da09d9ac7b378095aa23c3326 Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Mon, 14 Mar 2022 11:14:39 +0100
Subject: [PATCH 2/2] properly init/quit sdl_mixer library
---
src/php_sdl_mixer.c | 39 ++++++++++++++++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/src/php_sdl_mixer.c b/src/php_sdl_mixer.c
index 4707e04..9e5d7f8 100644
--- a/src/php_sdl_mixer.c
+++ b/src/php_sdl_mixer.c
@@ -2,6 +2,7 @@
#include "mixer.h"
#include "music.h"
#include "php_sdl_mixer_arginfo.h"
+#include "zend_smart_string.h"
#ifdef COMPILE_DL_SDL_MIXER
ZEND_GET_MODULE(sdl_mixer)
@@ -9,9 +10,13 @@ ZEND_GET_MODULE(sdl_mixer)
#define PHP_MINIT_CALL(func) PHP_MINIT(func)(INIT_FUNC_ARGS_PASSTHRU)
+static int sld_mixer_flags;
+
/* {{{ PHP_MINIT_FUNCTION */
PHP_MINIT_FUNCTION(sdl_mixer)
{
+ sld_mixer_flags = Mix_Init(MIX_INIT_FLAC|MIX_INIT_MOD|MIX_INIT_MP3|MIX_INIT_OGG|MIX_INIT_MID|MIX_INIT_OPUS);
+
php_mix_chunk_minit_helper();
php_mix_music_minit_helper();
@@ -25,9 +30,19 @@ PHP_MINIT_FUNCTION(sdl_mixer)
}
/* }}} */
+/* {{{ PHP_MINIT_FUNCTION */
+PHP_MSHUTDOWN_FUNCTION(sdl_mixer)
+{
+ Mix_Quit();
+
+ return SUCCESS;
+}
+/* }}} */
+
PHP_MINFO_FUNCTION(sdl_mixer)
{
char buffer[128];
+ smart_string info = {0};
SDL_version compile_version;
const SDL_version *link_version = Mix_Linked_Version();
SDL_MIXER_VERSION(&compile_version);
@@ -39,6 +54,28 @@ PHP_MINFO_FUNCTION(sdl_mixer)
php_info_print_table_row(2, "SDL_mixer linked version", buffer);
snprintf(buffer, sizeof(buffer), "%d.%d.%d", compile_version.major, compile_version.minor, compile_version.patch);
php_info_print_table_row(2, "SDL_mixer compiled version", buffer);
+ if (sld_mixer_flags & MIX_INIT_FLAC) {
+ smart_string_appends(&info, "flac");
+ }
+ if (sld_mixer_flags & MIX_INIT_MOD) {
+ smart_string_appends(&info, ", mod");
+ }
+ if (sld_mixer_flags & MIX_INIT_MP3) {
+ smart_string_appends(&info, ", mp3");
+ }
+ if (sld_mixer_flags & MIX_INIT_OGG) {
+ smart_string_appends(&info, ", ogg");
+ }
+ if (sld_mixer_flags & MIX_INIT_MID) {
+ smart_string_appends(&info, ", mid");
+ }
+ if (sld_mixer_flags & MIX_INIT_OPUS) {
+ smart_string_appends(&info, ", opus");
+ }
+ smart_string_0(&info);
+ php_info_print_table_row(2, "SDL_mixer flags", info.c);
+ smart_string_free(&info);
+
php_info_print_table_end();
}
@@ -54,7 +91,7 @@ zend_module_entry sdl_mixer_module_entry = {
"SDL_mixer",
ext_functions,
PHP_MINIT(sdl_mixer),
- NULL, /* PHP_MSHUTDOWN - Module shutdown */
+ PHP_MSHUTDOWN(sdl_mixer),
NULL, /* PHP_RINIT - Request initialization */
NULL, /* PHP_RSHUTDOWN - Request shutdown */
PHP_MINFO(sdl_mixer),
|