From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/layman:master commit in: src/
Date: Wed, 5 Oct 2011 20:56:51 +0000 (UTC) [thread overview]
Message-ID: <650c79cb75b4b09257ce0e489c5e20707d8758e0.dol-sen@gentoo> (raw)
commit: 650c79cb75b4b09257ce0e489c5e20707d8758e0
Author: Detlev Casanova <detlev.casanova <AT> gmail <DOT> com>
AuthorDate: Fri Jul 9 13:31:23 2010 +0000
Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Fri Jul 9 13:31:23 2010 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=650c79cb
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 <Python.h>
struct DbBase
@@ -8,7 +9,7 @@ struct DbBase
PyObject *object;
};
-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 = PyList_New(pathCount);
for (unsigned int i = 0; i < pathCount; i++)
@@ -16,10 +17,8 @@ DbBase* createDbBase(const char *paths[], unsigned int pathCount, Config *c, int
PyObject *path = PyBytes_FromString(paths[i]);
PyList_Insert(pypaths, i, path);
}
-
- PyObject *cfg = _object(c);
-
- PyObject *obj = executeFunction("layman.dbbase", "DbBase", "OOIII", pypaths, cfg, ignore, quiet, ignore_init_read_errors);
+
+ PyObject *obj = executeFunction("layman.dbbase", "DbBase", "OOIII", pypaths, dictToPyDict(dict), ignore, quiet, ignore_init_read_errors);
Py_DECREF(pypaths);
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
#include "config.h"
+#include "dict.h"
typedef struct DbBase DbBase;
-DbBase* createDbBase(const char *paths[], unsigned int path_count, Config *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);
#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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#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 = malloc(sizeof(Dict));
+ ret->count = 0;
+ ret->root = 0;
+ return ret;
+}
+
+void dictInsert(Dict* list, const char* key, const char* value)
+{
+ if (!list)
+ return;
+ DictElem *node = malloc(sizeof(DictElem));
+ node->key = key;
+ node->val = value;
+ node->next = list->root;
+ list->root = node;
+ list->count++;
+}
+
+unsigned int dictCount(Dict *list)
+{
+ return (list ? list->count : 0);
+}
+
+void dictFree(Dict *list, int deref)
+{
+ if (!list)
+ return;
+
+ DictElem *node = list->root;
+ while (node)
+ {
+ DictElem *tmp = node;
+ node = node->next;
+ /*if (deref)
+ {
+ Py_DECREF(tmp->object);
+ }*/
+ free(tmp);
+ }
+
+ free(list);
+}
+
+PyObject *dictToPyDict(Dict *dict)
+{
+ PyObject *pydict = PyDict_New();
+ DictElem *node = dict->root;
+ while (node)
+ {
+ PyDict_SetItem(pydict, PyBytes_FromString(node->key), PyBytes_FromString(node->val));
+ node = 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 <Python.h>
+
+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
next reply other threads:[~2011-10-05 20:59 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-05 20:56 Brian Dolbec [this message]
-- strict thread matches above, loose matches on Subject: below --
2011-10-05 20:56 [gentoo-commits] proj/layman:master commit in: src/ Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
2011-10-05 20:56 Brian Dolbec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=650c79cb75b4b09257ce0e489c5e20707d8758e0.dol-sen@gentoo \
--to=brian.dolbec@gmail.com \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox