File tree 2 files changed +12
-9
lines changed 2 files changed +12
-9
lines changed Original file line number Diff line number Diff line change @@ -539,6 +539,8 @@ private static function init(): void
539
539
typedef void (*FreeFn)(void* a);
540
540
void vips_value_set_blob (GValue* value,
541
541
FreeFn free_fn, void* data, size_t length);
542
+ void* vips_blob_copy (const void *data, size_t length);
543
+ void vips_area_unref (void *area);
542
544
543
545
const char* vips_value_get_ref_string (const GValue* value,
544
546
size_t* length);
@@ -760,8 +762,7 @@ private static function init(): void
760
762
761
763
VipsSource* vips_source_new_from_descriptor (int descriptor);
762
764
VipsSource* vips_source_new_from_file (const char* filename);
763
- VipsSource* vips_source_new_from_memory (const void* data,
764
- size_t size);
765
+ VipsSource* vips_source_new_from_blob (void* blob);
765
766
766
767
typedef struct _VipsSourceCustom {
767
768
VipsSource parent_object;
Original file line number Diff line number Diff line change @@ -64,17 +64,19 @@ public static function newFromFile(string $filename): self
64
64
*/
65
65
public static function newFromMemory (string $ data ): self
66
66
{
67
- # we need to set the memory to a copy of the data that vips_lib
68
- # can own and free
69
- $ n = strlen ($ data );
70
- $ memory = FFI ::vips ()->new ("char[ $ n] " , false , true );
71
- \FFI ::memcpy ($ memory , $ data , $ n );
72
- $ pointer = FFI ::vips ()->vips_source_new_from_memory ($ memory , $ n );
67
+ $ blob = FFI ::vips ()->vips_blob_copy ($ data , strlen ($ data ));
68
+ if ($ blob === null ) {
69
+ throw new Exception ("can't create source from memory " );
70
+ }
73
71
72
+ $ pointer = FFI ::vips ()->vips_source_new_from_blob ($ blob );
74
73
if ($ pointer === null ) {
74
+ FFI ::vips ()->vips_area_unref ($ blob );
75
75
throw new Exception ("can't create source from memory " );
76
76
}
77
77
78
- return new self ($ pointer );
78
+ $ source = new self ($ pointer );
79
+ FFI ::vips ()->vips_area_unref ($ blob );
80
+ return $ source ;
79
81
}
80
82
}
You can’t perform that action at this time.
0 commit comments