mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 12:20:41 +00:00
use skynet_malloc api
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
https://github.com/cloudwu/lua-serialize
|
||||
*/
|
||||
|
||||
// include skynet.h first for malloc hook
|
||||
#include "skynet.h"
|
||||
#include "skynet_malloc.h"
|
||||
|
||||
#include <lua.h>
|
||||
#include <lauxlib.h>
|
||||
@@ -50,7 +49,7 @@ struct read_block {
|
||||
|
||||
inline static struct block *
|
||||
blk_alloc(void) {
|
||||
struct block *b = malloc(sizeof(struct block));
|
||||
struct block *b = skynet_malloc(sizeof(struct block));
|
||||
b->next = NULL;
|
||||
return b;
|
||||
}
|
||||
@@ -113,7 +112,7 @@ wb_free(struct write_block *wb) {
|
||||
struct block *blk = wb->head;
|
||||
while (blk) {
|
||||
struct block * next = blk->next;
|
||||
free(blk);
|
||||
skynet_free(blk);
|
||||
blk = next;
|
||||
}
|
||||
wb->head = NULL;
|
||||
@@ -145,7 +144,7 @@ rb_read(struct read_block *rb, void *buffer, int sz) {
|
||||
|
||||
if (rb->ptr == BLOCK_SIZE) {
|
||||
struct block * next = rb->current->next;
|
||||
free(rb->current);
|
||||
skynet_free(rb->current);
|
||||
rb->current = next;
|
||||
rb->ptr = 0;
|
||||
}
|
||||
@@ -168,7 +167,7 @@ rb_read(struct read_block *rb, void *buffer, int sz) {
|
||||
|
||||
for (;;) {
|
||||
struct block * next = rb->current->next;
|
||||
free(rb->current);
|
||||
skynet_free(rb->current);
|
||||
rb->current = next;
|
||||
|
||||
if (sz < BLOCK_SIZE) {
|
||||
@@ -188,7 +187,7 @@ static void
|
||||
rb_close(struct read_block *rb) {
|
||||
while (rb->current) {
|
||||
struct block * next = rb->current->next;
|
||||
free(rb->current);
|
||||
skynet_free(rb->current);
|
||||
rb->current = next;
|
||||
}
|
||||
rb->len = 0;
|
||||
@@ -549,7 +548,7 @@ _seri(lua_State *L, struct block *b) {
|
||||
memcpy(&len, b->buffer ,sizeof(len));
|
||||
|
||||
len -= 4;
|
||||
uint8_t * buffer = malloc(len);
|
||||
uint8_t * buffer = skynet_malloc(len);
|
||||
uint8_t * ptr = buffer;
|
||||
int sz = len;
|
||||
if (len < BLOCK_SIZE - 4) {
|
||||
@@ -622,7 +621,7 @@ _luaseri_pack(lua_State *L) {
|
||||
|
||||
while (b) {
|
||||
struct block * next = b->next;
|
||||
free(b);
|
||||
skynet_free(b);
|
||||
b = next;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user