Commits

Anonymous committed b880a75

tried to reach stability for strings containing NUL chars

  • Participants
  • Parent commits b4f5d30
  • Branches unstable

Comments (0)

Files changed (8)

 def utf8tounicode(str string):
     return string.decode('utf-8')
 
-cdef char *_escape_key(object key, list error):
+cdef void copy_from_map_to(TCMAP *_from, TCMAP *_to):
+    cdef void *_name, *_content
+    cdef int _name_len, _content_len
+    
+    tcmapiterinit(_from)
+    _name = tcmapiternext(_from, &_name_len)
+    while _name != NULL:
+        _content = tcmapget(_from, _name, _name_len, &_content_len)
+        tcmapput(_to, _name, _name_len, _content, _content_len)
+    
+cdef char *_escape_key(object key, list error, int *_size):
+    cdef char *_result
+    
     try:
         tmp, unesc = escape_key(key)
-        return tmp
+        PyString_AsStringAndSize(tmp, &_result, _size)
+        return _result
     except:
         error.extend(sys.exc_info())
         return NULL
     cdef object errlog = cargo[2]
 
     # create pythonic primary key
-    cdef str primkey = ps.PyString_FromStringAndSize(<constchar_p>pkbuf, <Py_ssize_t>pksiz) 
+    cdef str primkey = PyString_FromStringAndSize(<char*>pkbuf, pksiz) 
     cdef dict row = {}
+    cdef TCMAP *_row
     
     try:
         # load row
         ret = callback(primkey, row)
         
         if ret is row:
+            _row = table.dict2map(ret, table.last_error)
+            if not _row: table._last_error()
             tcmapclear(cols)
-            for key, value in table.escape_dict(ret).iteritems():
-                tcmapput2(cols, <char*>key, <char*>value)
+            copy_from_map_to(_row, cols)
+            tcmapdel(_row)
             return MODIFY
     
     except DeleteRow:            
     TCMAP *tcmapnew2(uint32)
     void tcmapdel(TCMAP*)
     void tcmapiterinit(TCMAP*)
-    char* tcmapiternext2(TCMAP*)
-    char* tcmapget2(TCMAP*, char*)
-    void tcmapput2(TCMAP*, char*, char*)
+    void *tcmapiternext(TCMAP *map, int *sp)
+    #char* tcmapiternext2(TCMAP*)
+    void *tcmapget(TCMAP *map, void *kbuf, int ksiz, int *sp)
+    #char* tcmapget2(TCMAP*, char*)
+    void tcmapput(TCMAP *map, void *kbuf, int ksiz, void *vbuf, int vsiz)
+    #void tcmapput2(TCMAP*, char*, char*)
     void tcmapclear(TCMAP*)
     
     # list handling
     TCMAP* tctdbget(TCTDB*, void*, int)
     
     # delete something from db
+    bint tctdbout(TCTDB*, void*, int)
     bint tctdbout2(TCTDB*, constchar_p)
     
     # number of rows
     uint64 tctdbrnum(TCTDB*)
     
     # existence of a primary key
+    int tctdbvsiz(TCTDB*, void*, int)
     int tctdbvsiz2(TCTDB*, constchar_p)
     
     # forward matching keys
+    TCLIST *tctdbfwmkeys(TCTDB *tdb, void *pbuf, int psiz, int max)
     TCLIST *tctdbfwmkeys2(TCTDB*, constchar_p, int)
     
     def has_key(self, primkey):
         cdef char* _primkey
-        cdef int keysize
+        cdef int _primkey_len, _value_len
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        keysize = tctdbvsiz2(self.db, _primkey)
-        if keysize: return keysize
+        _value_len = tctdbvsiz(self.db, <void*>_primkey, _primkey_len)
+        if _value_len > -1: return True
         else: return False
     
     # methods that *add* data
     # =======================
     def __setitem__(self, primkey, dict value):
         cdef char *_primkey
+        cdef int _primkey_len
+        cdef TCMAP *_map
+        
+        print "ok"
+        
+        _map = (<Table>self).dict2map(value, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
+        if _primkey == NULL: self._last_error()
+        
+        print "ok2"
+        print _primkey, _primkey_len
+        
+        try:
+            print "ok3"
+            if not tctdbput(self.db, <void*>_primkey, _primkey_len, _map):
+                print "ok4a"
+                #self._throw()
+                print "hier?"
+            else:
+                print "ok4b"
+        finally:
+            print "ok5"
+            tcmapdel(_map)
+            print "ok6"
+
+    def setdefault(self, primkey, dict value):
+        cdef char *_primkey
+        cdef int _primkey_len
         cdef TCMAP *_map
         
         _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
-        if _primkey == NULL: self._last_error()
-        
-        try:
-            if not tctdbput(self.db, _primkey, strlen(_primkey), _map): self._throw()
-        finally:
-            tcmapdel(_map)
-
-    def setdefault(self, primkey, dict value):
-        cdef char *_primkey
-        cdef TCMAP *_map
-        
-        _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
         if not _map:
             raise ValueError("Incompatible dictionary: each key must be one of (str, unicode, int, long, float)")       
         try:
-            if not tctdbputkeep(self.db, _primkey, strlen(_primkey), _map):
+            if not tctdbputkeep(self.db, <void*>_primkey, _primkey_len, _map):
                 self._throw()
         finally:
             tcmapdel(_map)
 
     def cat(self, primkey, dict value):
         cdef char *_primkey
+        cdef int _primkey_len
         cdef TCMAP *_map
         
         _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
         if not _map:
             raise ValueError("Incompatible dictionary: each key must be one of (str, unicode, int, long, float)")  
         try:
-            if not tctdbputcat(self.db, _primkey, strlen(_primkey), _map):
+            if not tctdbputcat(self.db, <void*>_primkey, _primkey_len, _map):
                 self._throw()
         finally:
             tcmapdel(_map)
     
     def modify(self, primkey, dict value):
-        cdef dict esc_value
         cdef char *_primkey
-        cdef TCMAP *_map
+        cdef int _primkey_len
+        cdef TCMAP *_map, *_value
 
-        _value = self.escape_dict(value)
-        
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        _map = tctdbget(self.db, _primkey, strlen(_primkey))
-        for k, v in _value.items(): tcmapput2(_map, k, v)
-        tctdbput(self.db, _primkey, strlen(_primkey), _map)
+        _value = (<Table>self).dict2map(value, self.last_error)
+        if _value == NULL: self._last_error()
+        
+        _map = tctdbget(self.db, <void*>_primkey, _primkey_len)
+        if not _map:
+            tcmapdel(_value)
+            raise KeyError(primkey)
+
+        try:
+            copy_from_map_to(_value, _map)
+            if not tctdbput(self.db, <void*>_primkey, _primkey_len, _map): self._throw()
+        finally:
+            tcmapdel(_value)
+            tcmapdel(_map)
     
     def __delitem__(self, primkey):
         cdef char *_primkey
+        cdef int _primkey_len
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        if not tctdbout2(self.db, _primkey):
+        if not tctdbout(self.db, _primkey, _primkey_len):
             raise KeyError(primkey)
     
     # methods that *retrieve* data
     def __getitem__(self, primkey):
         # declarations
         cdef char *_primkey 
+        cdef int _primkey_len
         cdef TCMAP *_map
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
-        
-        _map = tctdbget(self.db, _primkey, strlen(_primkey))
-        
+                
         # translate this map into a python dict
+        _map = tctdbget(self.db, _primkey, _primkey_len)
         if _map:
             return (<Table>self).map2dict(_map)
         else:
         except KeyError:
             return default
     
-    def _fetch(self, startswith, int limit, str mode):
-        cdef char *_startswith
+    def _fetch(LocalTable self, str startswith, int limit, str mode):
+        print "Okay!"
+        
+        cdef char *_startswith, *_primkey
+        cdef int _primkey_len
+        cdef int _startswith_len
+        cdef str key
+        
         cdef TCLIST *keylist
-        cdef TCMAP *map
-        cdef constchar_p primkey
+        cdef TCMAP *_map
         cdef int i, listlen, size = 0
         cdef list out = []  
         
-        _startswith = _escape_key(startswith, self.last_error)
+        _startswith = _escape_key(startswith, self.last_error, &_startswith_len)
         if _startswith == NULL: self._last_error()
         
-        keylist = tctdbfwmkeys2(self.db, _startswith, limit)
+        keylist = tctdbfwmkeys(self.db, <void*>_startswith, _startswith_len, limit)
         listlen = tclistnum(keylist)
         
         if mode == "keys":
             for i in range(listlen):
-                out.append(<constchar_p>tclistval(keylist, i, &size))
+                _primkey = <char*>tclistval(keylist, i, &_primkey_len)
+                key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                out.append(key)
         
         elif mode == "values":
             for i in range(listlen):
-                primkey = <constchar_p>tclistval(keylist, i, &size)
-                map = tctdbget(self.db, primkey, size)
-                if map != NULL:
-                    value = (<Table>self).map2dict(map)
-                    tcmapdel(map)
+                _primkey = <char*>tclistval(keylist, i, <int*>&_primkey_len)
+                _map = tctdbget(self.db, _primkey, _primkey_len)
+                if _map != NULL:
+                    value = (<Table>self).map2dict(_map)
+                    tcmapdel(_map)
                     out.append(value)
         
         elif mode == "items":
             for i in range(listlen):
-                primkey = <constchar_p>tclistval(keylist, i, &size)
-                map = tctdbget(self.db, primkey, size)
-                if map != NULL:
-                    value = (<Table>self).map2dict(map)
-                    tcmapdel(map)
-                    out.append((primkey, value))       
+                _primkey = <char*>tclistval(keylist, i, <int*>&_primkey_len)
+                _map = tctdbget(self.db, _primkey, _primkey_len)
+                if _map != NULL:
+                    key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                    value = (<Table>self).map2dict(_map)
+                    tcmapdel(_map)
+                    out.append((key, value))       
         
         tclistdel(keylist)
         return out
     cpdef list keys(self, str startswith = "", int limit = -1):
         return self._fetch(startswith, limit, "keys")
     
-    cpdef list values(self, key_startswith = "", int limit = -1):
+    cpdef list values(self, str key_startswith = "", int limit = -1):
         return self._fetch(key_startswith, limit, "values")
     
     cpdef list items(self, str key_startswith = "", int limit = -1):
         cdef TDBQRY **cqueries
         cdef Query query
         cdef TCLIST *rows
-        cdef constchar_p primkey
-        cdef TCMAP *map
+        cdef char *_primkey
+        cdef int _primkey_len
+        cdef TCMAP *_map
         
         # Type check: accept Query and Condition instances.
         # Throw an Exception for anything else.
         free(<void*>cqueries)
         
         # iter through all rows
-        for i in range(<int>tclistnum(rows)):
-            primkey = <constchar_p>tclistval(rows, i, &size)
-            map = tctdbget(self.db, primkey, size)
-            if map != NULL:
-                out = (<Table>self).map2dict(map)
-                tcmapdel(map)
-                outlist.append((primkey, out))
+        for i in range(tclistnum(rows)):
+            _primkey = <char*>tclistval(rows, i, <int*>&_primkey_len)
+            _map = tctdbget(self.db, _primkey, _primkey_len)
+            if _map != NULL:
+                key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                out = (<Table>self).map2dict(_map)
+                tcmapdel(_map)
+                outlist.append((key, out))
         tclistdel(rows)
         
         return outlist
 # tokyo tyrant (just the table api)
 # =================================
+cdef extern from "Python.h":
+    void PyString_AsStringAndSize(object string, char **buffer, int *size)
+    char * PyString_FromStringAndSize(char *string, int size)
+
 cdef extern from "tcrdb.h":
     cdef enum:
         RECORD_LOCKING "RDBXOLCKREC"
     uint64 tcrdbrnum(TCRDB*)
     
     # existence of a primary key
+    int tcrdbvsiz(TCRDB*, void*, int)
     int tcrdbvsiz2(TCRDB*, constchar_p)
     
     # forward matching keys
+    TCLIST *tcrdbfwmkeys(TCRDB *tdb, void *pbuf, int psiz, int max)
     TCLIST *tcrdbfwmkeys2(TCRDB*, constchar_p, int)
     
     def has_key(self, primkey):
         cdef char* _primkey
-        cdef int keysize
+        cdef int _primkey_len, _value_len
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        keysize = tcrdbvsiz2(self.db, _primkey)
-        if keysize: return keysize
+        _value_len = tcrdbvsiz(self.db, <void*>_primkey, _primkey_len)
+        if _value_len > -1: return True
         else: return False
     
     # methods that *add* data
     # =======================
     def __setitem__(self, primkey, dict value):
         cdef char *_primkey
+        cdef int _primkey_len
         cdef TCMAP *_map
         
         _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
         try:
-            if not tcrdbtblput(self.db, _primkey, strlen(_primkey), _map): self._throw()
+            if not tcrdbtblput(self.db, <void*>_primkey, _primkey_len, _map): self._throw()
         finally:
             tcmapdel(_map)
 
     def setdefault(self, primkey, dict value):
         cdef char *_primkey
+        cdef int _primkey_len
         cdef TCMAP *_map
         
         _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
         if not _map:
             raise ValueError("Incompatible dictionary: each key must be one of (str, unicode, int, long, float)")       
         try:
-            if not tcrdbtblputkeep(self.db, _primkey, strlen(_primkey), _map):
+            if not tcrdbtblputkeep(self.db, <void*>_primkey, _primkey_len, _map):
                 self._throw()
         finally:
             tcmapdel(_map)
 
     def cat(self, primkey, dict value):
         cdef char *_primkey
+        cdef int _primkey_len
         cdef TCMAP *_map
         
         _map = (<Table>self).dict2map(value, self.last_error)
-        if _map == NULL: self.last_error()
-        _primkey = _escape_key(primkey, self.last_error)
+        if _map == NULL: self._last_error()
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
         if not _map:
             raise ValueError("Incompatible dictionary: each key must be one of (str, unicode, int, long, float)")  
         try:
-            if not tcrdbtblputcat(self.db, _primkey, strlen(_primkey), _map):
+            if not tcrdbtblputcat(self.db, <void*>_primkey, _primkey_len, _map):
                 self._throw()
         finally:
             tcmapdel(_map)
     
     def modify(self, primkey, dict value):
-        cdef dict esc_value
         cdef char *_primkey
-        cdef TCMAP *_map
+        cdef int _primkey_len
+        cdef TCMAP *_map, *_value
 
-        _value = self.escape_dict(value)
-        
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        # todo: this approach isn't atomic for remote tables
-        # Use a lua extension later.
-        _map = tcrdbtblget(self.db, _primkey, strlen(_primkey))
-        for k, v in _value.items(): tcmapput2(_map, k, v)
-        tcrdbtblput(self.db, _primkey, strlen(_primkey), _map)
+        _value = (<Table>self).dict2map(value, self.last_error)
+        if _value == NULL: self._last_error()
+        
+        _map = tcrdbtblget(self.db, <void*>_primkey, _primkey_len)
+        if not _map:
+            tcmapdel(_value)
+            raise KeyError(primkey)
+
+        try:
+            copy_from_map_to(_value, _map)
+            if not tcrdbtblput(self.db, <void*>_primkey, _primkey_len, _map): self._throw()
+        finally:
+            tcmapdel(_value)
+            tcmapdel(_map)
     
     def __delitem__(self, primkey):
         cdef char *_primkey
+        cdef int _primkey_len
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        if not tcrdbtblout(self.db, _primkey, strlen(_primkey)):
+        if not tcrdbtblout(self.db, _primkey, _primkey_len):
             raise KeyError(primkey)
     
     # methods that *retrieve* data
     def __getitem__(self, primkey):
         # declarations
         cdef char *_primkey 
+        cdef int _primkey_len
         cdef TCMAP *_map
         
-        _primkey = _escape_key(primkey, self.last_error)
+        _primkey = _escape_key(primkey, self.last_error, &_primkey_len)
         if _primkey == NULL: self._last_error()
         
-        _map = tcrdbtblget(self.db, _primkey, strlen(_primkey))
-        
         # translate this map into a python dict
+        _map = tcrdbtblget(self.db, _primkey, _primkey_len)
         if _map:
             return (<Table>self).map2dict(_map)
         else:
             return default
     
     def _fetch(self, startswith, int limit, str mode):
-        cdef char *_startswith
+        cdef char *_startswith, *_primkey
+        cdef int _startswith_len, _primkey_len
+        cdef str key
+        
         cdef TCLIST *keylist
-        cdef TCMAP *map
-        cdef constchar_p primkey
+        cdef TCMAP *_map
         cdef int i, listlen, size = 0
         cdef list out = []  
         
-        _startswith = _escape_key(startswith, self.last_error)
+        _startswith = _escape_key(startswith, self.last_error, &_startswith_len)
         if _startswith == NULL: self._last_error()
         
-        keylist = tcrdbfwmkeys2(self.db, _startswith, limit)
+        keylist = tcrdbfwmkeys(self.db, <void*>_startswith, _startswith_len, limit)
         listlen = tclistnum(keylist)
         
         if mode == "keys":
             for i in range(listlen):
-                out.append(<constchar_p>tclistval(keylist, i, &size))
+                _primkey = <char*>tclistval(keylist, i, <int*>&_primkey_len)
+                key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                out.append(key)
         
         elif mode == "values":
             for i in range(listlen):
-                primkey = <constchar_p>tclistval(keylist, i, &size)
-                map = tcrdbtblget(self.db, primkey, size)
-                if map != NULL:
-                    value = (<Table>self).map2dict(map)
-                    tcmapdel(map)
+                _primkey = <char*>tclistval(keylist, i, <int*>&_primkey_len)
+                _map = tcrdbtblget(self.db, _primkey, _primkey_len)
+                if _map != NULL:
+                    value = (<Table>self).map2dict(_map)
+                    tcmapdel(_map)
                     out.append(value)
         
         elif mode == "items":
             for i in range(listlen):
-                primkey = <constchar_p>tclistval(keylist, i, &size)
-                map = tcrdbtblget(self.db, primkey, size)
-                if map != NULL:
-                    value = (<Table>self).map2dict(map)
-                    tcmapdel(map)
-                    out.append((primkey, value))       
+                _primkey = <char*>tclistval(keylist, i, <int*>&_primkey_len)
+                _map = tcrdbtblget(self.db, _primkey, _primkey_len)
+                if _map != NULL:
+                    key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                    value = (<Table>self).map2dict(_map)
+                    tcmapdel(_map)
+                    out.append((key, value))       
         
         tclistdel(keylist)
         return out
         cdef RDBQRY **cqueries
         cdef Query query
         cdef TCLIST *rows
-        cdef constchar_p primkey
-        cdef TCMAP *map
+        cdef char *_primkey
+        cdef int _primkey_len
+        cdef TCMAP *_map
         
         # Type check: accept Query and Condition instances.
         # Throw an Exception for anything else.
         free(<void*>cqueries)
         
         # iter through all rows
-        for i in range(<int>tclistnum(rows)):
-            primkey = <constchar_p>tclistval(rows, i, &size)
-            map = tcrdbtblget(self.db, primkey, size)
-            if map != NULL:
-                out = (<Table>self).map2dict(map)
-                tcmapdel(map)
-                outlist.append((primkey, out))
+        for i in range(tclistnum(rows)):
+            _primkey = <char*>tclistval(rows, i, <int*>&_primkey_len)
+            _map = tcrdbtblget(self.db, _primkey, _primkey_len)
+            if _map != NULL:
+                key = PyString_FromStringAndSize(_primkey, _primkey_len)
+                out = (<Table>self).map2dict(_map)
+                tcmapdel(_map)
+                outlist.append((key, out))
         tclistdel(rows)
         
         return outlist
     def extension(self, char *funcname, str key, str value, str locking = 'no'):
         cdef char *_key, *_value
         cdef void *_result
-        cdef Py_ssize_t _key_len, _value_len,
+        cdef int _key_len, _value_len,
         #cdef int _in_len, _out_len,
         cdef int _opts, _result_len
         cdef str result
         
         # convert python strings to c strings, which may contain 
         # NUL characters.
-        ps.PyString_AsStringAndSize(key, &_key, &_key_len)
-        ps.PyString_AsStringAndSize(value, &_value, &_value_len)
+        PyString_AsStringAndSize(key, &_key, &_key_len)
+        PyString_AsStringAndSize(value, &_value, &_value_len)
         
         # call the extension
-        _result = tcrdbext(self.db, funcname, _opts, <void*>_key, <int>_key_len,
-                           <void*>_value, <int>_value_len, &_result_len)
+        _result = tcrdbext(self.db, funcname, _opts, <void*>_key, _key_len,
+                           <void*>_value, _value_len, &_result_len)
         
         # handle errors
         if _result == NULL: self._throw()
         
         # convert the result to python
-        result = ps.PyString_FromStringAndSize(<char*>_result, <Py_ssize_t>_result_len)
+        result = PyString_FromStringAndSize(<char*>_result, _result_len)
         free(_result)
         
         return result
     
     cdef TCMAP *dict2map(self, dict value, list error):
         cdef dict esc_dict
-        cdef TCMAP *map_
+        cdef char *_name, *_value
+        cdef int _name_len = 0, _value_len = 0
+        cdef TCMAP *_map
         
         try:
             esc_dict = self.escape_dict(value)
+            _map = tcmapnew()
+            for k, v in value.items():
+                PyString_AsStringAndSize(k, &_name, &_name_len)
+                PyString_AsStringAndSize(v, &_value, &_value_len)
+                tcmapput(_map, <void*>_name, _name_len, <void*>_value, _value_len)
+            return _map
         except:
             error.extend(sys.exc_info())
             return NULL
         
-        map_ = tcmapnew()
-        for k, v in esc_dict.iteritems():
-            tcmapput2(map_, k, v)
-        return map_
+    cdef dict map2dict(self, TCMAP *_map):
+        cdef dict out = {}
+        cdef void *_key, *_value
+        cdef int _key_len = 0, _value_len = 0
+        cdef str key, value
         
-    cdef dict map2dict(self, TCMAP *map_):
-        cdef dict out = {}
-        cdef char* key
-        
-        tcmapiterinit(map_)
-        key = tcmapiternext2(map_)
-        while key != NULL:
-            out[key] = tcmapget2(map_, key)
-            key = tcmapiternext2(map_)
+        tcmapiterinit(_map)
+        _key = tcmapiternext(_map, &_key_len)
+        while _key != NULL:
+            _value = tcmapget(_map, _key, _key_len, &_value_len)
+            key = PyString_FromStringAndSize(<char*>_key, _key_len)
+            value = PyString_FromStringAndSize(<char*>_value, _value_len)
+            out[key] = value
+            _key = tcmapiternext(_map, &_key_len)
         
         return self.unescape_dict(out)

tests/test_queries.py

 from time import sleep
 
 import tokyotable
+table = t = tokyotable.LocalTable('test-queries.tct', 'w')
+#t['Timo'] = {'vorname': 'Timo', 'nachname': 'Stolz', 'alter': 25, 'stadt': u'Lörrach'}
+#t['Fred'] = {'vorname': 'Fred', 'nachname': 'Feuerstein', 'freund': u'Barnie Geröllheimer', 'alter': 45}
 
-table = t = tokyotable.LocalTable('test-queries.tct', 'w')
-t['Timo'] = {'vorname': 'Timo', 'nachname': 'Stolz', 'alter': 25, 'stadt': u'Lörrach'}
-t['Fred'] = {'vorname': 'Fred', 'nachname': 'Feuerstein', 'freund': u'Barnie Geröllheimer', 'alter': 45}
+#class TestQueries(unittest.TestCase):
+#    def test_numeric_range(self):
+#        condition = tokyotable.Column('alter').between(21, 36)
+#        result = dict(table.select(condition))
+#        self.assert_('Timo' in result and 'Fred' not in result)
+#    
+#    def test_modification_within_a_callback(self):
+#        def tag_as_young(key, value):
+#            value['altersgruppe'] = 'jung'
+#            #value[(1,2)] = 'tuples gehen nicht'
+#            return value
+#        
+#        condition = tokyotable.Column('alter').between(21, 36)
+#        table.call(condition, tag_as_young)
+#        self.assertEqual(table['Timo'], {'vorname': 'Timo', 'nachname': 'Stolz', 'alter': 25, 'stadt': u'Lörrach', 'altersgruppe': 'jung'})
 
-class TestQueries(unittest.TestCase):
-    def test_numeric_range(self):
-        condition = tokyotable.Column('alter').between(21, 36)
-        result = dict(table.select(condition))
-        self.assert_('Timo' in result and 'Fred' not in result)
-    
-    def test_modification_within_a_callback(self):
-        def tag_as_young(key, value):
-            value['altersgruppe'] = 'jung'
-            #value[(1,2)] = 'tuples gehen nicht'
-            return value
-        
-        condition = tokyotable.Column('alter').between(21, 36)
-        table.call(condition, tag_as_young)
-        self.assertEqual(table['Timo'], {'vorname': 'Timo', 'nachname': 'Stolz', 'alter': 25, 'stadt': u'Lörrach', 'altersgruppe': 'jung'})
+#suite = unittest.TestSuite()
+#suite.addTest(unittest.makeSuite(TestQueries))
 
-    
-suite = unittest.TestSuite()
-suite.addTest(unittest.makeSuite(TestQueries))
-
-if __name__ == '__main__':
-    unittest.main()
+#if __name__ == '__main__':
+#    unittest.main()