Skip to content

Commit

Permalink
Added "compact" handler for Zend MM storage.
Browse files Browse the repository at this point in the history
  • Loading branch information
dstogov committed Sep 29, 2007
1 parent 72d0454 commit ae14f6b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ PHP NEWS
- Added support for __callstatic() magic method. (Sara)
- Added support for dynamic access of static members using $foo::myFunc().
(Etienne Kneuss)
- Added "compact" handler for Zend MM storage. (Dmitry)

- Improved php.ini handling: (Jani)
. Added ".htaccess" style user-defined php.ini files support for CGI/FastCGI
Expand Down
28 changes: 15 additions & 13 deletions Zend/zend_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ static void zend_mm_mem_dummy_dtor(zend_mm_storage *storage)
free(storage);
}

static void zend_mm_mem_dummy_compact(zend_mm_storage *storage)
{
}

#if defined(HAVE_MEM_MMAP_ANON) || defined(HAVE_MEM_MMAP_ZERO)

static zend_mm_segment* zend_mm_mem_mmap_realloc(zend_mm_storage *storage, zend_mm_segment* segment, size_t size)
Expand Down Expand Up @@ -180,7 +184,7 @@ static zend_mm_segment* zend_mm_mem_mmap_anon_alloc(zend_mm_storage *storage, si
return ret;
}

# define ZEND_MM_MEM_MMAP_ANON_DSC {"mmap_anon", zend_mm_mem_dummy_init, zend_mm_mem_dummy_dtor, zend_mm_mem_mmap_anon_alloc, zend_mm_mem_mmap_realloc, zend_mm_mem_mmap_free}
# define ZEND_MM_MEM_MMAP_ANON_DSC {"mmap_anon", zend_mm_mem_dummy_init, zend_mm_mem_dummy_dtor, zend_mm_mem_dummy_compact, zend_mm_mem_mmap_anon_alloc, zend_mm_mem_mmap_realloc, zend_mm_mem_mmap_free}

#endif

Expand Down Expand Up @@ -215,7 +219,7 @@ static zend_mm_segment* zend_mm_mem_mmap_zero_alloc(zend_mm_storage *storage, si
return ret;
}

# define ZEND_MM_MEM_MMAP_ZERO_DSC {"mmap_zero", zend_mm_mem_mmap_zero_init, zend_mm_mem_mmap_zero_dtor, zend_mm_mem_mmap_zero_alloc, zend_mm_mem_mmap_realloc, zend_mm_mem_mmap_free}
# define ZEND_MM_MEM_MMAP_ZERO_DSC {"mmap_zero", zend_mm_mem_mmap_zero_init, zend_mm_mem_mmap_zero_dtor, zend_mm_mem_dummy_compact, zend_mm_mem_mmap_zero_alloc, zend_mm_mem_mmap_realloc, zend_mm_mem_mmap_free}

#endif

Expand All @@ -240,6 +244,12 @@ static void zend_mm_mem_win32_dtor(zend_mm_storage *storage)
free(storage);
}

static void zend_mm_mem_win32_compact(zend_mm_storage *storage)
{
HeapDestroy((HANDLE)storage->data);
storage->data = (void*)HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
}

static zend_mm_segment* zend_mm_mem_win32_alloc(zend_mm_storage *storage, size_t size)
{
return (zend_mm_segment*) HeapAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, size);
Expand All @@ -255,7 +265,7 @@ static zend_mm_segment* zend_mm_mem_win32_realloc(zend_mm_storage *storage, zend
return (zend_mm_segment*) HeapReAlloc((HANDLE)storage->data, HEAP_NO_SERIALIZE, segment, size);
}

# define ZEND_MM_MEM_WIN32_DSC {"win32", zend_mm_mem_win32_init, zend_mm_mem_win32_dtor, zend_mm_mem_win32_alloc, zend_mm_mem_win32_realloc, zend_mm_mem_win32_free}
# define ZEND_MM_MEM_WIN32_DSC {"win32", zend_mm_mem_win32_init, zend_mm_mem_win32_dtor, zend_mm_mem_win32_compact, zend_mm_mem_win32_alloc, zend_mm_mem_win32_realloc, zend_mm_mem_win32_free}

#endif

Expand All @@ -276,7 +286,7 @@ static void zend_mm_mem_malloc_free(zend_mm_storage *storage, zend_mm_segment *p
free(ptr);
}

# define ZEND_MM_MEM_MALLOC_DSC {"malloc", zend_mm_mem_dummy_init, zend_mm_mem_dummy_dtor, zend_mm_mem_malloc_alloc, zend_mm_mem_malloc_realloc, zend_mm_mem_malloc_free}
# define ZEND_MM_MEM_MALLOC_DSC {"malloc", zend_mm_mem_dummy_init, zend_mm_mem_dummy_dtor, zend_mm_mem_dummy_compact, zend_mm_mem_malloc_alloc, zend_mm_mem_malloc_realloc, zend_mm_mem_malloc_free}

#endif

Expand Down Expand Up @@ -1560,15 +1570,7 @@ ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, int full_shutdown, int silent
free(heap);
}
} else {
#ifdef HAVE_MEM_WIN32
/* FIX for bug #41713 */
/* TODO: add new "compact" handler */
if (storage->handlers->dtor == zend_mm_mem_win32_dtor &&
storage->handlers->init == zend_mm_mem_win32_init) {
HeapDestroy((HANDLE)storage->data);
storage->data = (void*)HeapCreate(HEAP_NO_SERIALIZE, 0, 0);
}
#endif
storage->handlers->compact(storage);
heap->segments_list = NULL;
zend_mm_init(heap);
heap->real_size = 0;
Expand Down
1 change: 1 addition & 0 deletions Zend/zend_alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ typedef struct _zend_mm_mem_handlers {
const char *name;
zend_mm_storage* (*init)(void *params);
void (*dtor)(zend_mm_storage *storage);
void (*compact)(zend_mm_storage *storage);
zend_mm_segment* (*_alloc)(zend_mm_storage *storage, size_t size);
zend_mm_segment* (*_realloc)(zend_mm_storage *storage, zend_mm_segment *ptr, size_t size);
void (*_free)(zend_mm_storage *storage, zend_mm_segment *ptr);
Expand Down

0 comments on commit ae14f6b

Please sign in to comment.