cleanups before attempting gobject base

This commit is contained in:
John Cupitt 2011-06-18 17:47:56 +01:00
parent 4918a67e14
commit 863325a257
3 changed files with 32 additions and 6 deletions

View File

@ -3,10 +3,15 @@
import logging
import gc
import gobject
import vipsimage
logging.basicConfig(level = logging.DEBUG)
# should be able to find vipsimage, hopefully
print gobject.type_from_name('VipsImage')
# test unref
for i in range (1,10):
a = vipsimage.VipsImage('/home/john/pics/healthygirl.jpg')
@ -25,10 +30,17 @@ print 'xoffset =', a.xoffset()
print 'yoffset =', a.yoffset()
# should raise an error
# a = vipsimage.VipsImage('banana')
a = vipsimage.VipsImage('banana')
# try calling a vips8 method
a = vipsimage.VipsImage('/home/john/pics/healthygirl.jpg')
b = vipsimage.VipsImage('/home/john/pics/babe.jpg')
c = a.add(b)
print 'starting shutdown ...'
del a
del b
del c
# sometimes have to do several GCs to get them all, not sure why
for i in range(10):
gc.collect ()

View File

@ -101,6 +101,16 @@ vips_image_get_xres.restype = ctypes.c_double;
vips_image_get_yres = libvips.vips_image_get_yres
vips_image_get_yres.restype = ctypes.c_double;
vips_operation_new = libvips.vips_operation_new
vips_operation_new.argtypes = [ctypes.c_char_p]
vips_operation_new.restype = ctypes.c_void_p
vips_operation_new.errcheck = vipsobject.check_pointer_return
def vips_call_instance(self, name, args):
logging.debug('vipsimage: vips_call_instance name=%s, self=%s, args=%s' %
(name, self, args))
operation = vips_operation_new(name)
class VipsImage(vipsobject.VipsObject):
"""Manipulate a libvips image."""
@ -120,6 +130,10 @@ class VipsImage(vipsobject.VipsObject):
self.enable_finalize()
def __getattr__(self, name):
logging.debug('vipsimage: __getattr__ %s' % name)
return lambda *args: vips_call_instance(self, name, args)
def width(self):
return libvips.vips_image_get_width(self.vipsobject)

View File

@ -12,6 +12,8 @@ import logging
import sys
import ctypes
import gobject
import finalizable
# .15 is 7.25+ with the new vips8 API
@ -27,7 +29,7 @@ def class_value(classobject, value):
return 'unknown'
class Error(Exception):
class VipsError(Exception):
"""An error from libvips.
@ -48,12 +50,12 @@ class Error(Exception):
# handy checkers, assign to errcheck
def check_int_return(result, func, args):
if result != 0:
raise Error('Error calling vips function %s.' % func.__name__)
raise VipsError('Error calling vips function %s.' % func.__name__)
return result
def check_pointer_return(result, func, args):
if result == None:
raise Error('Error calling vips function %s.' % func.__name__)
raise VipsError('Error calling vips function %s.' % func.__name__)
return result
vips_error_buffer = libvips.vips_error_buffer
@ -80,5 +82,3 @@ class VipsObject(finalizable.Finalizable):
logging.debug('vipsobject: init')
self.vipsobject = None