8000 complete test suite passes cleanly · libvips/pyvips@1cc7f7f · GitHub
[go: up one dir, main page]

Skip to content

Commit 1cc7f7f

Browse files
committed
complete test suite passes cleanly
woo!
1 parent c81436e commit 1cc7f7f

File tree

4 files changed

+41
-25
lines changed

4 files changed

+41
-25
lines changed

README.rst

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,26 @@
55
pyvips experimental CFFI binding for libvips
66
--------------------------------------------
77

8+
Status
9+
------
10+
11+
This binding passes the vips test suite cleanly and with no leaks, so it should
12+
be OK to use. The docs still need updating, and it could use a little polish.
13+
14+
To convert old code, replace the lines::
15+
16+
import gi
17+
gi.require_version('Vips', '8.0')
18+
from gi.repository import Vips
19+
20+
with::
21+
22+
import pyvips
23+
Vips = pyvips
24+
25+
Background
26+
----------
27+
828
This is supposed to be an experiment with making a libvips binding using cffi.
929

1030
http://cffi.readthedocs.io/en/latest/ref.html
@@ -50,17 +70,3 @@ Run test suite::
5070

5171
$ nosetests |& more
5272
$ nosetests --logging-level=WARNING
53-
54-
Converting old code
55-
-------------------
56-
57-
Replace the lines::
58-
59-
import gi
60-
gi.require_version('Vips', '8.0')
61-
from gi.repository import Vips
62-
63-
with::
64-
65-
import pyvips
66-
Vips = pyvips

pyvips/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
void vips_error_clear (void);
3939
4040
int vips_init (const char* argv0);
41+
void vips_shutdown (void);
4142
4243
typedef struct _VipsImage VipsImage;
4344
typedef struct _GValue GValue;
@@ -75,14 +76,13 @@ def __str__(self):
7576
if vips_lib.vips_init(sys.argv[0]) != 0:
7677
raise Error('unable to init Vips')
7778

79+
def shutdown():
80+
logger.debug('Shutting down libvips')
81+
vips_lib.vips_shutdown()
82+
7883
logger.debug('Inited libvips')
7984
logger.debug('')
8085

81-
# a callback that triggers g_free()
82-
@ffi.callback('void(void*)')
83-
def g_free_callback(ptr):
84-
gobject_lib.g_free(ptr)
85-
8686
def leak_set(leak):
8787
return vips_lib.vips_leak_set(leak)
8888

@@ -95,5 +95,5 @@ def path_filename7(filename):
9595
def path_mode7(filename):
9696
return ffi.string(vips_lib.vips_path_mode7(filename))
9797

98-
__all__ = ['ffi', 'g_free_callback', 'vips_lib', 'gobject_lib', 'Error',
99-
'leak_set', 'type_find', 'path_filename7', 'path_mode7']
98+
__all__ = ['ffi', 'vips_lib', 'gobject_lib', 'Error', 'leak_set', 'type_find',
99+
'path_filename7', 'path_mode7', 'shutdown']

pyvips/gvalue.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@
6262
6363
''')
6464

65+
# a callback that triggers g_free()
66+
@ffi.callback('void(void*)')
67+
def my_callback(ptr):
68+
print 'hello!!'
69+
print 'free_callback: freeing {0}'.format(ptr)
70+
71+
gobject_lib.g_free(ptr)
72+
6573
class GValue(object):
6674

6775
# look up some common gtypes at init for speed
@@ -151,7 +159,7 @@ def set(self, value):
151159
ffi.memmove(memory, value, len(value))
152160

153161
vips_lib.vips_value_set_blob(self.gvalue,
154-
g_free_callback, memory, len(value))
162+
gobject_lib.g_free, memory, len(value))
155163
else:
156164
raise Error('unsupported gtype for set {0}, fundamental {1}'.
157165
format(GValue.type_name(gtype),

pyvips/tests/test_foreign.py

Lines changed: 5 additions & 3 deletions
126
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,13 @@ def jpeg_valid(self, im):
119119
self.assertEqual(im.bands, 3)
120120

121121
self.file_loader("jpegload", JPEG_FILE, jpeg_valid)
122-
self.buffer_loader("jpegload_buffer", JPEG_FILE, jpeg_valid)
123-
self.save_load_buffer("jpegsave_buffer", "jpegload_buffer", self.colour,
124-
80)
125122
self.save_load("%s.jpg", self.mono)
126123
self.save_load("%s.jpg", self.colour)
127124

125+
self.buffer_loader("jpegload_buffer", JPEG_FILE, jpeg_valid)
+
self.save_load_buffer("jpegsave_buffer", "jpegload_buffer",
127+
self.colour, 80)
128+
128129
# see if we have exif parsing: our test image has this field
129130
x = pyvips.Image.new_from_file(JPEG_FILE)
130131
if x.get_typeof("exif-ifd0-Orientation") != 0:
@@ -172,6 +173,7 @@ def jpeg_valid(self, im):
172173
self.assertEqual(x1.height, x2.width)
173174
os.unlink(filename)
174175

176+
175177
def test_png(self):
176178
if pyvips.type_find("VipsForeign", "pngload") == 0:
177179
print("no png support in this vips, skipping test")

0 commit comments

Comments
 (0)
0