]> git.ipfire.org Git - people/ms/libloc.git/commitdiff
python: Only use global loc context
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 13:00:24 +0000 (13:00 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 29 Dec 2017 13:00:24 +0000 (13:00 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/as.c
src/python/database.c

index 83aea345bf607f4685d1d22acd0d44477d64a91d..4aad074fc653add9c7aab9d06ec2d74475f9ff76 100644 (file)
 #include <loc/as.h>
 #include <loc/stringpool.h>
 
+#include "locationmodule.h"
 #include "as.h"
 
 static PyObject* AS_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
-       // Create libloc context
-       struct loc_ctx* ctx;
-       int r = loc_new(&ctx);
-       if (r)
-               return NULL;
-
        // Create stringpool
        struct loc_stringpool* pool;
-       r = loc_stringpool_new(ctx, &pool);
-       if (r) {
-               loc_unref(ctx);
+       int r = loc_stringpool_new(loc_ctx, &pool);
+       if (r)
                return NULL;
-       }
 
        ASObject* self = (ASObject*)type->tp_alloc(type, 0);
        if (self) {
-               self->ctx = ctx;
+               self->ctx = loc_ref(loc_ctx);
                self->pool = pool;
        }
 
index c29d912b00de4c10de1a82fb12b0e5303b31d537..e38256bfd7db0198a6eaabc7ab3fad8ed82e9210 100644 (file)
 #include <loc/libloc.h>
 #include <loc/database.h>
 
+#include "locationmodule.h"
 #include "database.h"
 
 static PyObject* Database_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
-       // Create libloc context
-       struct loc_ctx* ctx;
-       int r = loc_new(&ctx);
-       if (r)
-               return NULL;
-
        DatabaseObject* self = (DatabaseObject*)type->tp_alloc(type, 0);
        if (self) {
-               self->ctx = ctx;
+               self->ctx = loc_ref(loc_ctx);
        }
 
        return (PyObject*)self;