Ver Fonte

lib/kmi: option to build it with system malloc

- MI lib can be built independently of core with system malloc for pkg
  memory (see Makefile)
Daniel-Constantin Mierla há 16 anos atrás
pai
commit
85f2302e84
5 ficheiros alterados com 14 adições e 13 exclusões
  1. 2 0
      lib/kmi/Makefile
  2. 3 3
      lib/kmi/attr.c
  3. 2 2
      lib/kmi/fmt.c
  4. 2 2
      lib/kmi/mi.c
  5. 5 6
      lib/kmi/tree.c

+ 2 - 0
lib/kmi/Makefile

@@ -4,6 +4,8 @@ NAME:=kmi
 MAJOR_VER=1
 MINOR_VER=0
 BUGFIX_VER=0
+## uncomment next line for using system malloc with MI
+#DEFS+= -DMI_SYSTEM_MALLOC
 LIBS=
 
 include ../../Makefile.libs

+ 3 - 3
lib/kmi/attr.c

@@ -36,8 +36,8 @@
 #include <string.h>
 #include <errno.h>
 
-#include "../../mem/mem.h"
 #include "../../dprint.h"
+#include "mi_mem.h"
 #include "attr.h"
 #include "fmt.h"
 
@@ -75,7 +75,7 @@ struct mi_attr *add_mi_attr(struct mi_node *node, int flags,
 		size_mem += value_len;
 	}
 
-	new = (struct mi_attr *)pkg_malloc(size_mem);
+	new = (struct mi_attr *)mi_malloc(size_mem);
 	if (!new) {
 		LM_ERR("no more pkg mem (%d)\n",size_mem);
 		return NULL;
@@ -167,7 +167,7 @@ void del_mi_attr_list(struct mi_node *node)
 
 	for(head = node->attributes; head ;){
 		p = head->next;
-		pkg_free(head);
+		mi_free(head);
 		head = p;
 	}
 

+ 2 - 2
lib/kmi/fmt.c

@@ -34,7 +34,7 @@
 
 #include <string.h>
 #include "../../dprint.h"
-#include "../../mem/mem.h"
+#include "mi_mem.h"
 
 char *mi_fmt_buf = 0;
 int  mi_fmt_buf_len = 0;
@@ -42,7 +42,7 @@ int  mi_fmt_buf_len = 0;
 
 int mi_fmt_init( unsigned int size )
 {
-	mi_fmt_buf = (char*)pkg_malloc(size);
+	mi_fmt_buf = (char*)mi_malloc(size);
 	if (mi_fmt_buf==NULL) {
 		LM_ERR("no more pkg mem\n");
 		return -1;

+ 2 - 2
lib/kmi/mi.c

@@ -46,7 +46,7 @@
 #include <string.h>
 
 #include "../../dprint.h"
-#include "../../mem/mem.h"
+#include "mi_mem.h"
 #include "mi.h"
 
 static struct mi_cmd*  mi_cmds = 0;
@@ -138,7 +138,7 @@ int register_mi_cmd( mi_cmd_f f, char *name, void *param,
 		return -1;
 	}
 
-	cmds = (struct mi_cmd*)pkg_realloc( mi_cmds,
+	cmds = (struct mi_cmd*)mi_realloc( mi_cmds,
 			(mi_cmds_no+1)*sizeof(struct mi_cmd) );
 	if (cmds==0) {
 		LM_ERR("no more pkg memory\n");

+ 5 - 6
lib/kmi/tree.c

@@ -34,9 +34,8 @@
 #include <string.h>
 #include <stdio.h>
 #include <errno.h>
-#include "../../mem/mem.h"
-#include "../../mem/shm_mem.h"
 #include "../../dprint.h"
+#include "mi_mem.h"
 #include "tree.h"
 #include "fmt.h"
 
@@ -50,7 +49,7 @@ struct mi_root *init_mi_tree(unsigned int code, char *reason, int reason_len)
 	if (use_shm)
 		root = (struct mi_root *)shm_malloc(sizeof(struct mi_root));
 	else
-		root = (struct mi_root *)pkg_malloc(sizeof(struct mi_root));
+		root = (struct mi_root *)mi_malloc(sizeof(struct mi_root));
 	if (!root) {
 		LM_ERR("no more pkg mem\n");
 		return NULL;
@@ -83,7 +82,7 @@ static void free_mi_node(struct mi_node *parent)
 		shm_free(parent);
 	} else {
 		del_mi_attr_list(parent);
-		pkg_free(parent);
+		mi_free(parent);
 	}
 }
 
@@ -100,7 +99,7 @@ void free_mi_tree(struct mi_root *parent)
 	if (use_shm)
 		shm_free(parent);
 	else
-		pkg_free(parent);
+		mi_free(parent);
 }
 
 
@@ -135,7 +134,7 @@ static inline struct mi_node *create_mi_node(char *name, int name_len,
 	if (use_shm)
 		new = (struct mi_node *)shm_malloc(size_mem);
 	else
-		new = (struct mi_node *)pkg_malloc(size_mem);
+		new = (struct mi_node *)mi_malloc(size_mem);
 	if(!new) {
 		LM_ERR("no more pkg mem\n");
 		return NULL;