From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RBYYx-0003ul-BX for garchives@archives.gentoo.org; Wed, 05 Oct 2011 20:59:36 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0F96821C1AC; Wed, 5 Oct 2011 20:56:52 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id C26B521C1A5 for ; Wed, 5 Oct 2011 20:56:52 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 665881B403D for ; Wed, 5 Oct 2011 20:56:52 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id B969D8004C for ; Wed, 5 Oct 2011 20:56:51 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <650c79cb75b4b09257ce0e489c5e20707d8758e0.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: src/ X-VCS-Repository: proj/layman X-VCS-Files: src/dbbase.c src/dbbase.h src/dict.c src/dict.h X-VCS-Directories: src/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 650c79cb75b4b09257ce0e489c5e20707d8758e0 Date: Wed, 5 Oct 2011 20:56:51 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 203764373287524ff6f109f793c77e08 commit: 650c79cb75b4b09257ce0e489c5e20707d8758e0 Author: Detlev Casanova gmail com> AuthorDate: Fri Jul 9 13:31:23 2010 +0000 Commit: Brian Dolbec gmail com> CommitDate: Fri Jul 9 13:31:23 2010 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D650c79cb Add a C <-> Python Dict class and fix DbBase to take a Dict fo it's config argument --- src/dbbase.c | 11 +++---- src/dbbase.h | 3 +- src/dict.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++= ++++++ src/dict.h | 14 ++++++++++ 4 files changed, 101 insertions(+), 7 deletions(-) diff --git a/src/dbbase.c b/src/dbbase.c index c617326..dbff007 100644 --- a/src/dbbase.c +++ b/src/dbbase.c @@ -1,6 +1,7 @@ -#include "config.h" +//#include "config.h" #include "dbbase.h" #include "interpreter.h" +#include "dict.h" #include =20 struct DbBase @@ -8,7 +9,7 @@ struct DbBase PyObject *object; }; =20 -DbBase* createDbBase(const char *paths[], unsigned int pathCount, Config= *c, int ignore, int quiet, int ignore_init_read_errors) +DbBase* createDbBase(const char *paths[], unsigned int pathCount, Dict *= dict, int ignore, int quiet, int ignore_init_read_errors) { PyObject *pypaths =3D PyList_New(pathCount); for (unsigned int i =3D 0; i < pathCount; i++) @@ -16,10 +17,8 @@ DbBase* createDbBase(const char *paths[], unsigned int= pathCount, Config *c, int PyObject *path =3D PyBytes_FromString(paths[i]); PyList_Insert(pypaths, i, path); } -=09 - PyObject *cfg =3D _object(c); -=09 - PyObject *obj =3D executeFunction("layman.dbbase", "DbBase", "OOIII", p= ypaths, cfg, ignore, quiet, ignore_init_read_errors); + + PyObject *obj =3D executeFunction("layman.dbbase", "DbBase", "OOIII", p= ypaths, dictToPyDict(dict), ignore, quiet, ignore_init_read_errors); Py_DECREF(pypaths); =20 if (!obj) diff --git a/src/dbbase.h b/src/dbbase.h index 12065af..56f9270 100644 --- a/src/dbbase.h +++ b/src/dbbase.h @@ -2,9 +2,10 @@ #define DB_BASE_H =20 #include "config.h" +#include "dict.h" =20 typedef struct DbBase DbBase; =20 -DbBase* createDbBase(const char *paths[], unsigned int path_count, Confi= g *c, int ignore, int quiet, int ignore_init_read_errors); +DbBase* createDbBase(const char *paths[], unsigned int path_count, Dict = *c, int ignore, int quiet, int ignore_init_read_errors); =20 #endif diff --git a/src/dict.c b/src/dict.c new file mode 100644 index 0000000..a818a69 --- /dev/null +++ b/src/dict.c @@ -0,0 +1,80 @@ +#include +#include +#include + +#include "dict.h" + +/* + * Dict + */ +typedef struct DictElem DictElem; +struct DictElem +{ + const char *key; + const char *val; + struct DictElem *next; +}; + +struct Dict +{ + DictElem *root; + int count; +}; + +Dict *dictCreate() +{ + Dict *ret =3D malloc(sizeof(Dict)); + ret->count =3D 0; + ret->root =3D 0; + return ret; +} + +void dictInsert(Dict* list, const char* key, const char* value) +{ + if (!list) + return; + DictElem *node =3D malloc(sizeof(DictElem)); + node->key =3D key; + node->val =3D value; + node->next =3D list->root; + list->root =3D node; + list->count++; +} + +unsigned int dictCount(Dict *list) +{ + return (list ? list->count : 0); +} + +void dictFree(Dict *list, int deref) +{ + if (!list) + return; + + DictElem *node =3D list->root; + while (node) + { + DictElem *tmp =3D node; + node =3D node->next; + /*if (deref) + { + Py_DECREF(tmp->object); + }*/ + free(tmp); + } + + free(list); +} + +PyObject *dictToPyDict(Dict *dict) +{ + PyObject *pydict =3D PyDict_New(); + DictElem *node =3D dict->root; + while (node) + { + PyDict_SetItem(pydict, PyBytes_FromString(node->key), PyBytes_FromStri= ng(node->val)); + node =3D node->next; + } + + return pydict; +} diff --git a/src/dict.h b/src/dict.h new file mode 100644 index 0000000..844963c --- /dev/null +++ b/src/dict.h @@ -0,0 +1,14 @@ +#ifndef DICT_H +#define DICT_H + +#include + +typedef struct Dict Dict; + +Dict* dictCreate(); +//char* tableFind(Dict *table, char* key); +void dictFree(Dict *t, int); +void dictInsert(Dict* list, const char* key, const char* value); +unsigned int dictCount(Dict *table); +PyObject* dictToPyDict(Dict *dict); +#endif