more more stuff to vips_

window, memory, buffer, b64 all moved to the vips_ namespace
This commit is contained in:
John Cupitt 2011-03-25 14:01:12 +00:00
parent 56840af97d
commit 842d2e1b16
20 changed files with 235 additions and 224 deletions

View File

@ -190,6 +190,9 @@ struct im_col_tab_disp *im_col_make_tables_RGB( VipsImage *im,
struct im_col_display *d ); struct im_col_display *d );
struct im_col_tab_disp *im_col_display_get_table( struct im_col_display *d ); struct im_col_tab_disp *im_col_display_get_table( struct im_col_display *d );
char *vips__b64_encode( const unsigned char *data, size_t data_length );
unsigned char *vips__b64_decode( const char *buffer, size_t *data_length );
void *vips__mmap( int fd, int writeable, size_t length, gint64 offset ); void *vips__mmap( int fd, int writeable, size_t length, gint64 offset );
int vips__munmap( void *start, size_t length ); int vips__munmap( void *start, size_t length );
int vips_mapfile( VipsImage * ); int vips_mapfile( VipsImage * );

View File

@ -45,12 +45,12 @@ G_STMT_START { \
} G_STMT_END } G_STMT_END
/* Can't just use VIPS_FREEF(), we want the extra cast to void on the argument /* Can't just use VIPS_FREEF(), we want the extra cast to void on the argument
* to im_free() to make sure we can work for "const char *" variables. * to vips_free() to make sure we can work for "const char *" variables.
*/ */
#define VIPS_FREE( S ) \ #define VIPS_FREE( S ) \
G_STMT_START { \ G_STMT_START { \
if( S ) { \ if( S ) { \
(void) im_free( (void *) (S) ); \ (void) vips_free( (void *) (S) ); \
(S) = 0; \ (S) = 0; \
} \ } \
} G_STMT_END } G_STMT_END
@ -63,17 +63,18 @@ G_STMT_START { \
if( !(S) || !sst || strcmp( (S), sst ) != 0 ) { \ if( !(S) || !sst || strcmp( (S), sst ) != 0 ) { \
VIPS_FREE( S ); \ VIPS_FREE( S ); \
if( sst ) \ if( sst ) \
(S) = im_strdup( NULL, sst ); \ (S) = vips_strdup( NULL, sst ); \
} \ } \
} \ } \
} G_STMT_END } G_STMT_END
#define VIPS_NEW( IM, T ) ((T *) im_malloc( (IM), sizeof( T ))) #define VIPS_NEW( IM, T ) ((T *) vips_malloc( (IM), sizeof( T )))
#define VIPS_ARRAY( IM, N, T ) ((T *) im_malloc( (IM), (N) * sizeof( T ))) #define VIPS_ARRAY( IM, N, T ) ((T *) vips_malloc( (IM), (N) * sizeof( T )))
void *im_malloc( VipsImage *im, size_t size ); void *vips_malloc( VipsImage *image, size_t size );
char *im_strdup( VipsImage *im, const char *str ); int vips_free( void *s );
int im_free( void *s );
char *vips_strdup( VipsImage *image, const char *str );
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -70,54 +70,54 @@ typedef struct {
PEL *baseaddr; /* Base of window */ PEL *baseaddr; /* Base of window */
size_t length; /* Size of window */ size_t length; /* Size of window */
} im_window_t; } VipsWindow;
/* window manager. /* window manager.
*/ */
im_window_t *im_window_ref( struct _VipsImage *im, int top, int height ); VipsWindow *vips_window_ref( struct _VipsImage *im, int top, int height );
int im_window_unref( im_window_t *window ); int vips_window_unref( VipsWindow *window );
void im_window_print( im_window_t *window ); void vips_window_print( VipsWindow *window );
/* Per-thread buffer cache. Held in a GPrivate. /* Per-thread buffer cache. Held in a GPrivate.
*/ */
typedef struct im__buffer_cache_t { typedef struct {
GHashTable *hash; /* Hash to im_buffer_cache_list_t* */ GHashTable *hash; /* Hash to VipsBufferCacheList* */
GThread *thread; /* Just for sanity checking */ GThread *thread; /* Just for sanity checking */
} im_buffer_cache_t; } VipsBufferCache;
/* Per-image buffer cache. Hash to this from im_buffer_cache_t. /* Per-image buffer cache. Hash to this from VipsBufferCache.
* We can't store the GSList directly in the hash table, as GHashTable lacks an * We can't store the GSList directly in the hash table, as GHashTable lacks an
* update operation and we'd need to _remove() and _insert() on every list * update operation and we'd need to _remove() and _insert() on every list
* operation. * operation.
*/ */
typedef struct im__buffer_cache_list_t { typedef struct {
GSList *buffers; /* GSList of im_buffer_t* */ GSList *buffers; /* GSList of VipsBuffer* */
GThread *thread; /* Just for sanity checking */ GThread *thread; /* Just for sanity checking */
struct _VipsImage *im; struct _VipsImage *im;
im_buffer_cache_t *cache; VipsBufferCache *cache;
} im_buffer_cache_list_t; } VipsBufferCacheList;
/* What we track for each pixel buffer. /* What we track for each pixel buffer.
*/ */
typedef struct im__buffer_t { typedef struct {
int ref_count; /* # of regions referencing us */ int ref_count; /* # of regions referencing us */
struct _VipsImage *im; /* VipsImage we are attached to */ struct _VipsImage *im; /* VipsImage we are attached to */
VipsRect area; /* Area this pixel buffer covers */ VipsRect area; /* Area this pixel buffer covers */
gboolean done; /* Calculated and in cache */ gboolean done; /* Calculated and in cache */
im_buffer_cache_t *cache; VipsBufferCache *cache;
char *buf; /* Private malloc() area */ char *buf; /* Private malloc() area */
size_t bsize; /* Size of private malloc() */ size_t bsize; /* Size of private malloc() */
} im_buffer_t; } VipsBuffer;
void im_buffer_done( im_buffer_t *buffer ); void vips_buffer_done( VipsBuffer *buffer );
void im_buffer_undone( im_buffer_t *buffer ); void vips_buffer_undone( VipsBuffer *buffer );
void im_buffer_unref( im_buffer_t *buffer ); void vips_buffer_unref( VipsBuffer *buffer );
im_buffer_t *im_buffer_new( struct _VipsImage *im, VipsRect *area ); VipsBuffer *vips_buffer_new( struct _VipsImage *im, VipsRect *area );
im_buffer_t *im_buffer_ref( struct _VipsImage *im, VipsRect *area ); VipsBuffer *vips_buffer_ref( struct _VipsImage *im, VipsRect *area );
im_buffer_t *im_buffer_unref_ref( im_buffer_t *buffer, VipsBuffer *vips_buffer_unref_ref( VipsBuffer *buffer,
struct _VipsImage *im, VipsRect *area ); struct _VipsImage *im, VipsRect *area );
void im_buffer_print( im_buffer_t *buffer ); void vips_buffer_print( VipsBuffer *buffer );
/* Sections of region.h that are private to VIPS. /* Sections of region.h that are private to VIPS.
*/ */

View File

@ -80,11 +80,11 @@ typedef struct _VipsRegion {
/* Ref to the window we use for this region, if any. /* Ref to the window we use for this region, if any.
*/ */
im_window_t *window; VipsWindow *window;
/* Ref to the buffer we use for this region, if any. /* Ref to the buffer we use for this region, if any.
*/ */
im_buffer_t *buffer; VipsBuffer *buffer;
/* The image this region is on has changed and caches need to be /* The image this region is on has changed and caches need to be
* dropped. * dropped.

View File

@ -303,6 +303,10 @@ VipsDemandStyle im_char2dhint( const char *str );
#define im__print_renders vips__print_renders #define im__print_renders vips__print_renders
#define im_cache vips_image_cache #define im_cache vips_image_cache
#define im_malloc vips_malloc
#define im_free vips_free
#define im_strdup vips_strdup
/* Buffer processing. /* Buffer processing.
*/ */
typedef void (*im_wrapone_fn)( void *in, void *out, int width, typedef void (*im_wrapone_fn)( void *in, void *out, int width,

View File

@ -62,6 +62,9 @@ Modified on:
12/5/09 12/5/09
- fix signed/unsigned warning - fix signed/unsigned warning
25/3/11
- move to vips_ namespace
*/ */
/* /*
@ -155,7 +158,7 @@ encode24( char *p, int bits, size_t remaining )
* rather than quick. * rather than quick.
*/ */
char * char *
im__b64_encode( const unsigned char *data, size_t data_length ) vips__b64_encode( const unsigned char *data, size_t data_length )
{ {
/* Worst case: 1.333 chars per byte, plus 10% for extra carriage /* Worst case: 1.333 chars per byte, plus 10% for extra carriage
* returns and stuff. And the \n\0 at the end. * returns and stuff. And the \n\0 at the end.
@ -168,16 +171,16 @@ im__b64_encode( const unsigned char *data, size_t data_length )
int cursor; int cursor;
if( data_length <= 0 ) { if( data_length <= 0 ) {
vips_error( "im__b64_encode", "%s", _( "too little data" ) ); vips_error( "vips__b64_encode", "%s", _( "too little data" ) );
return( NULL ); return( NULL );
} }
if( output_data_length > 1024 * 1024 ) { if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data. /* We shouldn't really be used for large amounts of data.
*/ */
vips_error( "im__b64_encode", "%s", _( "too much data" ) ); vips_error( "vips__b64_encode", "%s", _( "too much data" ) );
return( NULL ); return( NULL );
} }
if( !(buffer = im_malloc( NULL, output_data_length )) ) if( !(buffer = vips_malloc( NULL, output_data_length )) )
return( NULL ); return( NULL );
p = buffer; p = buffer;
@ -211,7 +214,7 @@ im__b64_encode( const unsigned char *data, size_t data_length )
for( total = 0, i = 0; i < data_length; i++ ) for( total = 0, i = 0; i < data_length; i++ )
total += data[i]; total += data[i];
printf( "im__b64_encode: length = %d, checksum 0x%x\n", printf( "vips__b64_encode: length = %d, checksum 0x%x\n",
data_length, total & 0xffff ); data_length, total & 0xffff );
} }
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -222,7 +225,7 @@ im__b64_encode( const unsigned char *data, size_t data_length )
/* Decode base64 back to binary in a malloc'd buffer. NULL on error. /* Decode base64 back to binary in a malloc'd buffer. NULL on error.
*/ */
unsigned char * unsigned char *
im__b64_decode( const char *buffer, size_t *data_length ) vips__b64_decode( const char *buffer, size_t *data_length )
{ {
const size_t buffer_length = strlen( buffer ); const size_t buffer_length = strlen( buffer );
@ -239,11 +242,11 @@ im__b64_decode( const char *buffer, size_t *data_length )
if( output_data_length > 1024 * 1024 ) { if( output_data_length > 1024 * 1024 ) {
/* We shouldn't really be used for large amounts of data. /* We shouldn't really be used for large amounts of data.
*/ */
vips_error( "im__b64_decode", "%s", _( "too much data" ) ); vips_error( "vips__b64_decode", "%s", _( "too much data" ) );
return( NULL ); return( NULL );
} }
if( !(data = im_malloc( NULL, output_data_length )) ) if( !(data = vips_malloc( NULL, output_data_length )) )
return( NULL ); return( NULL );
p = data; p = data;
@ -279,7 +282,7 @@ im__b64_decode( const char *buffer, size_t *data_length )
for( total = 0, i = 0; i < p - data; i++ ) for( total = 0, i = 0; i < p - data; i++ )
total += data[i]; total += data[i];
printf( "im__b64_decode: length = %d, checksum 0x%x\n", printf( "vips__b64_decode: length = %d, checksum 0x%x\n",
p - data, total & 0xffff ); p - data, total & 0xffff );
} }
#endif /*DEBUG*/ #endif /*DEBUG*/

View File

@ -10,7 +10,7 @@
* - split to a buffer hash per thread * - split to a buffer hash per thread
* - reuse buffer mallocs when we can * - reuse buffer mallocs when we can
* 20/2/07 * 20/2/07
* - add im_buffer_cache_list_t and we can avoid some hash ops on * - add VipsBufferCacheList and we can avoid some hash ops on
* done/undone * done/undone
* 5/3/10 * 5/3/10
* - move invalid stuff to region * - move invalid stuff to region
@ -67,7 +67,7 @@
#ifdef DEBUG #ifdef DEBUG
/* Track all regions here for debugging. /* Track all regions here for debugging.
*/ */
static GSList *im__buffers_all = NULL; static GSList *vips__buffers_all = NULL;
#endif /*DEBUG*/ #endif /*DEBUG*/
#ifdef DEBUG_CREATE #ifdef DEBUG_CREATE
@ -77,14 +77,14 @@ static int buffer_cache_n = 0;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
static GPrivate *thread_buffer_cache_key = NULL; static GPrivate *thread_buffer_cache_key = NULL;
#else /*!HAVE_THREADS*/ #else /*!HAVE_THREADS*/
static im_buffer_cache_t *thread_buffer_cache = NULL; static VipsBufferCache *thread_buffer_cache = NULL;
#endif /*HAVE_THREADS*/ #endif /*HAVE_THREADS*/
/* Only need this if we're threading and need to do a lot of start/stop. /* Only need this if we're threading and need to do a lot of start/stop.
*/ */
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
static void static void
buffer_cache_free( im_buffer_cache_t *cache ) buffer_cache_free( VipsBufferCache *cache )
{ {
#ifdef DEBUG_CREATE #ifdef DEBUG_CREATE
buffer_cache_n -= 1; buffer_cache_n -= 1;
@ -100,7 +100,7 @@ buffer_cache_free( im_buffer_cache_t *cache )
#endif /*HAVE_THREADS*/ #endif /*HAVE_THREADS*/
static void static void
buffer_cache_list_free( im_buffer_cache_list_t *cache_list ) buffer_cache_list_free( VipsBufferCacheList *cache_list )
{ {
GSList *p; GSList *p;
@ -108,21 +108,21 @@ buffer_cache_list_free( im_buffer_cache_list_t *cache_list )
* unref. * unref.
*/ */
for( p = cache_list->buffers; p; p = p->next ) { for( p = cache_list->buffers; p; p = p->next ) {
im_buffer_t *buffer = (im_buffer_t *) p->data; VipsBuffer *buffer = (VipsBuffer *) p->data;
buffer->done = FALSE; buffer->done = FALSE;
} }
g_slist_free( cache_list->buffers ); g_slist_free( cache_list->buffers );
im_free( cache_list ); vips_free( cache_list );
} }
static im_buffer_cache_list_t * static VipsBufferCacheList *
buffer_cache_list_new( im_buffer_cache_t *cache, IMAGE *im ) buffer_cache_list_new( VipsBufferCache *cache, VipsImage *im )
{ {
im_buffer_cache_list_t *cache_list; VipsBufferCacheList *cache_list;
if( !(cache_list = VIPS_NEW( NULL, im_buffer_cache_list_t )) ) if( !(cache_list = VIPS_NEW( NULL, VipsBufferCacheList )) )
return( NULL ); return( NULL );
cache_list->buffers = NULL; cache_list->buffers = NULL;
cache_list->thread = g_thread_self(); cache_list->thread = g_thread_self();
@ -138,12 +138,12 @@ buffer_cache_list_new( im_buffer_cache_t *cache, IMAGE *im )
return( cache_list ); return( cache_list );
} }
static im_buffer_cache_t * static VipsBufferCache *
buffer_cache_new( void ) buffer_cache_new( void )
{ {
im_buffer_cache_t *cache; VipsBufferCache *cache;
if( !(cache = VIPS_NEW( NULL, im_buffer_cache_t )) ) if( !(cache = VIPS_NEW( NULL, VipsBufferCache )) )
return( NULL ); return( NULL );
cache->hash = g_hash_table_new_full( g_direct_hash, g_direct_equal, cache->hash = g_hash_table_new_full( g_direct_hash, g_direct_equal,
@ -163,10 +163,10 @@ buffer_cache_new( void )
/* Get the buffer cache. /* Get the buffer cache.
*/ */
static im_buffer_cache_t * static VipsBufferCache *
buffer_cache_get( void ) buffer_cache_get( void )
{ {
im_buffer_cache_t *cache; VipsBufferCache *cache;
#ifdef HAVE_THREADS #ifdef HAVE_THREADS
if( !(cache = g_private_get( thread_buffer_cache_key )) ) { if( !(cache = g_private_get( thread_buffer_cache_key )) ) {
@ -185,17 +185,17 @@ buffer_cache_get( void )
/* Pixels have been calculated: publish for other parts of this thread to see. /* Pixels have been calculated: publish for other parts of this thread to see.
*/ */
void void
im_buffer_done( im_buffer_t *buffer ) vips_buffer_done( VipsBuffer *buffer )
{ {
if( !buffer->done ) { if( !buffer->done ) {
IMAGE *im = buffer->im; VipsImage *im = buffer->im;
im_buffer_cache_t *cache = buffer_cache_get(); VipsBufferCache *cache = buffer_cache_get();
im_buffer_cache_list_t *cache_list; VipsBufferCacheList *cache_list;
#ifdef DEBUG #ifdef DEBUG
printf( "im_buffer_done: thread %p adding to cache %p\n", printf( "vips_buffer_done: thread %p adding to cache %p\n",
g_thread_self(), cache ); g_thread_self(), cache );
im_buffer_print( buffer ); vips_buffer_print( buffer );
#endif /*DEBUG*/ #endif /*DEBUG*/
/* Look up and update the buffer list. /* Look up and update the buffer list.
@ -218,15 +218,15 @@ im_buffer_done( im_buffer_t *buffer )
/* Take off the public 'done' list. /* Take off the public 'done' list.
*/ */
void void
im_buffer_undone( im_buffer_t *buffer ) vips_buffer_undone( VipsBuffer *buffer )
{ {
if( buffer->done ) { if( buffer->done ) {
IMAGE *im = buffer->im; VipsImage *im = buffer->im;
im_buffer_cache_t *cache = buffer->cache; VipsBufferCache *cache = buffer->cache;
im_buffer_cache_list_t *cache_list; VipsBufferCacheList *cache_list;
#ifdef DEBUG #ifdef DEBUG
printf( "im_buffer_undone: thread %p removing " printf( "vips_buffer_undone: thread %p removing "
"buffer %p from cache %p\n", "buffer %p from cache %p\n",
g_thread_self(), buffer, cache ); g_thread_self(), buffer, cache );
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -245,17 +245,17 @@ im_buffer_undone( im_buffer_t *buffer )
buffer->cache = NULL; buffer->cache = NULL;
#ifdef DEBUG #ifdef DEBUG
printf( "im_buffer_undone: %d buffers left\n", printf( "vips_buffer_undone: %d buffers left\n",
g_slist_length( cache_list->buffers ) ); g_slist_length( cache_list->buffers ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
} }
} }
void void
im_buffer_unref( im_buffer_t *buffer ) vips_buffer_unref( VipsBuffer *buffer )
{ {
#ifdef DEBUG #ifdef DEBUG
printf( "** im_buffer_unref: left = %d, top = %d, " printf( "** vips_buffer_unref: left = %d, top = %d, "
"width = %d, height = %d (%p)\n", "width = %d, height = %d (%p)\n",
buffer->area.left, buffer->area.top, buffer->area.left, buffer->area.top,
buffer->area.width, buffer->area.height, buffer->area.width, buffer->area.height,
@ -269,22 +269,22 @@ im_buffer_unref( im_buffer_t *buffer )
if( buffer->ref_count == 0 ) { if( buffer->ref_count == 0 ) {
#ifdef DEBUG #ifdef DEBUG
if( !buffer->done ) if( !buffer->done )
printf( "im_buffer_unref: buffer was not done\n" ); printf( "vips_buffer_unref: buffer was not done\n" );
#endif /*DEBUG*/ #endif /*DEBUG*/
im_buffer_undone( buffer ); vips_buffer_undone( buffer );
buffer->im = NULL; buffer->im = NULL;
VIPS_FREE( buffer->buf ); VIPS_FREE( buffer->buf );
buffer->bsize = 0; buffer->bsize = 0;
im_free( buffer ); vips_free( buffer );
#ifdef DEBUG #ifdef DEBUG
g_mutex_lock( vips__global_lock ); g_mutex_lock( vips__global_lock );
g_assert( g_slist_find( im__buffers_all, buffer ) ); g_assert( g_slist_find( vips__buffers_all, buffer ) );
im__buffers_all = g_slist_remove( im__buffers_all, buffer ); vips__buffers_all = g_slist_remove( vips__buffers_all, buffer );
printf( "%d buffers in vips\n", printf( "%d buffers in vips\n",
g_slist_length( im__buffers_all ) ); g_slist_length( vips__buffers_all ) );
g_mutex_unlock( vips__global_lock ); g_mutex_unlock( vips__global_lock );
#endif /*DEBUG*/ #endif /*DEBUG*/
} }
@ -292,12 +292,12 @@ im_buffer_unref( im_buffer_t *buffer )
/* Make a new buffer. /* Make a new buffer.
*/ */
im_buffer_t * VipsBuffer *
im_buffer_new( IMAGE *im, VipsRect *area ) vips_buffer_new( VipsImage *im, VipsRect *area )
{ {
im_buffer_t *buffer; VipsBuffer *buffer;
if( !(buffer = VIPS_NEW( NULL, im_buffer_t )) ) if( !(buffer = VIPS_NEW( NULL, VipsBuffer )) )
return( NULL ); return( NULL );
buffer->ref_count = 1; buffer->ref_count = 1;
@ -307,13 +307,13 @@ im_buffer_new( IMAGE *im, VipsRect *area )
buffer->cache = NULL; buffer->cache = NULL;
buffer->bsize = (size_t) VIPS_IMAGE_SIZEOF_PEL( im ) * buffer->bsize = (size_t) VIPS_IMAGE_SIZEOF_PEL( im ) *
area->width * area->height; area->width * area->height;
if( !(buffer->buf = im_malloc( NULL, buffer->bsize )) ) { if( !(buffer->buf = vips_malloc( NULL, buffer->bsize )) ) {
im_buffer_unref( buffer ); vips_buffer_unref( buffer );
return( NULL ); return( NULL );
} }
#ifdef DEBUG #ifdef DEBUG
printf( "** im_buffer_new: left = %d, top = %d, " printf( "** vips_buffer_new: left = %d, top = %d, "
"width = %d, height = %d (%p)\n", "width = %d, height = %d (%p)\n",
buffer->area.left, buffer->area.top, buffer->area.left, buffer->area.top,
buffer->area.width, buffer->area.height, buffer->area.width, buffer->area.height,
@ -322,8 +322,8 @@ im_buffer_new( IMAGE *im, VipsRect *area )
#ifdef DEBUG #ifdef DEBUG
g_mutex_lock( vips__global_lock ); g_mutex_lock( vips__global_lock );
im__buffers_all = g_slist_prepend( im__buffers_all, buffer ); vips__buffers_all = g_slist_prepend( vips__buffers_all, buffer );
printf( "%d buffers in vips\n", g_slist_length( im__buffers_all ) ); printf( "%d buffers in vips\n", g_slist_length( vips__buffers_all ) );
g_mutex_unlock( vips__global_lock ); g_mutex_unlock( vips__global_lock );
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -331,15 +331,15 @@ im_buffer_new( IMAGE *im, VipsRect *area )
} }
static int static int
buffer_move( im_buffer_t *buffer, VipsRect *area ) buffer_move( VipsBuffer *buffer, VipsRect *area )
{ {
IMAGE *im = buffer->im; VipsImage *im = buffer->im;
size_t new_bsize; size_t new_bsize;
g_assert( buffer->ref_count == 1 ); g_assert( buffer->ref_count == 1 );
buffer->area = *area; buffer->area = *area;
im_buffer_undone( buffer ); vips_buffer_undone( buffer );
g_assert( !buffer->done ); g_assert( !buffer->done );
new_bsize = (size_t) VIPS_IMAGE_SIZEOF_PEL( im ) * new_bsize = (size_t) VIPS_IMAGE_SIZEOF_PEL( im ) *
@ -347,7 +347,7 @@ buffer_move( im_buffer_t *buffer, VipsRect *area )
if( buffer->bsize < new_bsize ) { if( buffer->bsize < new_bsize ) {
buffer->bsize = new_bsize; buffer->bsize = new_bsize;
VIPS_FREE( buffer->buf ); VIPS_FREE( buffer->buf );
if( !(buffer->buf = im_malloc( NULL, buffer->bsize )) ) if( !(buffer->buf = vips_malloc( NULL, buffer->bsize )) )
return( -1 ); return( -1 );
} }
@ -356,12 +356,12 @@ buffer_move( im_buffer_t *buffer, VipsRect *area )
/* Find an existing buffer that encloses area and return a ref. /* Find an existing buffer that encloses area and return a ref.
*/ */
static im_buffer_t * static VipsBuffer *
buffer_find( IMAGE *im, VipsRect *r ) buffer_find( VipsImage *im, VipsRect *r )
{ {
im_buffer_cache_t *cache = buffer_cache_get(); VipsBufferCache *cache = buffer_cache_get();
im_buffer_cache_list_t *cache_list; VipsBufferCacheList *cache_list;
im_buffer_t *buffer; VipsBuffer *buffer;
GSList *p; GSList *p;
VipsRect *area; VipsRect *area;
@ -375,7 +375,7 @@ buffer_find( IMAGE *im, VipsRect *r )
* search for the largest? * search for the largest?
*/ */
for( ; p; p = p->next ) { for( ; p; p = p->next ) {
buffer = (im_buffer_t *) p->data; buffer = (VipsBuffer *) p->data;
area = &buffer->area; area = &buffer->area;
if( area->left <= r->left && if( area->left <= r->left &&
@ -385,7 +385,7 @@ buffer_find( IMAGE *im, VipsRect *r )
buffer->ref_count += 1; buffer->ref_count += 1;
#ifdef DEBUG #ifdef DEBUG
printf( "im_buffer_find: left = %d, top = %d, " printf( "vips_buffer_find: left = %d, top = %d, "
"width = %d, height = %d, count = %d (%p)\n", "width = %d, height = %d, count = %d (%p)\n",
buffer->area.left, buffer->area.top, buffer->area.left, buffer->area.top,
buffer->area.width, buffer->area.height, buffer->area.width, buffer->area.height,
@ -405,15 +405,15 @@ buffer_find( IMAGE *im, VipsRect *r )
/* Return a ref to a buffer that encloses area. /* Return a ref to a buffer that encloses area.
*/ */
im_buffer_t * VipsBuffer *
im_buffer_ref( IMAGE *im, VipsRect *area ) vips_buffer_ref( VipsImage *im, VipsRect *area )
{ {
im_buffer_t *buffer; VipsBuffer *buffer;
if( !(buffer = buffer_find( im, area )) ) if( !(buffer = buffer_find( im, area )) )
/* No existing buffer ... make a new one. /* No existing buffer ... make a new one.
*/ */
if( !(buffer = im_buffer_new( im, area )) ) if( !(buffer = vips_buffer_new( im, area )) )
return( NULL ); return( NULL );
return( buffer ); return( buffer );
@ -422,10 +422,10 @@ im_buffer_ref( IMAGE *im, VipsRect *area )
/* Unref old, ref new, in a single operation. Reuse stuff if we can. The /* Unref old, ref new, in a single operation. Reuse stuff if we can. The
* buffer we return might or might not be done. * buffer we return might or might not be done.
*/ */
im_buffer_t * VipsBuffer *
im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, VipsRect *area ) vips_buffer_unref_ref( VipsBuffer *old_buffer, VipsImage *im, VipsRect *area )
{ {
im_buffer_t *buffer; VipsBuffer *buffer;
g_assert( !old_buffer || old_buffer->im == im ); g_assert( !old_buffer || old_buffer->im == im );
@ -438,7 +438,7 @@ im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, VipsRect *area )
/* Does the new area already have a buffer? /* Does the new area already have a buffer?
*/ */
if( (buffer = buffer_find( im, area )) ) { if( (buffer = buffer_find( im, area )) ) {
VIPS_FREEF( im_buffer_unref, old_buffer ); VIPS_FREEF( vips_buffer_unref, old_buffer );
return( buffer ); return( buffer );
} }
@ -446,7 +446,7 @@ im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, VipsRect *area )
*/ */
if( old_buffer && old_buffer->ref_count == 1 ) { if( old_buffer && old_buffer->ref_count == 1 ) {
if( buffer_move( old_buffer, area ) ) { if( buffer_move( old_buffer, area ) ) {
im_buffer_unref( old_buffer ); vips_buffer_unref( old_buffer );
return( NULL ); return( NULL );
} }
@ -455,17 +455,17 @@ im_buffer_unref_ref( im_buffer_t *old_buffer, IMAGE *im, VipsRect *area )
/* Fallback ... unref the old one, make a new one. /* Fallback ... unref the old one, make a new one.
*/ */
VIPS_FREEF( im_buffer_unref, old_buffer ); VIPS_FREEF( vips_buffer_unref, old_buffer );
if( !(buffer = im_buffer_new( im, area )) ) if( !(buffer = vips_buffer_new( im, area )) )
return( NULL ); return( NULL );
return( buffer ); return( buffer );
} }
void void
im_buffer_print( im_buffer_t *buffer ) vips_buffer_print( VipsBuffer *buffer )
{ {
printf( "im_buffer_t: %p ref_count = %d, ", buffer, buffer->ref_count ); printf( "VipsBuffer: %p ref_count = %d, ", buffer, buffer->ref_count );
printf( "im = %p, ", buffer->im ); printf( "im = %p, ", buffer->im );
printf( "area.left = %d, ", buffer->area.left ); printf( "area.left = %d, ", buffer->area.left );
printf( "area.top = %d, ", buffer->area.top ); printf( "area.top = %d, ", buffer->area.top );

View File

@ -182,7 +182,7 @@ imagevec_dest( im_object obj )
iv->vec[i] = NULL; iv->vec[i] = NULL;
} }
im_free( iv->vec ); vips_free( iv->vec );
iv->vec = NULL; iv->vec = NULL;
iv->n = 0; iv->n = 0;
} }
@ -245,7 +245,7 @@ mask_init( im_object *obj, char *str )
/* Install string, clear mask. /* Install string, clear mask.
*/ */
if( str && !(mo->name = im_strdup( NULL, str )) ) if( str && !(mo->name = vips_strdup( NULL, str )) )
return( -1 ); return( -1 );
mo->mask = NULL; mo->mask = NULL;
@ -290,7 +290,7 @@ dmask_dest( im_object obj )
im_mask_object *mo = obj; im_mask_object *mo = obj;
if( mo->name ) { if( mo->name ) {
im_free( mo->name ); vips_free( mo->name );
mo->name = NULL; mo->name = NULL;
} }
if( mo->mask ) { if( mo->mask ) {
@ -309,7 +309,7 @@ imask_dest( im_object obj )
im_mask_object *mo = obj; im_mask_object *mo = obj;
if( mo->name ) { if( mo->name ) {
im_free( mo->name ); vips_free( mo->name );
mo->name = NULL; mo->name = NULL;
} }
if( mo->mask ) { if( mo->mask ) {
@ -425,7 +425,7 @@ doublevec_dest( im_object obj )
im_doublevec_object *dv = obj; im_doublevec_object *dv = obj;
if( dv->vec ) { if( dv->vec ) {
im_free( dv->vec ); vips_free( dv->vec );
dv->vec = NULL; dv->vec = NULL;
dv->n = 0; dv->n = 0;
} }
@ -510,7 +510,7 @@ intvec_dest( im_object obj )
im_intvec_object *iv = obj; im_intvec_object *iv = obj;
if( iv->vec ) { if( iv->vec ) {
im_free( iv->vec ); vips_free( iv->vec );
iv->vec = NULL; iv->vec = NULL;
iv->n = 0; iv->n = 0;
} }
@ -623,7 +623,7 @@ im_type_desc im__input_int = {
static int static int
input_string_init( im_object *obj, char *str ) input_string_init( im_object *obj, char *str )
{ {
if( !(*obj = (im_object) im_strdup( NULL, str )) ) if( !(*obj = (im_object) vips_strdup( NULL, str )) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
@ -636,7 +636,7 @@ im_type_desc im__input_string = {
0, /* Memory to allocate */ 0, /* Memory to allocate */
IM_TYPE_ARG, /* It requires a command-line arg */ IM_TYPE_ARG, /* It requires a command-line arg */
input_string_init, /* Init function */ input_string_init, /* Init function */
im_free /* Destroy function */ vips_free /* Destroy function */
}; };
/* Output string type. /* Output string type.
@ -646,7 +646,7 @@ im_type_desc im__output_string = {
0, /* Memory to allocate */ 0, /* Memory to allocate */
IM_TYPE_OUTPUT, /* It's an output argument */ IM_TYPE_OUTPUT, /* It's an output argument */
NULL, /* Init function */ NULL, /* Init function */
im_free /* Destroy function */ vips_free /* Destroy function */
}; };
/* Output double type. /* Output double type.

View File

@ -416,7 +416,7 @@ vips_stop_many( void *seq, void *a, void *b )
for( i = 0; ar[i]; i++ ) for( i = 0; ar[i]; i++ )
g_object_unref( ar[i] ); g_object_unref( ar[i] );
im_free( (char *) ar ); vips_free( (char *) ar );
} }
return( 0 ); return( 0 );

View File

@ -398,7 +398,7 @@ vips_image_finalize( GObject *gobject )
if( image->dtype == VIPS_IMAGE_SETBUF ) { if( image->dtype == VIPS_IMAGE_SETBUF ) {
VIPS_DEBUG_MSG( "vips_image_finalize: " VIPS_DEBUG_MSG( "vips_image_finalize: "
"freeing buffer\n" ); "freeing buffer\n" );
im_free( image->data ); vips_free( image->data );
image->dtype = VIPS_IMAGE_NONE; image->dtype = VIPS_IMAGE_NONE;
} }
@ -608,7 +608,7 @@ lazy_new( VipsImage *image,
lazy->real = NULL; lazy->real = NULL;
g_signal_connect( image, "close", G_CALLBACK( lazy_free_cb ), NULL ); g_signal_connect( image, "close", G_CALLBACK( lazy_free_cb ), NULL );
if( !(lazy->filename = im_strdup( NULL, filename )) ) if( !(lazy->filename = vips_strdup( NULL, filename )) )
return( NULL ); return( NULL );
return( lazy ); return( lazy );
@ -819,7 +819,7 @@ vips_attach_save( VipsImage *image, int (*save_fn)(), const char *filename )
if( (sb = VIPS_NEW( image, SaveBlock )) ) { if( (sb = VIPS_NEW( image, SaveBlock )) ) {
sb->save_fn = save_fn; sb->save_fn = save_fn;
sb->filename = im_strdup( image, filename ); sb->filename = vips_strdup( image, filename );
g_signal_connect( image, "written", g_signal_connect( image, "written",
G_CALLBACK( vips_image_save_cb ), sb ); G_CALLBACK( vips_image_save_cb ), sb );
} }
@ -1841,7 +1841,7 @@ vips__image_write_prepare( VipsImage *image )
/* Allocate memory. /* Allocate memory.
*/ */
if( !image->data ) if( !image->data )
if( !(image->data = im_malloc( NULL, if( !(image->data = vips_malloc( NULL,
VIPS_IMAGE_SIZEOF_IMAGE( image ))) ) VIPS_IMAGE_SIZEOF_IMAGE( image ))) )
return( -1 ); return( -1 );

View File

@ -449,7 +449,7 @@ extract_prefix( const char *dir, const char *name )
printf( "extract_prefix: found \"%s\"\n", vname ); printf( "extract_prefix: found \"%s\"\n", vname );
#endif /*DEBUG*/ #endif /*DEBUG*/
return( im_strdup( NULL, vname ) ); return( vips_strdup( NULL, vname ) );
} }
/* Search a path for a file ... we overwrite the PATH string passed in. /* Search a path for a file ... we overwrite the PATH string passed in.

View File

@ -104,7 +104,7 @@ static int next_trace = 0;
#endif /*DEBUGM*/ #endif /*DEBUGM*/
/** /**
* IM_NEW: * VIPS_NEW:
* @IM: allocate memory local to @IM, or %NULL for no auto-free * @IM: allocate memory local to @IM, or %NULL for no auto-free
* @T: type of thing to allocate * @T: type of thing to allocate
* *
@ -112,7 +112,7 @@ static int next_trace = 0;
*/ */
/** /**
* IM_ARRAY: * VIPS_ARRAY:
* @IM: allocate memory local to @IM, or %NULL for no auto-free * @IM: allocate memory local to @IM, or %NULL for no auto-free
* @N: number of @T 's to allocate * @N: number of @T 's to allocate
* @T: type of thing to allocate * @T: type of thing to allocate
@ -121,20 +121,20 @@ static int next_trace = 0;
*/ */
/** /**
* im_free: * vips_free:
* @s: memory to free * @s: memory to free
* *
* VIPS free function. VIPS tries to use this instead of free(). It always * VIPS free function. VIPS tries to use this instead of free(). It always
* returns zero, so it can be used as a callback handler. * returns zero, so it can be used as a callback handler.
* *
* Only use it to free * Only use it to free
* memory that was previously allocated with im_malloc() with a %NULL first * memory that was previously allocated with vips_malloc() with a %NULL first
* argument. * argument.
* *
* Returns: 0 * Returns: 0
*/ */
int int
im_free( void *s ) vips_free( void *s )
{ {
#ifdef DEBUGM #ifdef DEBUGM
{ {
@ -179,14 +179,14 @@ im_free( void *s )
} }
static void static void
im_malloc_cb( VipsImage *image, char *buf ) vips_malloc_cb( VipsImage *image, char *buf )
{ {
im_free( buf ); vips_free( buf );
} }
/** /**
* im_malloc: * vips_malloc:
* @im: allocate memory local to this #IMAGE, or %NULL * @image: allocate memory local to this #VipsImage, or %NULL
* @size: number of bytes to allocate * @size: number of bytes to allocate
* *
* Malloc local to @im, that is, the memory will be automatically * Malloc local to @im, that is, the memory will be automatically
@ -201,7 +201,7 @@ im_malloc_cb( VipsImage *image, char *buf )
* Returns: a pointer to the allocated memory, or %NULL on error. * Returns: a pointer to the allocated memory, or %NULL on error.
*/ */
void * void *
im_malloc( IMAGE *im, size_t size ) vips_malloc( VipsImage *image, size_t size )
{ {
void *buf; void *buf;
@ -249,7 +249,7 @@ im_malloc( IMAGE *im, size_t size )
next_trace += 1; next_trace += 1;
if( next_trace > trace_freq ) { if( next_trace > trace_freq ) {
printf( "im_malloc: %d, %d allocs, total %.3gM, " printf( "vips_malloc: %d, %d allocs, total %.3gM, "
"high water %.3gM\n", "high water %.3gM\n",
size, size,
total_allocs, total_allocs,
@ -266,9 +266,24 @@ im_malloc( IMAGE *im, size_t size )
printf( "woah! big!\n" ); printf( "woah! big!\n" );
#endif /*DEBUGM*/ #endif /*DEBUGM*/
if( im ) if( image )
g_signal_connect( im, "close", g_signal_connect( image, "close",
G_CALLBACK( im_malloc_cb ), buf ); G_CALLBACK( vips_malloc_cb ), buf );
return( buf ); return( buf );
} }
/* strdup local to a descriptor.
*/
char *
vips_strdup( VipsImage *image, const char *str )
{
int l = strlen( str );
char *buf;
if( !(buf = (char *) vips_malloc( image, l + 1 )) )
return( NULL );
strcpy( buf, str );
return( buf );
}

View File

@ -198,7 +198,7 @@ meta_free( Meta *meta )
g_value_unset( &meta->value ); g_value_unset( &meta->value );
VIPS_FREE( meta->field ); VIPS_FREE( meta->field );
im_free( meta ); vips_free( meta );
} }
static Meta * static Meta *
@ -212,7 +212,7 @@ meta_new( IMAGE *im, const char *field, GValue *value )
meta->field = NULL; meta->field = NULL;
memset( &meta->value, 0, sizeof( GValue ) ); memset( &meta->value, 0, sizeof( GValue ) );
if( !(meta->field = im_strdup( NULL, field )) ) { if( !(meta->field = vips_strdup( NULL, field )) ) {
meta_free( meta ); meta_free( meta );
return( NULL ); return( NULL );
} }
@ -782,7 +782,7 @@ area_unref( Area *area )
if( area->count == 0 && area->free_fn ) { if( area->count == 0 && area->free_fn ) {
(void) area->free_fn( area->data, NULL ); (void) area->free_fn( area->data, NULL );
area->free_fn = NULL; area->free_fn = NULL;
im_free( area ); vips_free( area );
#ifdef DEBUG #ifdef DEBUG
area_number -= 1; area_number -= 1;
@ -964,10 +964,10 @@ im_ref_string_set( GValue *value, const char *str )
g_assert( G_VALUE_TYPE( value ) == IM_TYPE_REF_STRING ); g_assert( G_VALUE_TYPE( value ) == IM_TYPE_REF_STRING );
if( !(str_copy = im_strdup( NULL, str )) ) if( !(str_copy = vips_strdup( NULL, str )) )
return( -1 ); return( -1 );
if( !(area = area_new( (im_callback_fn) im_free, str_copy )) ) { if( !(area = area_new( (im_callback_fn) vips_free, str_copy )) ) {
im_free( str_copy ); vips_free( str_copy );
return( -1 ); return( -1 );
} }
@ -1141,9 +1141,9 @@ transform_blob_save_string( const GValue *src_value, GValue *dest_value )
char *b64; char *b64;
blob = im_blob_get( src_value, &blob_length ); blob = im_blob_get( src_value, &blob_length );
if( (b64 = im__b64_encode( blob, blob_length )) ) { if( (b64 = vips__b64_encode( blob, blob_length )) ) {
im_save_string_set( dest_value, b64 ); im_save_string_set( dest_value, b64 );
im_free( b64 ); vips_free( b64 );
} }
} }
@ -1155,9 +1155,9 @@ transform_save_string_blob( const GValue *src_value, GValue *dest_value )
size_t blob_length; size_t blob_length;
b64 = im_save_string_get( src_value ); b64 = im_save_string_get( src_value );
if( (blob = im__b64_decode( b64, &blob_length )) ) if( (blob = vips__b64_decode( b64, &blob_length )) )
im_blob_set( dest_value, im_blob_set( dest_value,
(im_callback_fn) im_free, blob, blob_length ); (im_callback_fn) vips_free, blob, blob_length );
} }
GType GType

View File

@ -101,7 +101,7 @@ guess_prefix_vec( im_object *argv )
return( -1 ); return( -1 );
} }
argv[2] = im_strdup( NULL, prefix ); argv[2] = vips_strdup( NULL, prefix );
return( 0 ); return( 0 );
} }
@ -137,7 +137,7 @@ guess_libdir_vec( im_object *argv )
return( -1 ); return( -1 );
} }
argv[2] = im_strdup( NULL, libdir ); argv[2] = vips_strdup( NULL, libdir );
return( 0 ); return( 0 );
} }
@ -293,7 +293,7 @@ history_get_vec( im_object *argv )
const char *str; const char *str;
if( !(str = im_history_get( (IMAGE *) argv[0] )) || if( !(str = im_history_get( (IMAGE *) argv[0] )) ||
!(*out = im_strdup( NULL, str )) ) !(*out = vips_strdup( NULL, str )) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
@ -382,7 +382,7 @@ static im_arg_desc version_string_args[] = {
static int static int
version_string_vec( im_object *argv ) version_string_vec( im_object *argv )
{ {
if( !(argv[0] = im_strdup( NULL, vips_version_string() )) ) if( !(argv[0] = vips_strdup( NULL, vips_version_string() )) )
return( -1 ); return( -1 );
return( 0 ); return( 0 );
@ -595,7 +595,7 @@ plugin_free( Plugin *plug )
} }
VIPS_FREE( plug->name ); VIPS_FREE( plug->name );
plug->pack = NULL; plug->pack = NULL;
im_free( plug ); vips_free( plug );
plugin_list = g_slist_remove( plugin_list, plug ); plugin_list = g_slist_remove( plugin_list, plug );
@ -626,7 +626,7 @@ im_load_plugin( const char *name )
/* Attach name. /* Attach name.
*/ */
if( !(plug->name = im_strdup( NULL, name )) ) { if( !(plug->name = vips_strdup( NULL, name )) ) {
plugin_free( plug ); plugin_free( plug );
return( NULL ); return( NULL );
} }
@ -858,7 +858,7 @@ im_free_vargv( im_function *fn, im_object *vargv )
/* If there is local storage, free it. /* If there is local storage, free it.
*/ */
if( fn->argv[i].desc->size != 0 ) if( fn->argv[i].desc->size != 0 )
im_free( vargv[i] ); vips_free( vargv[i] );
/* NULL out pointer. /* NULL out pointer.
*/ */
@ -887,7 +887,7 @@ im_allocate_vargv( im_function *fn, im_object *vargv )
int sz = fn->argv[i].desc->size; int sz = fn->argv[i].desc->size;
if( sz != 0 ) if( sz != 0 )
if( !(vargv[i] = im_malloc( NULL, sz )) ) { if( !(vargv[i] = vips_malloc( NULL, sz )) ) {
/* Free anything we did allocate. /* Free anything we did allocate.
*/ */
(void) im_free_vargv( fn, vargv ); (void) im_free_vargv( fn, vargv );

View File

@ -266,8 +266,8 @@ vips__region_stop( VipsRegion *region )
static void static void
vips_region_reset( VipsRegion *region ) vips_region_reset( VipsRegion *region )
{ {
VIPS_FREEF( im_window_unref, region->window ); VIPS_FREEF( vips_window_unref, region->window );
VIPS_FREEF( im_buffer_unref, region->buffer ); VIPS_FREEF( vips_buffer_unref, region->buffer );
region->invalid = FALSE; region->invalid = FALSE;
} }
@ -378,7 +378,7 @@ vips__region_no_ownership( VipsRegion *region )
region->thread = NULL; region->thread = NULL;
if( region->buffer ) if( region->buffer )
im_buffer_undone( region->buffer ); vips_buffer_undone( region->buffer );
g_mutex_unlock( region->im->sslock ); g_mutex_unlock( region->im->sslock );
} }
@ -501,7 +501,7 @@ vips_region_buffer( VipsRegion *reg, VipsRect *r )
*/ */
if( reg->invalid ) { if( reg->invalid ) {
vips_region_reset( reg ); vips_region_reset( reg );
if( !(reg->buffer = im_buffer_new( im, &clipped )) ) if( !(reg->buffer = vips_buffer_new( im, &clipped )) )
return( -1 ); return( -1 );
} }
else { else {
@ -509,9 +509,9 @@ vips_region_buffer( VipsRegion *reg, VipsRect *r )
* and new buffer ref in one call to reduce malloc/free * and new buffer ref in one call to reduce malloc/free
* cycling. * cycling.
*/ */
VIPS_FREEF( im_window_unref, reg->window ); VIPS_FREEF( vips_window_unref, reg->window );
if( !(reg->buffer = if( !(reg->buffer =
im_buffer_unref_ref( reg->buffer, im, &clipped )) ) vips_buffer_unref_ref( reg->buffer, im, &clipped )) )
return( -1 ); return( -1 );
} }
@ -586,7 +586,7 @@ vips_region_image( VipsRegion *reg, VipsRect *r )
clipped.top + clipped.height ) { clipped.top + clipped.height ) {
vips_region_reset( reg ); vips_region_reset( reg );
if( !(reg->window = im_window_ref( reg->im, if( !(reg->window = vips_window_ref( reg->im,
clipped.top, clipped.height )) ) clipped.top, clipped.height )) )
return( -1 ); return( -1 );
@ -800,7 +800,7 @@ vips_region_fill( VipsRegion *reg, VipsRect *r, VipsRegionFillFn fn, void *a )
/* Publish our results. /* Publish our results.
*/ */
if( reg->buffer ) if( reg->buffer )
im_buffer_done( reg->buffer ); vips_buffer_done( reg->buffer );
} }
return( 0 ); return( 0 );

View File

@ -172,7 +172,7 @@ wbuffer_free( WriteBuffer *wbuffer )
im_semaphore_destroy( &wbuffer->go ); im_semaphore_destroy( &wbuffer->go );
im_semaphore_destroy( &wbuffer->nwrite ); im_semaphore_destroy( &wbuffer->nwrite );
im_semaphore_destroy( &wbuffer->done ); im_semaphore_destroy( &wbuffer->done );
im_free( wbuffer ); vips_free( wbuffer );
} }
static void static void

View File

@ -209,7 +209,7 @@ tile_free( Tile *tile )
VIPS_DEBUG_MSG_AMBER( "tile_free\n" ); VIPS_DEBUG_MSG_AMBER( "tile_free\n" );
VIPS_UNREF( tile->region ); VIPS_UNREF( tile->region );
im_free( tile ); vips_free( tile );
return( NULL ); return( NULL );
} }
@ -241,7 +241,7 @@ render_free( Render *render )
VIPS_FREEF( g_slist_free, render->dirty ); VIPS_FREEF( g_slist_free, render->dirty );
VIPS_FREEF( g_hash_table_destroy, render->tiles ); VIPS_FREEF( g_hash_table_destroy, render->tiles );
im_free( render ); vips_free( render );
#ifdef VIPS_DEBUG_AMBER #ifdef VIPS_DEBUG_AMBER
render_num_renders -= 1; render_num_renders -= 1;

View File

@ -168,10 +168,10 @@ im_slist_fold2( GSList *list, void *start, VSListFold2Fn fn, void *a, void *b )
static void static void
im_slist_free_all_cb( void * thing, void * dummy ) im_slist_free_all_cb( void * thing, void * dummy )
{ {
im_free( thing ); vips_free( thing );
} }
/* Free a g_slist of things which need im_free()ing. /* Free a g_slist of things which need vips_free()ing.
*/ */
void void
im_slist_free_all( GSList *list ) im_slist_free_all( GSList *list )
@ -276,21 +276,6 @@ im_strrstr( const char *haystack, const char *needle )
return( NULL ); return( NULL );
} }
/* strdup local to a descriptor.
*/
char *
im_strdup( IMAGE *im, const char *str )
{
int l = strlen( str );
char *buf;
if( !(buf = (char *) im_malloc( im, l + 1 )) )
return( NULL );
strcpy( buf, str );
return( buf );
}
/* Test for string b ends string a. /* Test for string b ends string a.
*/ */
gboolean gboolean
@ -703,12 +688,12 @@ im__file_read( FILE *fp, const char *filename, unsigned int *length_out )
else { else {
/* Allocate memory and fill. /* Allocate memory and fill.
*/ */
if( !(str = im_malloc( NULL, len + 1 )) ) if( !(str = vips_malloc( NULL, len + 1 )) )
return( NULL ); return( NULL );
rewind( fp ); rewind( fp );
read = fread( str, sizeof( char ), (size_t) len, fp ); read = fread( str, sizeof( char ), (size_t) len, fp );
if( read != (size_t) len ) { if( read != (size_t) len ) {
im_free( str ); vips_free( str );
vips_error( "im__file_read", vips_error( "im__file_read",
_( "error reading from file \"%s\"" ), _( "error reading from file \"%s\"" ),
filename ); filename );
@ -971,7 +956,7 @@ im__gslist_gvalue_get( const GSList *list )
/* +1 for '\0'. /* +1 for '\0'.
*/ */
if( !(all = im_malloc( NULL, length + 1 )) ) if( !(all = vips_malloc( NULL, length + 1 )) )
return( NULL ); return( NULL );
q = all; q = all;

View File

@ -322,10 +322,10 @@ read_chunk( int fd, gint64 offset, size_t length )
if( im__seek( fd, offset ) ) if( im__seek( fd, offset ) )
return( NULL ); return( NULL );
if( !(buf = im_malloc( NULL, length + 1 )) ) if( !(buf = vips_malloc( NULL, length + 1 )) )
return( NULL ); return( NULL );
if( read( fd, buf, length ) != (ssize_t) length ) { if( read( fd, buf, length ) != (ssize_t) length ) {
im_free( buf ); vips_free( buf );
vips_error( "VipsImage", "%s", _( "unable to read history" ) ); vips_error( "VipsImage", "%s", _( "unable to read history" ) );
return( NULL ); return( NULL );
} }
@ -399,10 +399,10 @@ read_xml( IMAGE *im )
if( !(buf = im__read_extension_block( im, &size )) ) if( !(buf = im__read_extension_block( im, &size )) )
return( NULL ); return( NULL );
if( !(doc = xmlParseMemory( buf, size )) ) { if( !(doc = xmlParseMemory( buf, size )) ) {
im_free( buf ); vips_free( buf );
return( NULL ); return( NULL );
} }
im_free( buf ); vips_free( buf );
if( !(node = xmlDocGetRootElement( doc )) || if( !(node = xmlDocGetRootElement( doc )) ||
!node->nsDef || !node->nsDef ||
!im_isprefix( NAMESPACE, (char *) node->nsDef->href ) ) { !im_isprefix( NAMESPACE, (char *) node->nsDef->href ) ) {

View File

@ -88,7 +88,7 @@ static int max_mmap_usage = 0;
#endif /*DEBUG_TOTAL*/ #endif /*DEBUG_TOTAL*/
static int static int
im_window_unmap( im_window_t *window ) vips_window_unmap( VipsWindow *window )
{ {
/* unmap the old window /* unmap the old window
*/ */
@ -112,34 +112,34 @@ im_window_unmap( im_window_t *window )
} }
static int static int
im_window_free( im_window_t *window ) vips_window_free( VipsWindow *window )
{ {
assert( window->ref_count == 0 ); assert( window->ref_count == 0 );
#ifdef DEBUG #ifdef DEBUG
printf( "** im_window_free: window top = %d, height = %d (%p)\n", printf( "** vips_window_free: window top = %d, height = %d (%p)\n",
window->top, window->height, window ); window->top, window->height, window );
#endif /*DEBUG*/ #endif /*DEBUG*/
if( im_window_unmap( window ) ) if( vips_window_unmap( window ) )
return( -1 ); return( -1 );
window->im = NULL; window->im = NULL;
im_free( window ); vips_free( window );
return( 0 ); return( 0 );
} }
int int
im_window_unref( im_window_t *window ) vips_window_unref( VipsWindow *window )
{ {
IMAGE *im = window->im; IMAGE *im = window->im;
g_mutex_lock( im->sslock ); g_mutex_lock( im->sslock );
#ifdef DEBUG #ifdef DEBUG
printf( "im_window_unref: window top = %d, height = %d, count = %d\n", printf( "vips_window_unref: window top = %d, height = %d, count = %d\n",
window->top, window->height, window->ref_count ); window->top, window->height, window->ref_count );
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -152,11 +152,11 @@ im_window_unref( im_window_t *window )
im->windows = g_slist_remove( im->windows, window ); im->windows = g_slist_remove( im->windows, window );
#ifdef DEBUG #ifdef DEBUG
printf( "im_window_unref: %d windows left\n", printf( "vips_window_unref: %d windows left\n",
g_slist_length( im->windows ) ); g_slist_length( im->windows ) );
#endif /*DEBUG*/ #endif /*DEBUG*/
if( im_window_free( window ) ) { if( vips_window_free( window ) ) {
g_mutex_unlock( im->sslock ); g_mutex_unlock( im->sslock );
return( -1 ); return( -1 );
} }
@ -178,7 +178,7 @@ trace_mmap_usage( void )
int max = max_mmap_usage / (1024 * 1024); int max = max_mmap_usage / (1024 * 1024);
if( total != last_total ) { if( total != last_total ) {
printf( "im_window_set: current mmap " printf( "vips_window_set: current mmap "
"usage of ~%dMB (high water mark %dMB)\n", "usage of ~%dMB (high water mark %dMB)\n",
total, max ); total, max );
last_total = total; last_total = total;
@ -215,7 +215,7 @@ im_getpagesize()
/* Map a window into a file. /* Map a window into a file.
*/ */
static int static int
im_window_set( im_window_t *window, int top, int height ) vips_window_set( VipsWindow *window, int top, int height )
{ {
int pagesize = im_getpagesize(); int pagesize = im_getpagesize();
@ -236,7 +236,7 @@ im_window_set( im_window_t *window, int top, int height )
/* Make sure we have enough file. /* Make sure we have enough file.
*/ */
if( end > window->im->file_length ) { if( end > window->im->file_length ) {
vips_error( "im_window_set", vips_error( "vips_window_set",
_( "unable to read data for \"%s\", %s" ), _( "unable to read data for \"%s\", %s" ),
window->im->filename, _( "file has been truncated" ) ); window->im->filename, _( "file has been truncated" ) );
return( -1 ); return( -1 );
@ -271,12 +271,12 @@ im_window_set( im_window_t *window, int top, int height )
/* Make a new window. /* Make a new window.
*/ */
static im_window_t * static VipsWindow *
im_window_new( IMAGE *im, int top, int height ) vips_window_new( IMAGE *im, int top, int height )
{ {
im_window_t *window; VipsWindow *window;
if( !(window = VIPS_NEW( NULL, im_window_t )) ) if( !(window = VIPS_NEW( NULL, VipsWindow )) )
return( NULL ); return( NULL );
window->ref_count = 0; window->ref_count = 0;
@ -287,8 +287,8 @@ im_window_new( IMAGE *im, int top, int height )
window->baseaddr = NULL; window->baseaddr = NULL;
window->length = 0; window->length = 0;
if( im_window_set( window, top, height ) ) { if( vips_window_set( window, top, height ) ) {
im_window_free( window ); vips_window_free( window );
return( NULL ); return( NULL );
} }
@ -296,7 +296,7 @@ im_window_new( IMAGE *im, int top, int height )
window->ref_count += 1; window->ref_count += 1;
#ifdef DEBUG #ifdef DEBUG
printf( "** im_window_new: window top = %d, height = %d (%p)\n", printf( "** vips_window_new: window top = %d, height = %d (%p)\n",
window->top, window->height, window ); window->top, window->height, window );
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -311,7 +311,7 @@ typedef struct {
} request_t; } request_t;
static void * static void *
im_window_fits( im_window_t *window, request_t *req ) vips_window_fits( VipsWindow *window, request_t *req )
{ {
if( window->top <= req->top && if( window->top <= req->top &&
window->top + window->height >= req->top + req->height ) window->top + window->height >= req->top + req->height )
@ -322,22 +322,22 @@ im_window_fits( im_window_t *window, request_t *req )
/* Find an existing window that fits within top/height and return a ref. /* Find an existing window that fits within top/height and return a ref.
*/ */
static im_window_t * static VipsWindow *
im_window_find( IMAGE *im, int top, int height ) vips_window_find( IMAGE *im, int top, int height )
{ {
request_t req; request_t req;
im_window_t *window; VipsWindow *window;
req.top = top; req.top = top;
req.height = height; req.height = height;
window = im_slist_map2( im->windows, window = im_slist_map2( im->windows,
(VSListMap2Fn) im_window_fits, &req, NULL ); (VSListMap2Fn) vips_window_fits, &req, NULL );
if( window ) { if( window ) {
window->ref_count += 1; window->ref_count += 1;
#ifdef DEBUG #ifdef DEBUG
printf( "im_window_find: ref window top = %d, height = %d, " printf( "vips_window_find: ref window top = %d, height = %d, "
"count = %d\n", "count = %d\n",
top, height, window->ref_count ); top, height, window->ref_count );
#endif /*DEBUG*/ #endif /*DEBUG*/
@ -348,14 +348,14 @@ im_window_find( IMAGE *im, int top, int height )
/* Return a ref to a window that encloses top/height. /* Return a ref to a window that encloses top/height.
*/ */
im_window_t * VipsWindow *
im_window_ref( IMAGE *im, int top, int height ) vips_window_ref( IMAGE *im, int top, int height )
{ {
im_window_t *window; VipsWindow *window;
g_mutex_lock( im->sslock ); g_mutex_lock( im->sslock );
if( !(window = im_window_find( im, top, height )) ) { if( !(window = vips_window_find( im, top, height )) ) {
/* No existing window ... make a new one. Ask for a larger /* No existing window ... make a new one. Ask for a larger
* window than we strictly need. There's no point making tiny * window than we strictly need. There's no point making tiny
* windows. * windows.
@ -370,7 +370,7 @@ im_window_ref( IMAGE *im, int top, int height )
top = VIPS_CLIP( 0, top, im->Ysize - 1 ); top = VIPS_CLIP( 0, top, im->Ysize - 1 );
height = VIPS_CLIP( 0, height, im->Ysize - top ); height = VIPS_CLIP( 0, height, im->Ysize - top );
if( !(window = im_window_new( im, top, height )) ) { if( !(window = vips_window_new( im, top, height )) ) {
g_mutex_unlock( im->sslock ); g_mutex_unlock( im->sslock );
return( NULL ); return( NULL );
} }
@ -382,9 +382,9 @@ im_window_ref( IMAGE *im, int top, int height )
} }
void void
im_window_print( im_window_t *window ) vips_window_print( VipsWindow *window )
{ {
printf( "im_window_t: %p ref_count = %d, ", window, window->ref_count ); printf( "VipsWindow: %p ref_count = %d, ", window, window->ref_count );
printf( "im = %p, ", window->im ); printf( "im = %p, ", window->im );
printf( "top = %d, ", window->top ); printf( "top = %d, ", window->top );
printf( "height = %d, ", window->height ); printf( "height = %d, ", window->height );