@@ -180,10 +180,10 @@ public static function shutDown(): void
180
180
181
181
public static function newGClosure (): \FFI \CData
182
182
{
183
- // GClosure measures 32-bit with the first few fields until marshal
184
- // Marshal is a function pointer, thus platform-dependant.
185
- // Data is a pointer, thus platform-dependant.
186
- // Notifiers is an array-pointer, thus platform-dependant.
183
+ // GClosure measures 32-bit with the first few fields until marshal.
184
+ // - Marshal is a function pointer, thus platform-dependant.
185
+ // - Data is a pointer, thus platform-dependant.
186
+ // - Notifiers is an array-pointer, thus platform-dependant.
187
187
// All in all it's basically 4 (bytes) + 3 * POINTER_SIZE
188
188
// However, gobject wants 8 (bytes) + 3 * POINTER_SIZE.
189
189
// I'm not sure where that extra byte comes from. Padding on 64-bit machines?
@@ -210,7 +210,7 @@ private static function libraryLoad(
210
210
array $ libraryPaths ,
211
211
string $ libraryName ,
212
212
string $ interface
213
- ): \FFI {
213
+ ): ? \FFI {
214
214
Utils::debugLog ("trying to open " , ["libraryName " => $ libraryName ]);
215
215
foreach ($ libraryPaths as $ path ) {
216
216
Utils::debugLog ("trying path " , ["path " => $ path ]);
@@ -225,6 +225,7 @@ private static function libraryLoad(
225
225
]);
226
226
}
227
227
}
228
+ return null ;
228
229
}
229
230
230
231
private static function init (): void
@@ -234,7 +235,7 @@ private static function init(): void
234
235
return ;
235
236
}
236
237
237
- // the two usual install problems
238
+ // the two usual installation problems
238
239
if (!extension_loaded ('ffi ' )) {
239
240
throw new Exception ('FFI extension not loaded ' );
240
241
}
@@ -267,16 +268,18 @@ private static function init(): void
267
268
$ libraryPaths [] = $ vipshome . "/lib/ " ;
268
269
}
269
270
270
- if (PHP_OS_FAMILY === "OSX " ||
271
- PHP_OS_FAMILY === "Darwin " ) {
272
- $ libraryPaths [] = "/opt/homebrew/lib/ " ; // Homebrew on Apple Silicon
271
+ if (PHP_OS_FAMILY === "OSX " || PHP_OS_FAMILY === "Darwin " ) {
272
+ // Homebrew on Apple Silicon
273
+ $ libraryPaths [] = "/opt/homebrew/lib/ " ;
274
+ // See https://github.com/Homebrew/brew/issues/13481#issuecomment-1207203483
275
+ $ libraryPaths [] = "/usr/local/lib/ " ;
273
276
}
274
277
275
- $ vips = self ::libraryLoad ($ libraryPaths , $ vips_libname , <<<EOS
278
+ $ vips = self ::libraryLoad ($ libraryPaths , $ vips_libname , <<<'CPP'
276
279
int vips_init (const char *argv0);
277
280
const char *vips_error_buffer (void);
278
281
int vips_version(int flag);
279
- EOS );
282
+ CPP );
280
283
281
284
if ($ vips === null ) {
282
285
// drop the "" (system path) member
@@ -313,19 +316,21 @@ private static function init(): void
313
316
"8.7 or later required " );
314
317
}
315
318
316
- // GType is the size of a pointer
317
- $ gtype = $ is_64bits ? "guint64 " : "guint32 " ;
318
-
319
319
// Typedefs shared across the libvips, GLib and GObject declarations
320
- $ typedefs = <<<EOS
320
+ $ typedefs = <<<'CPP'
321
321
// we need the glib names for these types
322
322
typedef uint32_t guint32;
323
323
typedef int32_t gint32;
324
324
typedef uint64_t guint64;
325
325
typedef int64_t gint64;
326
326
typedef void* gpointer;
327
327
328
- typedef $ gtype GType;
328
+ CPP;
329
+
330
+ // GType is the size of a pointer
331
+ $ typedefs .= 'typedef ' . ($ is_64bits ? 'guint64 ' : 'guint32 ' ) . ' GType; ' ;
332
+
333
+ $ typedefs .= <<<'CPP'
329
334
330
335
typedef struct _GData GData;
331
336
@@ -340,17 +345,17 @@ private static function init(): void
340
345
unsigned int ref_count;
341
346
GData *qdata;
342
347
} GObject;
343
- EOS ;
348
+ CPP ;
344
349
345
350
// GLib declarations
346
- $ glib_decls = $ typedefs . <<<EOS
351
+ $ glib_decls = $ typedefs . <<<'CPP'
347
352
void* g_malloc (size_t size);
348
353
void g_free (void* data);
349
354
void g_strfreev (char** str_array);
350
- EOS ;
355
+ CPP ;
351
356
352
357
// GObject declarations
353
- $ gobject_decls = $ typedefs . <<<EOS
358
+ $ gobject_decls = $ typedefs . <<<'CPP'
354
359
typedef struct _GValue {
355
360
GType g_type;
356
361
guint64 data[2];
@@ -467,10 +472,10 @@ private static function init(): void
467
472
void g_closure_set_marshal(GClosure* closure, marshaler marshal);
468
473
long g_signal_connect_closure(GObject* object, const char* detailed_signal, GClosure *closure, bool after);
469
474
GClosure* g_closure_new_simple (int sizeof_closure, void* data);
470
- EOS ;
475
+ CPP ;
471
476
472
477
# the whole libvips API, mostly adapted from pyvips
473
- $ vips_decls = $ typedefs . <<<EOS
478
+ $ vips_decls = $ typedefs . <<<'CPP'
474
479
typedef struct _VipsImage VipsImage;
475
480
typedef struct _VipsProgress VipsProgress;
476
481
@@ -696,10 +701,10 @@ private static function init(): void
696
701
697
702
int vips_object_get_args (VipsObject* object,
698
703
const char*** names, int** flags, int* n_args);
699
- EOS ;
704
+ CPP ;
700
705
701
706
if (self ::atLeast (8 , 8 )) {
702
- $ vips_decls = $ vips_decls . <<<EOS
707
+ $ vips_decls = $ vips_decls . <<<'CPP'
703
708
char** vips_foreign_get_suffixes (void);
704
709
705
710
void* vips_region_fetch (VipsRegion*, int, int, int, int,
@@ -708,11 +713,11 @@ private static function init(): void
708
713
int vips_region_height (VipsRegion*);
709
714
int vips_image_get_page_height (VipsImage*);
710
715
int vips_image_get_n_pages (VipsImage*);
711
- EOS ;
716
+ CPP ;
712
717
}
713
718
714
719
if (self ::atLeast (8 , 8 )) {
715
- $ vips_decls = $ vips_decls . <<<EOS
720
+ $ vips_decls = $ vips_decls . <<<'CPP'
716
721
typedef struct _VipsConnection {
717
722
VipsObject parent_object;
718
723
@@ -761,7 +766,7 @@ private static function init(): void
761
766
762
767
const char* vips_foreign_find_load_source (VipsSource *source);
763
768
const char* vips_foreign_find_save_target (const char* suffix);
764
- EOS ;
769
+ CPP ;
765
770
}
766
771
767
772
Utils::debugLog ("init " , ["binding ... " ]);
0 commit comments