Skip to content

Commit 8ca10b4

Browse files
committed
Document custom storage functions and link to PHP reference
1 parent 829d048 commit 8ca10b4

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/php-wasm/compile/php-wasm-memory-storage/wasm_memory_storage.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
#include "Zend/zend_alloc.h"
2222
#include "php_wasm_memory_storage.h"
2323

24+
/**
25+
* Allocate a chunk of memory.
26+
*
27+
* This function implements the PHP Zend custom memory storage operation "chunk_free()".
28+
*
29+
* Here is an example offered in the PHP source code:
30+
* https://github.com/php/php-src/blob/dbaeb62ab1e34067057170ab50cf39d1bde584d8/Zend/zend_alloc.h#L325
31+
*
32+
* @param storage The zend_mm_storage struct for this allocation.
33+
* @param size The number of bytes to allocate.
34+
* @param alignment The byte alignment of the memory allocation.
35+
* @returns A pointer to allocated memory or NULL on failure.
36+
*/
2437
void* wasm_memory_storage_chunk_alloc(zend_mm_storage* storage, size_t size, size_t alignment)
2538
{
2639
void* ptr = NULL;
@@ -32,6 +45,19 @@ void* wasm_memory_storage_chunk_alloc(zend_mm_storage* storage, size_t size, siz
3245
}
3346
}
3447

48+
/**
49+
* Free a chunk of memory.
50+
*
51+
* This function implements the PHP Zend custom memory storage operation "chunk_free()".
52+
*
53+
* Here is an example offered in the PHP source code:
54+
* https://github.com/php/php-src/blob/dbaeb62ab1e34067057170ab50cf39d1bde584d8/Zend/zend_alloc.h#L352
55+
*
56+
* @param storage The zend_mm_storage struct for this memory.
57+
* @param ptr The pointer to the memory to free.
58+
* @param size The size of the memory to free. Ignored.
59+
* @returns void
60+
*/
3561
void wasm_memory_storage_chunk_free(zend_mm_storage* storage, void* ptr, size_t size)
3662
{
3763
free(ptr);

0 commit comments

Comments
 (0)