瀏覽代碼

vips_error_go

Viktor Sokolov 3 月之前
父節點
當前提交
7561b1bb51
共有 4 個文件被更改,包括 17 次插入12 次删除
  1. 2 12
      vips/source.c
  2. 7 0
      vips/source.go
  3. 6 0
      vips/vips.c
  4. 2 0
      vips/vips.h

+ 2 - 12
vips/source.c

@@ -21,11 +21,7 @@ vips_imgproxy_source_read(VipsSource *source, void *buffer, size_t length)
 {
   VipsImgproxySource *self = (VipsImgproxySource *) source;
 
-  gint64 read_length = imgproxyReaderRead(self->readerHandle, buffer, length);
-  if (read_length < 0) {
-    vips_error("vips_imgproxy_source_read", "failed to read from imgproxy source");
-  }
-  return read_length;
+  return imgproxyReaderRead(self->readerHandle, buffer, length);
 }
 
 // seek function for vips imgproxy source. whence can be SEEK_SET (0), SEEK_CUR (1), or SEEK_END (2).
@@ -34,13 +30,7 @@ vips_imgproxy_source_seek(VipsSource *source, gint64 offset, int whence)
 {
   VipsImgproxySource *self = (VipsImgproxySource *) source;
 
-  gint64 actual_offset = imgproxyReaderSeek(self->readerHandle, offset, whence);
-
-  if (actual_offset < 0) {
-    vips_error("vips_imgproxy_source_seek", "failed to seek in imgproxy source");
-  }
-
-  return actual_offset;
+  return imgproxyReaderSeek(self->readerHandle, offset, whence);
 }
 
 static void

+ 7 - 0
vips/source.go

@@ -5,9 +5,11 @@ package vips
 #cgo CFLAGS: -O3
 #cgo LDFLAGS: -lm
 #include "source.h"
+#include "vips.h"
 */
 import "C"
 import (
+	"fmt"
 	"io"
 	"runtime/cgo"
 	"unsafe"
@@ -26,11 +28,13 @@ func imgproxyReaderSeek(handle C.uintptr_t, offset C.int64_t, whence int) C.int6
 	h := cgo.Handle(handle)
 	reader, ok := h.Value().(io.ReadSeeker)
 	if !ok {
+		C.vips_error_go(cachedCString("imgproxyReaderSeek"), cachedCString("failed to cast handle to io.ReadSeeker"))
 		return -1
 	}
 
 	pos, err := reader.Seek(int64(offset), whence)
 	if err != nil {
+		C.vips_error_go(cachedCString("imgproxyReaderSeek"), cachedCString("failed to seek"))
 		return -1
 	}
 
@@ -44,6 +48,7 @@ func imgproxyReaderRead(handle C.uintptr_t, pointer unsafe.Pointer, size C.int64
 	h := cgo.Handle(handle)
 	reader, ok := h.Value().(io.ReadSeeker)
 	if !ok {
+		C.vips_error_go(cachedCString("imgproxyReaderRead"), cachedCString("invalid reader handle"))
 		return -1
 	}
 
@@ -52,6 +57,8 @@ func imgproxyReaderRead(handle C.uintptr_t, pointer unsafe.Pointer, size C.int64
 	if err == io.EOF {
 		return 0
 	} else if err != nil {
+		msg := fmt.Sprintf("error reading from imgproxy source: %v", err)
+		C.vips_error_go(cachedCString("imgproxyReaderRead"), cachedCString(msg))
 		return -1
 	}
 

+ 6 - 0
vips/vips.c

@@ -1118,3 +1118,9 @@ vips_cleanup()
   vips_error_clear();
   vips_thread_shutdown();
 }
+
+void
+vips_error_go(const char *function, const char *message)
+{
+  vips_error(function, "%s", message);
+}

+ 2 - 0
vips/vips.h

@@ -101,3 +101,5 @@ int vips_avifsave_go(VipsImage *in, void **buf, size_t *len, int quality, int sp
 int vips_tiffsave_go(VipsImage *in, void **buf, size_t *len, int quality);
 
 void vips_cleanup();
+
+void vips_error_go(const char *function, const char *message);