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 1RBYYW-0003m0-Hf for garchives@archives.gentoo.org; Wed, 05 Oct 2011 20:59:08 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 75D2921C267; Wed, 5 Oct 2011 20:56:56 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2EC9521C266 for ; Wed, 5 Oct 2011 20:56:56 +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 A964B1B4045 for ; Wed, 5 Oct 2011 20:56:55 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id 0690B8004B for ; Wed, 5 Oct 2011 20:56:55 +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: <82813ef426d1a17df69e4daf91c7fb862e4ab26c.dol-sen@gentoo> Subject: [gentoo-commits] proj/layman:master commit in: src/ X-VCS-Repository: proj/layman X-VCS-Files: src/config.c src/laymanapi.c src/stringlist.c src/tester.c X-VCS-Directories: src/ X-VCS-Committer: dol-sen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 82813ef426d1a17df69e4daf91c7fb862e4ab26c Date: Wed, 5 Oct 2011 20:56:55 +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: 3ffa37f4cd61ab6ee9c6a03372a55f76 commit: 82813ef426d1a17df69e4daf91c7fb862e4ab26c Author: Detlev Casanova gmail com> AuthorDate: Mon Jul 19 09:59:44 2010 +0000 Commit: Brian Dolbec gmail com> CommitDate: Mon Jul 19 09:59:44 2010 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/layman.git;a=3D= commit;h=3D82813ef4 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" =20 +#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); =20 if (!obj) + { + debug("The execution failed, Are you sure app-portage/layman-8888 is p= roperly installed ?\n"); return NULL; + } =20 BareConfig *ret =3D malloc(sizeof(BareConfig)); ret->object =3D 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" =20 -int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, OverlayInf= o *results, const char *overlay); +static int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* overlays, Ove= rlayInfo *results, const char *overlay); =20 struct LaymanAPI { @@ -16,8 +16,13 @@ struct LaymanAPI */ LaymanAPI* laymanAPICreate(BareConfig* config, int report_error, int out= put) { - assert(NULL !=3D config); - PyObject *obj =3D executeFunction("layman.api", "LaymanAPI", "Oii", _ba= reConfigObject(config), report_error, output); + PyObject *cfg; + if (!config) + cfg =3D Py_None; + else + cfg =3D _bareConfigObject(config); + + PyObject *obj =3D executeFunction("layman.api", "LaymanAPI", "Oii", cfg= , report_error, output); if (!obj) return NULL; =20 @@ -42,7 +47,7 @@ int laymanAPIIsRepo(LaymanAPI *l, const char* repo) =20 Py_DECREF(obj); =20 - return !ret; + return ret; } =20 int laymanAPIIsInstalled(LaymanAPI *l, const char* repo) @@ -60,7 +65,7 @@ int laymanAPIIsInstalled(LaymanAPI *l, const char* repo= ) =20 Py_DECREF(obj); =20 - return !ret; + return ret; } =20 /* @@ -114,13 +119,13 @@ int laymanAPISync(LaymanAPI* l, const char* overlay= , int verbose) return 0; =20 int ret =3D PyObject_IsTrue(obj); -=09 + // ret must be 1 or 0 assert(-1 !=3D ret); -=09 + Py_DECREF(obj); -=09 - return !ret; + + return ret; } =20 /* @@ -141,7 +146,7 @@ int laymanAPIFetchRemoteList(LaymanAPI* l) =09 Py_DECREF(obj); =20 - return !ret; + return ret; } =20 /* @@ -207,9 +212,9 @@ int laymanAPIGetInfoStrList(LaymanAPI* l, StringList*= overlays, OverlayInfo* res assert(NULL !=3D tmp); results[k].text =3D strdup(tmp); =20 - results[k].official =3D !PyObject_IsTrue(official); + results[k].official =3D PyObject_IsTrue(official); assert(-1 !=3D results[k].official); - results[k].supported =3D !PyObject_IsTrue(supported); + results[k].supported =3D PyObject_IsTrue(supported); assert(-1 !=3D results[k].supported); =20 k++; @@ -381,9 +386,9 @@ int _laymanAPIGetAllInfos(LaymanAPI* l, StringList* o= verlays, OverlayInfo *resul results[k].srcUris =3D listToCList(srcUris); =20 // If official or supported is neither True or False, abort. - results[k].official =3D !PyObject_IsTrue(official); + results[k].official =3D PyObject_IsTrue(official); assert(-1 !=3D results[k].official); - results[k].supported =3D !PyObject_IsTrue(supported); + results[k].supported =3D PyObject_IsTrue(supported); assert(-1 !=3D results[k].supported); =20 k++; @@ -408,14 +413,14 @@ int laymanAPIAddRepo(LaymanAPI* l, const char *repo= ) =20 // Call the method PyObject *obj =3D PyObject_CallMethod(l->object, "delete_repos", "(s)",= repo); -=09 + // If the call returned NULL, it failed. int ret; if (!obj) ret =3D 0; else ret =3D 1; -=09 + Py_DECREF(obj); =20 return ret; @@ -437,14 +442,14 @@ int laymanAPIAddRepoList(LaymanAPI* l, StringList *= repos) // Call the method PyObject *obj =3D PyObject_CallMethod(l->object, "add_repos", "(O)", py= repos); Py_DECREF(pyrepos); -=09 + // If the call returned NULL, it failed. int ret; if (!obj) ret =3D 0; else ret =3D 1; -=09 + Py_DECREF(obj); =20 return ret; @@ -462,14 +467,14 @@ int laymanAPIDeleteRepo(LaymanAPI* l, const char *r= epo) =20 // Call the method PyObject *obj =3D PyObject_CallMethod(l->object, "delete_repos", "(s)",= repo); -=09 + // If the call returned NULL, it failed. int ret; if (!obj) ret =3D 0; else ret =3D 1; -=09 + Py_DECREF(obj); =20 return ret; @@ -487,18 +492,18 @@ int laymanAPIDeleteRepoList(LaymanAPI* l, StringLis= t *repos) =20 // Converting the C list to a python list PyObject *pyrepos =3D cListToPyList(repos); -=09 + // Call the method PyObject *obj =3D PyObject_CallMethod(l->object, "delete_repos", "(O)",= pyrepos); Py_DECREF(pyrepos); -=09 + // If the call returned NULL, it failed. int ret; if (!obj) ret =3D 0; else ret =3D 1; -=09 + Py_DECREF(obj); =20 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; }; =20 +// 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 =3D malloc(sizeof(StringList)); @@ -17,6 +19,10 @@ StringList* stringListCreate(size_t len) return ret; } =20 +/* + * 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; } =20 +/* + * 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; } =20 +/* + * Returns the String at position pos + */ char* stringListGetAt(StringList *l, unsigned int pos) { if (!l || !l->list || pos >=3D l->count) @@ -42,6 +54,9 @@ char* stringListGetAt(StringList *l, unsigned int pos) return l->list[pos]; } =20 +/* + * 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) =20 for (unsigned int i =3D 0; i < len; i++) { + //Item are copied so that the PyObject can be deleted after the call w= ithout + //destroying the data in the returned list. PyObject *elem =3D PyList_GetItem(list, i); ret->list[i] =3D malloc(sizeof(char) * (PyBytes_Size(elem) + 1)); strcpy(ret->list[i], PyBytes_AsString(elem)); @@ -62,6 +79,9 @@ StringList* listToCList(PyObject* list) return ret; } =20 +/* + * 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; } =20 +/* + * Prints a C String list. + */ void stringListPrint(StringList* list) { if (!list) @@ -84,16 +107,17 @@ void stringListPrint(StringList* list) for(unsigned int i =3D 0; i < list->count; i++) { printf("\"%s\"", list->list[i]); + // No coma after the last item. if (i < list->count - 1) printf(", "); } } =20 +/* + * Frees a string list and it's data + */ void stringListFree(StringList* list) { - if (!list) - return; - if (list && list->list) { for(unsigned int i =3D 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"))= ;*/ =20 LaymanAPI *l =3D laymanAPICreate(cfg, 0, 0); - /*if (0 =3D=3D laymanAPIFetchRemoteList(l)) + if (0 =3D=3D laymanAPIFetchRemoteList(l)) { printf("Unable to fetch the remote list.\n"); ret =3D -1; - goto finish; - }*/ + } =20 StringList *strs =3D laymanAPIGetAvailable(l, 0); printf("list:\n"); stringListPrint(strs); -=09 + printf("\n"); =20 unsigned int len =3D stringListCount(strs); //OverlayInfo *infos =3D calloc(len, sizeof(OverlayInfo)); //int count =3D laymanAPIGetAllInfos(l, strs, infos); =09 - OverlayInfo *oi =3D laymanAPIGetAllInfo(l, "enlfdsightenment"); + OverlayInfo *oi =3D 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 =3D 0; i < len; i++) +=09 + /*for (unsigned int i =3D 0; i < len; i++) { OverlayInfo *oi =3D 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); - } + }*/ =20 printf("\n"); =20 //free(infos); + stringListFree(strs); =20 bareConfigFree(cfg); laymanAPIFree(l); - stringListFree(strs); =20 interpreterFinalize(); =20