Skip to content

Commit

Permalink
Merge branch '229_win_fdopen' into im-7
Browse files Browse the repository at this point in the history
  • Loading branch information
justinfx committed Jul 16, 2023
2 parents a434deb + b953ce4 commit dd6a254
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
39 changes: 38 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:

jobs:
test:
name: Test ImageMagick7
name: Test ImageMagick7 linux
runs-on: ubuntu-latest
environment: imagemagick7
env:
Expand All @@ -31,3 +31,40 @@ jobs:
-v $PWD/.cache/go-build:/root/.cache/go-build \
-v $PWD/.cache/go/pkg:/go/pkg \
"$DOCKER_IMAGE"
test_windows:
name: Test ImageMagick7 windows
runs-on: windows-latest
steps:
- name: Checkout
uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup go
uses: actions/[email protected]
with:
go-version: 1.20.6

- name: Setup MSYS2
uses: msys2/setup-msys2@v2
with:
update: true
install: >-
base-devel
mingw-w64-x86_64-toolchain
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-imagemagick
- name: Install deps
shell: msys2 {0}
run: |
/c/hostedtoolcache/windows/go/1.20.6/x64/bin/go.exe env
pkg-config --cflags --libs MagickWand
MAGICK_CONFIGURE_PATH=/d/a/_temp/msys/msys64/mingw64/etc/ImageMagick-7 convert -list configure
- name: Test
shell: msys2 {0}
run: >
MAGICK_CONFIGURE_PATH=/d/a/_temp/msys/msys64/mingw64/etc/ImageMagick-7
/c/hostedtoolcache/windows/go/1.20.6/x64/bin/go.exe test -v ./imagick
10 changes: 8 additions & 2 deletions imagick/magick_wand_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -2946,11 +2946,17 @@ func (mw *MagickWand) WriteImagesFile(out *os.File) error {
// cfdopen returns a C-level FILE*. mode should be as described in fdopen(3).
// Caller is responsible for closing the file when successfully returned,
// via C.fclose()
func cfdopen(file *os.File, mode string) (*C.FILE, error) {
func cfdopen(file *os.File, mode string) (cfile *C.FILE, err error) {
cname := C.CString(file.Name())
cmode := C.CString(mode)
defer C.free(unsafe.Pointer(cname))
defer C.free(unsafe.Pointer(cmode))

cfile, err := C.fdopen(C.dup(C.int(file.Fd())), cmode)
if file.Name() != "" {
cfile, err = C.fopen(cname, cmode)
} else {
cfile, err = C.fdopen(C.dup(C.int(file.Fd())), cmode)
}
if err != nil {
return nil, err
}
Expand Down
29 changes: 29 additions & 0 deletions imagick/magick_wand_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package imagick

import (
"fmt"
"io/ioutil"
"os"
"reflect"
"runtime"
"sync/atomic"
Expand Down Expand Up @@ -177,6 +179,33 @@ func TestImageChannelMask(t *testing.T) {
}
}

func TestReadImageFile(t *testing.T) {
Initialize()
defer Terminate()

mw := NewMagickWand()
if err := mw.ReadImage(`logo:`); err != nil {
t.Fatal(err)
}

tmp, err := ioutil.TempFile("", "imagick_test-*.jpg")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmp.Name())

if err := mw.WriteImage(tmp.Name()); err != nil {
t.Fatal(err)
}
mw.Destroy()

mw = NewMagickWand()
defer mw.Destroy()
if err := mw.ReadImageFile(tmp); err != nil {
t.Fatal(err)
}
}

func TestReadImageBlob(t *testing.T) {
Initialize()
defer func(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions imagick/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ func relinquishMemory(ptr unsafe.Pointer) {

// relinquishes memory resources, null terminated array of strings
func relinquishMemoryCStringArray(p **C.char) {
if p == nil {
return
}
defer relinquishMemory(unsafe.Pointer(p))
for *p != nil {
relinquishMemory(unsafe.Pointer(*p))
Expand Down

0 comments on commit dd6a254

Please sign in to comment.