public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
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:55 +0000 (UTC)	[thread overview]
Message-ID: <82813ef426d1a17df69e4daf91c7fb862e4ab26c.dol-sen@gentoo> (raw)

commit:     82813ef426d1a17df69e4daf91c7fb862e4ab26c
Author:     Detlev Casanova <detlev.casanova <AT> gmail <DOT> com>
AuthorDate: Mon Jul 19 09:59:44 2010 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jul 19 09:59:44 2010 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=82813ef4

Fix PyObject_IsTrue calls

---
 src/config.c     |    5 +++++
 src/laymanapi.c  |   51 ++++++++++++++++++++++++++++-----------------------
 src/stringlist.c |   30 +++++++++++++++++++++++++++---
 src/tester.c     |   17 ++++++++---------
 4 files changed, 68 insertions(+), 35 deletions(-)

diff --git a/src/config.c b/src/config.c
index c0b5b79..0bb330a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -3,6 +3,8 @@
 #include "config.h"
 #include "internal.h"
 
+#define debug(x)	printf(x)
+
 struct BareConfig
 {
 	PyObject *object;
@@ -38,7 +40,10 @@ BareConfig *bareConfigCreate(Message *m, FILE* outFd, FILE* inFd, FILE* errFd)
 	Py_DECREF(pyerr);
 
 	if (!obj)
+	{
+		debug("The execution failed, Are you sure app-portage/layman-8888 is properly installed ?\n");
 		return NULL;
+	}
 
 	BareConfig *ret = malloc(sizeof(BareConfig));
 	ret->object = obj;

diff --git a/src/laymanapi.c b/src/laymanapi.c
index 74e98bf..6ddbba7 100644
--- a/src/laymanapi.c
+++ b/src/laymanapi.c
@@ -2,7 +2,7 @@
 #include "internal.h"
 #include "laymanapi.h"
 
-int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInfo *results, const char *overlay);
+static int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInfo *results, const char *overlay);
 
 struct LaymanAPI
 {
@@ -16,8 +16,13 @@ struct LaymanAPI
  */
 LaymanAPI* laymanAPICreate(BareConfig* config, int report_error, int output)
 {
-	assert(NULL != config);
-	PyObject *obj = executeFunction("layman.api", "LaymanAPI", "Oii", _bareConfigObject(config), report_error, output);
+	PyObject *cfg;
+	if (!config)
+		cfg = Py_None;
+	else
+		cfg = _bareConfigObject(config);
+
+	PyObject *obj = executeFunction("layman.api", "LaymanAPI", "Oii", cfg, report_error, output);
 	if (!obj)
 		return NULL;
 
@@ -42,7 +47,7 @@ int laymanAPIIsRepo(LaymanAPI *l, const char* repo)
 
 	Py_DECREF(obj);
 
-	return !ret;
+	return ret;
 }
 
 int laymanAPIIsInstalled(LaymanAPI *l, const char* repo)
@@ -60,7 +65,7 @@ int laymanAPIIsInstalled(LaymanAPI *l, const char* repo)
 
 	Py_DECREF(obj);
 
-	return !ret;
+	return ret;
 }
 
 /*
@@ -114,13 +119,13 @@ int laymanAPISync(LaymanAPI* l, const char* overlay, int verbose)
 		return 0;
 
 	int ret = PyObject_IsTrue(obj);
-	
+
 	// ret must be 1 or 0
 	assert(-1 != ret);
-	
+
 	Py_DECREF(obj);
-	
-	return !ret;
+
+	return ret;
 }
 
 /*
@@ -141,7 +146,7 @@ int laymanAPIFetchRemoteList(LaymanAPI* l)
 	
 	Py_DECREF(obj);
 
-	return !ret;
+	return ret;
 }
 
 /*
@@ -207,9 +212,9 @@ int laymanAPIGetInfoStrList(LaymanAPI* l, StringList* overlays, OverlayInfo* res
 		assert(NULL != tmp);
 		results[k].text = strdup(tmp);
 
-		results[k].official = !PyObject_IsTrue(official);
+		results[k].official = PyObject_IsTrue(official);
 		assert(-1 != results[k].official);
-		results[k].supported = !PyObject_IsTrue(supported);
+		results[k].supported = PyObject_IsTrue(supported);
 		assert(-1 != results[k].supported);
 
 		k++;
@@ -381,9 +386,9 @@ int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInfo *resul
 		results[k].srcUris = listToCList(srcUris);
 
 		// If official or supported is neither True or False, abort.
-		results[k].official = !PyObject_IsTrue(official);
+		results[k].official = PyObject_IsTrue(official);
 		assert(-1 != results[k].official);
-		results[k].supported = !PyObject_IsTrue(supported);
+		results[k].supported = PyObject_IsTrue(supported);
 		assert(-1 != results[k].supported);
 
 		k++;
@@ -408,14 +413,14 @@ int laymanAPIAddRepo(LaymanAPI* l, const char *repo)
 
 	// Call the method
 	PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(s)", repo);
-	
+
 	// If the call returned NULL, it failed.
 	int ret;
 	if (!obj)
 		ret = 0;
 	else
 		ret = 1;
-	
+
 	Py_DECREF(obj);
 
 	return ret;
@@ -437,14 +442,14 @@ int laymanAPIAddRepoList(LaymanAPI* l, StringList *repos)
 	// Call the method
 	PyObject *obj = PyObject_CallMethod(l->object, "add_repos", "(O)", pyrepos);
 	Py_DECREF(pyrepos);
-	
+
 	// If the call returned NULL, it failed.
 	int ret;
 	if (!obj)
 		ret = 0;
 	else
 		ret = 1;
-	
+
 	Py_DECREF(obj);
 
 	return ret;
@@ -462,14 +467,14 @@ int laymanAPIDeleteRepo(LaymanAPI* l, const char *repo)
 
 	// Call the method
 	PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(s)", repo);
-	
+
 	// If the call returned NULL, it failed.
 	int ret;
 	if (!obj)
 		ret = 0;
 	else
 		ret = 1;
-	
+
 	Py_DECREF(obj);
 
 	return ret;
@@ -487,18 +492,18 @@ int laymanAPIDeleteRepoList(LaymanAPI* l, StringList *repos)
 
 	// Converting the C list to a python list
 	PyObject *pyrepos = cListToPyList(repos);
-	
+
 	// Call the method
 	PyObject *obj = PyObject_CallMethod(l->object, "delete_repos", "(O)", pyrepos);
 	Py_DECREF(pyrepos);
-	
+
 	// If the call returned NULL, it failed.
 	int ret;
 	if (!obj)
 		ret = 0;
 	else
 		ret = 1;
-	
+
 	Py_DECREF(obj);
 
 	return ret;

diff --git a/src/stringlist.c b/src/stringlist.c
index 259eabb..915cca4 100644
--- a/src/stringlist.c
+++ b/src/stringlist.c
@@ -8,6 +8,8 @@ struct StringList
 	unsigned int count;
 };
 
+// Creates a String list to use with the library.
+// len is the number of strings in the list.
 StringList* stringListCreate(size_t len)
 {
 	StringList *ret = malloc(sizeof(StringList));
@@ -17,6 +19,10 @@ StringList* stringListCreate(size_t len)
 	return ret;
 }
 
+/*
+ * Inserts the string str in the list l at position pos.
+ * Return True if it succeeded, False if not.
+ */
 int stringListInsertAt(StringList *l, unsigned int pos, char *str)
 {
 	if(!l || !l->list || l->count < pos)
@@ -27,6 +33,9 @@ int stringListInsertAt(StringList *l, unsigned int pos, char *str)
 	return 1;
 }
 
+/*
+ * Returns the number of strings in the list
+ */
 unsigned int stringListCount(StringList *l)
 {
 	if (!l)
@@ -34,6 +43,9 @@ unsigned int stringListCount(StringList *l)
 	return l->count;
 }
 
+/*
+ * Returns the String at position pos
+ */
 char* stringListGetAt(StringList *l, unsigned int pos)
 {
 	if (!l || !l->list || pos >= l->count)
@@ -42,6 +54,9 @@ char* stringListGetAt(StringList *l, unsigned int pos)
 	return l->list[pos];
 }
 
+/*
+ * Converts a Python list object to a C String list
+ */
 StringList* listToCList(PyObject* list)
 {
 	if (!list || !PyList_Check(list))
@@ -54,6 +69,8 @@ StringList* listToCList(PyObject* list)
 
 	for (unsigned int i = 0; i < len; i++)
 	{
+		//Item are copied so that the PyObject can be deleted after the call without
+		//destroying the data in the returned list.
 		PyObject *elem = PyList_GetItem(list, i);
 		ret->list[i] = malloc(sizeof(char) * (PyBytes_Size(elem) + 1));
 		strcpy(ret->list[i], PyBytes_AsString(elem));
@@ -62,6 +79,9 @@ StringList* listToCList(PyObject* list)
 	return ret;
 }
 
+/*
+ * Converts a C String list to a Python List object
+ */
 PyObject* cListToPyList(StringList* list)
 {
 	if (!list)
@@ -76,6 +96,9 @@ PyObject* cListToPyList(StringList* list)
 	return ret;
 }
 
+/*
+ * Prints a C String list.
+ */
 void stringListPrint(StringList* list)
 {
 	if (!list)
@@ -84,16 +107,17 @@ void stringListPrint(StringList* list)
 	for(unsigned int i = 0; i < list->count; i++)
 	{
 		printf("\"%s\"", list->list[i]);
+		// No coma after the last item.
 		if (i < list->count - 1)
 			printf(", ");
 	}
 }
 
+/*
+ * Frees a string list and it's data
+ */
 void stringListFree(StringList* list)
 {
-	if (!list)
-		return;
-
 	if (list && list->list)
 	{
 		for(unsigned int i = 0; i < list->count; i++)

diff --git a/src/tester.c b/src/tester.c
index 049cc61..98dc171 100644
--- a/src/tester.c
+++ b/src/tester.c
@@ -22,24 +22,23 @@ int main(int argc, char *argv[])
 	printf("local_list: %s\n", bareConfigGetOptionValue(cfg, "local_list"));*/
 
 	LaymanAPI *l = laymanAPICreate(cfg, 0, 0);
-	/*if (0 == laymanAPIFetchRemoteList(l))
+	if (0 == laymanAPIFetchRemoteList(l))
 	{
 		printf("Unable to fetch the remote list.\n");
 		ret = -1;
-		goto finish;
-	}*/
+	}
 
 	StringList *strs = laymanAPIGetAvailable(l, 0);
 	printf("list:\n");
 	stringListPrint(strs);
-	
+
 	printf("\n");
 
 	unsigned int len = stringListCount(strs);
 	//OverlayInfo *infos = calloc(len, sizeof(OverlayInfo));
 	//int count = laymanAPIGetAllInfos(l, strs, infos);
 	
-	OverlayInfo *oi = laymanAPIGetAllInfo(l, "enlfdsightenment");
+	OverlayInfo *oi = laymanAPIGetAllInfo(l, "kuroo");
 	if (oi)
 	{
 		printf("%s\n~~~~~~~~~~~~~~~~~~~~\n", oi->name);
@@ -47,8 +46,8 @@ int main(int argc, char *argv[])
 		overlayInfoFree(*oi);
 		free(oi);
 	}
-
-	for (unsigned int i = 0; i < len; i++)
+	
+	/*for (unsigned int i = 0; i < len; i++)
 	{
 		OverlayInfo *oi = laymanAPIGetAllInfo(l, stringListGetAt(strs, i));
 		if (!oi)
@@ -57,15 +56,15 @@ int main(int argc, char *argv[])
 		printf("%s\n\n", oi->description);
 		overlayInfoFree(*oi);
 		free(oi);
-	}
+	}*/
 
 	printf("\n");
 
 	//free(infos);
+	stringListFree(strs);
 
 	bareConfigFree(cfg);
 	laymanAPIFree(l);
-	stringListFree(strs);
 
 	interpreterFinalize();
 



             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=82813ef426d1a17df69e4daf91c7fb862e4ab26c.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