#61
authoradam <anton@adamansky.com>
Tue, 30 Apr 2013 09:07:16 +0000 (16:07 +0700)
committeradam <anton@adamansky.com>
Tue, 30 Apr 2013 09:07:16 +0000 (16:07 +0700)
binding.gyp
luaejdb/luaejdb.c
node/ejdb_native.cc
pyejdb/setup.py
pyejdb/src/pejdb.c
tcejdb/configure.ac
tcejdb/ejdb.c
tcejdb/ejdb_private.h

index 6abedce..b76cca3 100644 (file)
@@ -6,14 +6,33 @@
     'target_defaults': {
         'configurations': {
             'Debug': {
+                'defines': [ '_DEBUG' ],
+                'msvs_settings': {
+                    'VCCLCompilerTool': {
+                      'RuntimeLibrary':'MultiThreadedDebugDLL'
+                    }
+                },
             },
             'Release':{
                 'defines': [ 'NDEBUG' ],
+                'msvs_settings': {
+                    'VCCLCompilerTool': {
+                      'RuntimeLibrary':'MultiThreadedDLL'
+                    }
+                }
             }
         },
         'conditions': [
             ['OS == "win"', {
-
+               'variables': {
+                  'EJDB_HOME%': 'C:/EJDB'
+               },
+               'defines': [
+                 '_UNICODE',
+               ],
+               'libraries': [
+                 '-l<(EJDB_HOME)/lib/tcejdbdll.lib'
+               ],
             }, {
                'defines': [
                  '_LARGEFILE_SOURCE',
                     '-lz -lpthread -lm -lc'
                 ]
             }],
-           [ 'OS=="mac"', {
-               'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
-               'cflags_cc!' : [ '-fno-exceptions' ],
-               'xcode_settings': {     
-                       'GCC_ENABLE_CPP_EXCEPTIONS':'YES',
-                       'OTHER_CFLAGS': [                               
-                               '-fsigned-char', '-pthread', '-Wno-variadic-macros', '-fexceptions'
-                       ],
-                       'OTHER_LDFLAGS': [
-                               '-Wl,-search_paths_first',
-                               '-L./tcejdb/static',                            
-                               '-lstcejdb -lz -lpthread -lm -lc'
-                       ]                                               
-               }
-            }]        
-         ],
+            [ 'OS=="mac"', {
+                'defines': ['_DARWIN_USE_64_BIT_INODE=1'],
+                'cflags_cc!' : [ '-fno-exceptions' ],
+                'xcode_settings': {
+                    'GCC_ENABLE_CPP_EXCEPTIONS':'YES',
+                    'OTHER_CFLAGS': [
+                        '-fsigned-char', '-pthread', '-Wno-variadic-macros', '-fexceptions'
+                        ],
+                    'OTHER_LDFLAGS': [
+                        '-Wl,-search_paths_first',
+                        '-L./tcejdb/static',
+                        '-lstcejdb -lz -lpthread -lm -lc'
+                    ]
+                }
+           }]
+        ],
         'include_dirs' : ['tcejdb'],
     },
 
index bbb1cda..9e3a72c 100644 (file)
@@ -52,24 +52,6 @@ static int set_ejdb_error(lua_State *L, EJDB *jb) {
     return luaL_error(L, emsg);
 }
 
-static bool ejcollockmethod(EJCOLL *coll, bool wr) {
-    assert(coll && coll->jb);
-    if (!coll->mmtx) return false;
-    if (wr ? pthread_rwlock_wrlock((pthread_rwlock_t*) coll->mmtx) != 0 : pthread_rwlock_rdlock((pthread_rwlock_t*) coll->mmtx) != 0) {
-        return false;
-    }
-    return (coll->tdb && coll->tdb->open);
-}
-
-static bool ejcollunlockmethod(EJCOLL *coll) {
-    assert(coll && coll->jb);
-    if (!coll->mmtx) return false;
-    if (pthread_rwlock_unlock((pthread_rwlock_t*) coll->mmtx) != 0) {
-        return false;
-    }
-    return true;
-}
-
 static EJDB *check_ejdb(lua_State *L, EJDB *jb) {
     if (jb == NULL) {
         luaL_error(L, "Closed EJDB database");
index 8ca0558..c06fff9 100644 (file)
 #include <vector>
 #include <sstream>
 #include <locale.h>
-#include <ext/hash_set>
 #include <stdint.h>
 
+#ifdef _WIN32
+#include <hash_set>
+#else
+#include <ext/hash_set>
+#endif
+
 using namespace node;
 using namespace v8;
 
@@ -48,25 +53,6 @@ static const int CMD_RET_ERROR = 1;
 
 namespace ejdb {
 
-    static bool ejcollockmethod(EJCOLL *coll, bool wr) {
-        assert(coll && coll->jb);
-        if (!coll->mmtx) return false;
-        if (wr ? pthread_rwlock_wrlock((pthread_rwlock_t*) coll->mmtx) != 0 : pthread_rwlock_rdlock((pthread_rwlock_t*) coll->mmtx) != 0) {
-            return false;
-        }
-        return (coll->tdb && coll->tdb->open);
-    }
-
-    static bool ejcollunlockmethod(EJCOLL *coll) {
-        assert(coll && coll->jb);
-        if (!coll->mmtx) return false;
-        if (pthread_rwlock_unlock((pthread_rwlock_t*) coll->mmtx) != 0) {
-            return false;
-        }
-        return true;
-    }
-
-
     ///////////////////////////////////////////////////////////////////////////
     //                           Some symbols                                //
     ///////////////////////////////////////////////////////////////////////////
index 679207d..c617c9e 100755 (executable)
@@ -85,7 +85,7 @@ def check_extension(ext):
             raise SystemExit(err_msg.format(ext.name, ext.min_ver, ext.url))
     return lib
 
-ejdb_ext = EJDBPythonExt(True, "tcejdb", "EJDB", "1.0.65",
+ejdb_ext = EJDBPythonExt(True, "tcejdb", "EJDB", "1.1.3",
                          "tcversion", "http://ejdb.org",
                          "_pyejdb", ["src/pyejdb.c"],
                          libraries=["tcejdb", "z", "pthread", "m", "c"],
@@ -99,7 +99,7 @@ class build_ext(_build_ext):
 
 setup(
     name="pyejdb",
-    version="1.0.4",
+    version="1.0.5",
     url="http://ejdb.org",
     keywords=["ejdb", "tokyocabinet", "nosql", "database", "storage", "embedded", "mongodb", "json"],
     description="Python3 binding for EJDB database engine.",
@@ -120,6 +120,7 @@ setup(
         "License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)",
         "Operating System :: POSIX",
         "Programming Language :: Python :: 3.2",
+        "Programming Language :: Python :: 3",
         "Topic :: Software Development :: Libraries"
     ],
     data_files = [("doc", ["README.md"])]
index 7473fd8..e656c1a 100644 (file)
@@ -179,7 +179,7 @@ static PyObject* EJDB_load(PEJDB *self, PyObject *args) {
     Py_BEGIN_ALLOW_THREADS
     doc = ejdbloadbson(coll, &oid);
     Py_END_ALLOW_THREADS
-    if (!doc) {            
+    if (!doc) {
         int ecode = ejdbecode(self->ejdb);
         if (ecode != TCESUCCESS && ecode != TCENOREC) {
             return set_ejdb_error(self->ejdb);
@@ -279,7 +279,7 @@ static PyObject* EJDB_dbmeta(PEJDB *self, PyObject *args) {
         goto fail;
     }
     for (int i = 0; i < TCLISTNUM(cols); ++i) {
-
+        bool locked = false;
         PyObject *pycoll = NULL;
         PyObject *pyindexes = NULL;
         PyObject *pyopts = NULL;
@@ -290,6 +290,10 @@ static PyObject* EJDB_dbmeta(PEJDB *self, PyObject *args) {
         if (!pycoll) {
             goto ffail;
         }
+        if (!ejcollockmethod(coll, false)) {
+            goto ffail;
+        }
+        locked = true;
         val = PyUnicode_FromStringAndSize(coll->cname, coll->cnamesz);
         PyDict_SetItemString(pycoll, "name", val);
         Py_XDECREF(val);
@@ -381,9 +385,16 @@ static PyObject* EJDB_dbmeta(PEJDB *self, PyObject *args) {
         Py_XDECREF(pyindexes);
 
         PyList_Append(carr, pycoll);
+        if (locked) {
+            ejcollunlockmethod(coll);
+            locked = false;
+        }
         continue;
 
 ffail:
+        if (locked) {
+            ejcollunlockmethod(coll);
+        }
         Py_XDECREF(pycoll);
         Py_XDECREF(pyindexes);
         Py_XDECREF(pyopts);
index 3da9f0a..34f04e7 100644 (file)
@@ -10,7 +10,7 @@ test -n "$CPPFLAGS" && MYCPPFLAGS="$CPPFLAGS $MYCPPFLAGS"
 test -n "$LDFLAGS" && MYLDFLAGS="$LDFLAGS $MYLDFLAGS"
 
 # Package name
-AC_INIT(tcejdb, 1.1.2)
+AC_INIT(tcejdb, 1.1.3)
 AC_CANONICAL_HOST
 
 # Package information
index 818a46f..f5c33b8 100644 (file)
@@ -76,11 +76,11 @@ typedef struct {
 /* private function prototypes */
 static void _ejdbsetecode(EJDB *jb, int ecode, const char *filename, int line, const char *func);
 static bool _ejdbsetmutex(EJDB *ejdb);
-static bool _ejdblockmethod(EJDB *ejdb, bool wr);
-static bool _ejdbunlockmethod(EJDB *ejdb);
-static bool _ejdbcolsetmutex(EJCOLL *coll);
-static bool _ejcollockmethod(EJCOLL *coll, bool wr);
-static bool _ejcollunlockmethod(EJCOLL *coll);
+EJDB_INLINE bool _ejdblockmethod(EJDB *ejdb, bool wr);
+EJDB_INLINE bool _ejdbunlockmethod(EJDB *ejdb);
+EJDB_INLINE bool _ejdbcolsetmutex(EJCOLL *coll);
+EJDB_INLINE bool _ejcollockmethod(EJCOLL *coll, bool wr);
+EJDB_INLINE bool _ejcollunlockmethod(EJCOLL *coll);
 static bson_type _bsonoidkey(bson *bs, bson_oid_t *oid);
 static char* _bsonitstrval(EJDB *jb, bson_iterator *it, int *vsz, TCLIST *tokens, txtflags_t flags);
 static char* _bsonipathrowldr(TCLIST *tokens, const char *pkbuf, int pksz, const char *rowdata, int rowdatasz,
@@ -819,7 +819,7 @@ static bool _ejdbsetmutex(EJDB *ejdb) {
    `tdb' specifies the table database object.
    `wr' specifies whether the lock is writer or not.
    If successful, the return value is true, else, it is false. */
-static bool _ejdblockmethod(EJDB *ejdb, bool wr) {
+EJDB_INLINE bool _ejdblockmethod(EJDB *ejdb, bool wr) {
     assert(ejdb);
     if (wr ? pthread_rwlock_wrlock(ejdb->mmtx) != 0 : pthread_rwlock_rdlock(ejdb->mmtx) != 0) {
         _ejdbsetecode(ejdb, TCETHREAD, __FILE__, __LINE__, __func__);
@@ -832,7 +832,7 @@ static bool _ejdblockmethod(EJDB *ejdb, bool wr) {
 /* Unlock a method of the table database object.
    `tdb' specifies the table database object.
    If successful, the return value is true, else, it is false. */
-static bool _ejdbunlockmethod(EJDB *ejdb) {
+EJDB_INLINE bool _ejdbunlockmethod(EJDB *ejdb) {
     assert(ejdb);
     if (pthread_rwlock_unlock(ejdb->mmtx) != 0) {
         _ejdbsetecode(ejdb, TCETHREAD, __FILE__, __LINE__, __func__);
@@ -842,7 +842,7 @@ static bool _ejdbunlockmethod(EJDB *ejdb) {
     return true;
 }
 
-static bool _ejdbcolsetmutex(EJCOLL *coll) {
+EJDB_INLINE bool _ejdbcolsetmutex(EJCOLL *coll) {
     assert(coll && coll->jb);
     if (coll->mmtx) {
         _ejdbsetecode(coll->jb, TCEINVALID, __FILE__, __LINE__, __func__);
@@ -859,7 +859,7 @@ static bool _ejdbcolsetmutex(EJCOLL *coll) {
     return true;
 }
 
-static bool _ejcollockmethod(EJCOLL *coll, bool wr) {
+EJDB_INLINE bool _ejcollockmethod(EJCOLL *coll, bool wr) {
     assert(coll && coll->jb);
     if (wr ? pthread_rwlock_wrlock(coll->mmtx) != 0 : pthread_rwlock_rdlock(coll->mmtx) != 0) {
         _ejdbsetecode(coll->jb, TCETHREAD, __FILE__, __LINE__, __func__);
@@ -869,7 +869,7 @@ static bool _ejcollockmethod(EJCOLL *coll, bool wr) {
     return (coll->tdb && coll->tdb->open);
 }
 
-static bool _ejcollunlockmethod(EJCOLL *coll) {
+EJDB_INLINE bool _ejcollunlockmethod(EJCOLL *coll) {
     assert(coll && coll->jb);
     if (pthread_rwlock_unlock(coll->mmtx) != 0) {
         _ejdbsetecode(coll->jb, TCETHREAD, __FILE__, __LINE__, __func__);
@@ -879,6 +879,14 @@ static bool _ejcollunlockmethod(EJCOLL *coll) {
     return true;
 }
 
+bool ejcollockmethod(EJCOLL *coll, bool wr) {
+    return _ejcollockmethod(coll, wr);
+}
+
+bool ejcollunlockmethod(EJCOLL *coll) {
+    return _ejcollunlockmethod(coll);
+}
+
 static void _qrydel(EJQ *q, bool freequery) {
     if (!q) {
         return;
index fc19870..99cc7e4 100644 (file)
@@ -23,7 +23,6 @@
 #include "tchdb.h"
 
 #include <assert.h>
-#include <pthread.h>
 
 EJDB_EXTERN_C_START
 
@@ -129,6 +128,10 @@ struct EJQ { /**> Query object. */
 
 #define JBINOPTMAPTHRESHOLD 16 /**> If number of tokens in `$in` array exeeds it then TCMAP will be used in fullscan matching of tokens */
 
+
+EJDB_EXPORT  bool ejcollockmethod(EJCOLL *coll, bool wr);
+EJDB_EXPORT  bool ejcollunlockmethod(EJCOLL *coll);
+
 EJDB_EXTERN_C_END
 
 #endif        /* EJDB_PRIVATE_H */