]> git.ipfire.org Git - people/ms/libloc.git/blobdiff - src/python/as.c
python: Access ASes from database
[people/ms/libloc.git] / src / python / as.c
index 83aea345bf607f4685d1d22acd0d44477d64a91d..a28727d6f36d1de1aed3f8249e28a0b5b845a33a 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;
+PyObject* new_as(PyTypeObject* type, struct loc_as* as) {
+       ASObject* self = (ASObject*)type->tp_alloc(type, 0);
+       if (self) {
+               self->as = loc_as_ref(as);
+       }
 
+       return (PyObject*)self;
+}
+
+static PyObject* AS_new(PyTypeObject* type, PyObject* args, PyObject* kwds) {
        // 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;
        }