Commits

Anonymous committed 4f5c5c6

more cleanup

Comments (0)

Files changed (4)

capsule_test/opaque.c

-#include <Python.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static int counter = 0;
-
-typedef struct t_opaque {
-  char message[256];
-  int x;
-} opaque;
-
-static char *opaque_desc = "opaque";
-
-static PyObject *NotOpaqueObject;
-
-//void opaque_dest(PyObject *object) {
-  //opaque *obj = (opaque *) PyCapsule_GetPointer(object, "opaque");
-  //if (!obj)
-  //return 0; /* an exception is already set */
-//  free(obj);
-//}
-
-void opaque_dest(void *obj, void *desc) {
-  printf("destroying object with desc %s\n", desc);
-  free(obj);
-}
-
-static PyObject *new_opaque(PyObject *self, PyObject *args) {
-  char *str;
-  if (!PyArg_ParseTuple(args, "s", &str))
-    return 0;
-
-  opaque *z = malloc(sizeof(opaque));
-
-  strcpy(z->message, str);
-  z->x = counter++;
-
-  //return PyCapsuleNew(z, "opaque", opaque_dest);
-
-  return PyCObject_FromVoidPtrAndDesc(z, opaque_desc, opaque_dest);
-}
-
-static PyObject *show_opaque(PyObject *self, PyObject *args) {
-  PyObject *obj;
-  opaque *op;
-
-  if (!PyArg_ParseTuple(args, "O", &obj))
-    return 0;
-
-  //op = (opaque *) PyCapsule_GetPointer(obj, "opaque");
-  //if (!op)
-  //return 0;
-  
-  if (!PyCObject_Check(obj)) {
-    PyErr_SetString(NotOpaqueObject, "show_opaque requires an opaque object as its sole argument");
-    return 0;
-  }
-  
-  op = (opaque *) PyCObject_AsVoidPtr(obj);
-  printf("%d:%s\n", op->x, op->message);
-  Py_INCREF(Py_None);
-  return Py_None;
-}
-
-static PyMethodDef OpaqueMethods[] = {
-  {"new_opaque", new_opaque, METH_VARARGS,
-   "Create an opaque object containing a message."},
-  {"show_opaque", show_opaque, METH_VARARGS,
-   "Display the contents of an opaque object."},
-  {0, 0, 0, 0}
-};
-
-PyMODINIT_FUNC initopaque() {
-  PyObject *m;
-
-  m = Py_InitModule("opaque", OpaqueMethods);
-  if (!m)
-    return;
-
-  NotOpaqueObject = PyErr_NewException("opaque.NotOpaqueObject", 0, 0);
-  Py_INCREF(NotOpaqueObject);
-  PyModule_AddObject(m, "NotOpaqueObject", NotOpaqueObject);
-}
-
-int main(int argc, char *argv[]) {
-  Py_SetProgramName(argv[0]);
-  Py_Initialize();
-  initopaque();
-  return 0;
-}

capsule_test/setup.py

-from distutils.core import setup, Extension
-
-opaque = Extension('opaque',
-                   sources = ['opaque.c'])
-
-setup (name = 'Opaque',
-       version = '1.0',
-       description = 'Opaque objects test',
-       ext_modules = [opaque])
                     sources = ['pylibcb.c'])
 
 setup (name = 'pylibcb',
-       version = '0.1',
+       version = '0.1.1',
        description = 'Python Couchbase Client',
        author='Sebastian Hubbard',
        author_email='sebastian@chango.com',

sketch

-library functionality:
-
-create instance
-- python object holding opaque reference to libcouchbase_server and event_base
-
-connect to cluster
-- libcouchbase_create/connect wrapper
-
-set single key
-- support key expiry
-- support CAS optionally
-
-get single key
-- support timeout on get operation
-
-delete key
-- nothing fancy here
-
-
-in order to support these functions:
-
-every time an operation with a timeout is invoked, a ticket must be assigned
-to the operation and kept track of in a separate table. when libcouchbase_wait
-is invoked, either the operation will break the event loop first, or the 
-timeout will break the event loop first. when the operation returns, it will
-update its ticket item in the operation table to mark itself as having succeeded
-when the timeout returns, if there is nothing in the operation table to mark
-the operation for the given ticket number as having completed successfully, the
-operation will be marked as timeout.
-
-immediately after the libcouchbase_wait, the table will have the entry for the
-current ticket number checked, and return a timeout (throw a pylibcb exception)
-or return the value successfully immediately.
-
-ticket assignment and table updates must be atomic (a threadsafe library)
-
-when both operations have returned (maybe note this with a semaphore in
-the ticket table), the entry can be deleted
-
-a table size of 1 cannot be used in case multiple python processes hold onto
-the same library memory ?