Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=689a2533304e140381562b512224b15bcdb55a6f
commit 689a2533304e140381562b512224b15bcdb55a6f Author: Michel Hermier <[email protected]> Date: Tue May 7 07:46:55 2013 +0200 libpacman: Use libflib FObject instead of local object implementation. diff --git a/lib/libpacman/Makefile.am b/lib/libpacman/Makefile.am index ad03659..79712ab 100644 --- a/lib/libpacman/Makefile.am +++ b/lib/libpacman/Makefile.am @@ -24,7 +24,6 @@ TARGETS = md5driver.c \ versioncmp.c \ backup.c \ file.c \ - object.c \ packages_transaction.c \ trans.c \ trans_sysupgrade.c \ diff --git a/lib/libpacman/file.c b/lib/libpacman/file.c index b34f9e2..89f5e06 100644 --- a/lib/libpacman/file.c +++ b/lib/libpacman/file.c @@ -29,7 +29,7 @@ int __pacman_file_init(struct pmfile *file, const struct pmfile_ops *ops) { if (ops == NULL || - __pacman_object_init(&file->base, &ops->base)) { + f_object_init(&file->base, &ops->base)) { return EINVAL; } @@ -37,9 +37,7 @@ int __pacman_file_init(struct pmfile *file, const struct pmfile_ops *ops) { return 0; } -int __pacman_file_fini(struct pmobject *object) { - struct pmfile *file = (struct pmfile *)object; - +int __pacman_file_fini(struct pmfile *file) { free(file->path); return 0; } diff --git a/lib/libpacman/file.h b/lib/libpacman/file.h index 390deb7..4eebc95 100644 --- a/lib/libpacman/file.h +++ b/lib/libpacman/file.h @@ -21,23 +21,23 @@ #ifndef _PACMAN_FILE_H #define _PACMAN_FILE_H -#include "object.h" +#include "fobject.h" struct pmfile { - struct pmobject base; + FObject base; char *path; }; struct pmfile_ops { - struct pmobject_ops base; + FObjectOps base; }; struct pmfile *_pacman_file_new(void); /* Implementation details */ int __pacman_file_init(struct pmfile *file, const struct pmfile_ops *ops); -int __pacman_file_fini(struct pmobject *object); +int __pacman_file_fini(struct pmfile *object); #endif /* _PACMAN_OBJECT_H */ diff --git a/lib/libpacman/handle.c b/lib/libpacman/handle.c index 24f4627..6aa9a74 100644 --- a/lib/libpacman/handle.c +++ b/lib/libpacman/handle.c @@ -45,10 +45,8 @@ #include "server.h" static -void _pacman_handle_fini(struct pmobject *obj) +void _pacman_handle_fini(pmhandle_t *ph) { - pmhandle_t *ph = (pmhandle_t *)obj; - /* close logfiles */ if(ph->logfd) { fclose(ph->logfd); @@ -78,7 +76,7 @@ void _pacman_handle_fini(struct pmobject *obj) } static const -struct pmobject_ops _pacman_handle_ops = { +FObjectOps _pacman_handle_ops = { .fini = _pacman_handle_fini, }; @@ -90,7 +88,7 @@ pmhandle_t *_pacman_handle_new() return(NULL); } - __pacman_object_init (&ph->base, &_pacman_handle_ops); + f_object_init (&ph->base, &_pacman_handle_ops); ph->lckfd = -1; ph->maxtries = 1; @@ -128,9 +126,9 @@ pmhandle_t *_pacman_handle_new() return(ph); } -int _pacman_handle_free(pmhandle_t *ph) +void _pacman_handle_free(pmhandle_t *ph) { - return _pacman_object_free (&ph->base); + f_object_delete (&ph->base); } int _pacman_handle_set_option(pmhandle_t *ph, unsigned char val, unsigned long data) diff --git a/lib/libpacman/handle.h b/lib/libpacman/handle.h index a99d16d..4756cff 100644 --- a/lib/libpacman/handle.h +++ b/lib/libpacman/handle.h @@ -31,16 +31,17 @@ typedef struct __pmhandle_t pmhandle_t; #include "list.h" #include "db.h" -#include "object.h" #include "trans.h" +#include "fobject.h" + typedef enum __pmaccess_t { PM_ACCESS_RO, PM_ACCESS_RW } pmaccess_t; struct __pmhandle_t { - struct pmobject base; + FObject base; pmaccess_t access; uid_t uid; @@ -81,7 +82,7 @@ extern pmhandle_t *handle; #define FREEHANDLE(p) do { if (p) { _pacman_handle_free(p); p = NULL; } } while (0) pmhandle_t *_pacman_handle_new(void); -int _pacman_handle_free(pmhandle_t *handle); +void _pacman_handle_free(pmhandle_t *handle); int _pacman_handle_set_option(pmhandle_t *handle, unsigned char val, unsigned long data); int _pacman_handle_get_option(pmhandle_t *handle, unsigned char val, long *data); diff --git a/lib/libpacman/object.c b/lib/libpacman/object.c deleted file mode 100644 index bdbab2f..0000000 --- a/lib/libpacman/object.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * object.c - * - * Copyright (c) 2013 by Michel Hermier <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ - -#include <errno.h> -#include <stdlib.h> /* for NULL */ - -#include "config.h" - -#include "object.h" - -int __pacman_object_init(struct pmobject *object, const struct pmobject_ops *ops) { - if (object == NULL || - ops == NULL) { - return EINVAL; - } - - object->ops = ops; - return 0; -} - -int __pacman_object_fini(struct pmobject *object) { - if (object == NULL || - object->ops == NULL) { - return EINVAL; - } - - return 0; -} - -int _pacman_object_free(struct pmobject *object) { - if (object == NULL || - object->ops == NULL) { - return EINVAL; - } - - if (object->ops->fini != NULL) { - object->ops->fini (object); - } - - free (object); - return 0; -} - -/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/object.h b/lib/libpacman/object.h deleted file mode 100644 index 4c88bbb..0000000 --- a/lib/libpacman/object.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * object.h - * - * Copyright (c) 2013 by Michel Hermier <[email protected]> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, - * USA. - */ -#ifndef _PACMAN_OBJECT_H -#define _PACMAN_OBJECT_H - -struct pmobject; - -struct pmobject_ops { - void (*fini)(struct pmobject *object); -}; - -struct pmobject { - const struct pmobject_ops *ops; -}; - -int _pacman_object_free(struct pmobject *object); - -/* Implementation details */ -int __pacman_object_init(struct pmobject *object, const struct pmobject_ops *ops); -int __pacman_object_fini(struct pmobject *object); - -#endif /* _PACMAN_OBJECT_H */ - -/* vim: set ts=2 sw=2 noet: */ diff --git a/lib/libpacman/package.c b/lib/libpacman/package.c index 3ef0165..c081b91 100644 --- a/lib/libpacman/package.c +++ b/lib/libpacman/package.c @@ -148,10 +148,9 @@ pmpkg_t *_pacman_pkg_dup(pmpkg_t *pkg) return(newpkg); } -void _pacman_pkg_free(void *data) +void _pacman_pkg_free(pmpkg_t *pkg) { - pmpkg_t *pkg = data; - _pacman_object_free (&pkg->base.base); + f_object_delete (&pkg->base.base); } /* Helper function for comparing packages diff --git a/lib/libpacman/package.h b/lib/libpacman/package.h index 574f903..878d004 100644 --- a/lib/libpacman/package.h +++ b/lib/libpacman/package.h @@ -98,7 +98,7 @@ do { \ pmpkg_t* _pacman_pkg_new(const char *name, const char *version); pmpkg_t *_pacman_pkg_dup(pmpkg_t *pkg); -void _pacman_pkg_free(void *data); +void _pacman_pkg_free(pmpkg_t *pkg); int _pacman_pkg_cmp(const void *p1, const void *p2); pmpkg_t *_pacman_pkg_load(const char *pkgfile); pmpkg_t *_pacman_pkg_isin(const char *needle, pmlist_t *haystack); diff --git a/lib/libpacman/trans.c b/lib/libpacman/trans.c index adb6226..fba64d6 100644 --- a/lib/libpacman/trans.c +++ b/lib/libpacman/trans.c @@ -131,7 +131,7 @@ void __pacman_trans_fini(struct pmobject *obj) { } static const -struct pmobject_ops _pacman_trans_ops = { +FObjectOps _pacman_trans_ops = { .fini = __pacman_trans_fini, }; @@ -140,7 +140,7 @@ pmtrans_t *_pacman_trans_new() pmtrans_t *trans = _pacman_zalloc(sizeof(pmtrans_t)); if (trans != NULL) { - __pacman_object_init (&trans->base, &_pacman_trans_ops); + f_object_init (&trans->base, &_pacman_trans_ops); trans->state = STATE_IDLE; } @@ -148,7 +148,7 @@ pmtrans_t *_pacman_trans_new() } void _pacman_trans_free(pmtrans_t *trans) { - _pacman_object_free (&trans->base); + f_object_delete (&trans->base); } int _pacman_trans_init(pmtrans_t *trans, pmtranstype_t type, unsigned int flags, pmtrans_cbs_t cbs) diff --git a/lib/libpacman/trans.h b/lib/libpacman/trans.h index 0083784..20335bc 100644 --- a/lib/libpacman/trans.h +++ b/lib/libpacman/trans.h @@ -51,7 +51,7 @@ typedef struct __pmtrans_cbs_t { } pmtrans_cbs_t; struct __pmtrans_t { - struct pmobject base; + FObject base; const pmtrans_ops_t *ops; int (*set_state)(pmtrans_t *trans, int new_state); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
