Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=df3f47f9a60bd97c943dccb766953c11f681b48b

commit df3f47f9a60bd97c943dccb766953c11f681b48b
Author: Michel Hermier <[email protected]>
Date:   Thu Apr 24 08:02:37 2014 +0200

libpacman: Add object memory allocator and object private data.

diff --git a/lib/libpacman/db/localdb.c b/lib/libpacman/db/localdb.c
index 16efae6..f7be7fa 100644
--- a/lib/libpacman/db/localdb.c
+++ b/lib/libpacman/db/localdb.c
@@ -141,7 +141,6 @@ static
int _pacman_localpkg_init(pmpkg_t *pkg, pmdb_t *db)
{
ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
-       _pacman_object_init(&pkg->as_pmobject_t, 
&_pacman_localpkg_operations.as_pmobject_operations_t);
ASSERT(_pacman_pkg_init(pkg, db) == 0, return -1);

return 0;
diff --git a/lib/libpacman/db/syncdb.c b/lib/libpacman/db/syncdb.c
index 7dab363..3b48e71 100644
--- a/lib/libpacman/db/syncdb.c
+++ b/lib/libpacman/db/syncdb.c
@@ -124,7 +124,6 @@ static
int _pacman_syncpkg_init(pmpkg_t *pkg, pmdb_t *db)
{
ASSERT(pkg != NULL, RET_ERR(PM_ERR_PKG_INVALID, -1));
-       _pacman_object_init(&pkg->as_pmobject_t, 
&_pacman_syncpkg_operations.as_pmobject_operations_t);
ASSERT(_pacman_pkg_init(pkg, db) == 0, return -1);

return 0;
diff --git a/lib/libpacman/object.c b/lib/libpacman/object.c
index a6cc411..d7de36d 100644
--- a/lib/libpacman/object.c
+++ b/lib/libpacman/object.c
@@ -39,12 +39,11 @@ int _pacman_object_delete(struct __pmobject_t *self)
return 0;
}

-int _pacman_object_init(struct __pmobject_t *self, const struct 
__pmobject_operations_t *operations)
+int _pacman_object_init(struct __pmobject_t *self, struct __pmobject_private_t 
*object_private)
{
ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-       ASSERT(self->operations == NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));

-       self->operations = NULL;
+       self->object_private = object_private;
return 0;
}

@@ -85,4 +84,17 @@ int _pacman_object_set(struct __pmobject_t *self, unsigned 
val, unsigned long da
return object_operations->set(self, val, data);
}

+struct __pmobject_t *_pacman_objectmemory_alloc(size_t size, const struct 
__pmobject_operations_t *operations)
+{
+       struct __pmobject_t *ret;
+
+       ASSERT(size >= sizeof(*ret), RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+       ASSERT(operations == NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+       if((ret = f_zalloc(size)) != NULL) {
+               ret->operations = operations;
+       }
+       return ret;
+}
+
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/object.h b/lib/libpacman/object.h
index 23fcf65..8cd8f68 100644
--- a/lib/libpacman/object.h
+++ b/lib/libpacman/object.h
@@ -24,6 +24,7 @@
#include <stddef.h>

struct __pmobject_t;
+struct __pmobject_private_t;

struct __pmobject_operations_t
{
@@ -36,11 +37,13 @@ struct __pmobject_operations_t
struct __pmobject_t
{
const struct __pmobject_operations_t *operations;
+
+       struct __pmobject_private *object_private;
};

int _pacman_object_delete(struct __pmobject_t *self);

-int _pacman_object_init(struct __pmobject_t *self, const struct 
__pmobject_operations_t *operations);
+int _pacman_object_init(struct __pmobject_t *self, struct __pmobject_private_t 
*object_private);
int _pacman_object_fini(struct __pmobject_t *self);

const struct __pmobject_operations_t *_pacman_object_operations(struct 
__pmobject_t *self);
@@ -48,6 +51,8 @@ const struct __pmobject_operations_t 
*_pacman_object_operations(struct __pmobjec
int _pacman_object_get(struct __pmobject_t *self, unsigned val, unsigned long 
*data);
int _pacman_object_set(struct __pmobject_t *self, unsigned val, unsigned long 
data);

+struct __pmobject_t *_pacman_objectmemory_alloc(size_t size, const struct 
__pmobject_operations_t *operations);
+
#endif /* _PACMAN__OBJECT_H */

/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libpacman/package.c b/lib/libpacman/package.c
index 46d9d24..dce4d42 100644
--- a/lib/libpacman/package.c
+++ b/lib/libpacman/package.c
@@ -188,6 +188,7 @@ int _pacman_pkg_delete(pmpkg_t *self)
int _pacman_pkg_init(pmpkg_t *self, pmdb_t *db)
{
ASSERT(self != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+       ASSERT(_pacman_object_init(&self->as_pmobject_t, NULL) == 0, return -1);
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));

self->database = db;
@@ -216,6 +217,16 @@ int _pacman_pkg_fini(pmpkg_t *self)
return 0;
}

+static
+const struct __pmpkg_operations_t *_pacman_package_operations(pmpkg_t *self)
+{
+       const struct __pmobject_operations_t *object_operations;
+
+       ASSERT((object_operations = 
_pacman_object_operations(&self->as_pmobject_t)) != NULL, 
RET_ERR(PM_ERR_WRONG_ARGS, NULL));
+
+       return (const struct __pmpkg_operations_t *)object_operations;
+}
+
/* Helper function for comparing packages
*/
int _pacman_pkg_cmp(const void *p1, const void *p2)
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to