[libgda] JDBC provider: improved the way C pointers are passed through JNI



commit 70222806edc7a387848756ddca2a6ba4bf44e514
Author: Vivien Malerba <malerba gnome-db org>
Date:   Tue Apr 30 20:54:50 2013 +0200

    JDBC provider: improved the way C pointers are passed through JNI

 configure.ac                        |    1 +
 providers/jdbc/GdaInputStream.c     |    8 ++--
 providers/jdbc/GdaJValue.c          |   60 +++++++++++++++++-----------------
 providers/jdbc/gda-jdbc-provider.c  |    6 ++--
 providers/jdbc/gda-jdbc-recordset.c |    8 ++--
 providers/jdbc/jni-wrapper.c        |   31 +++++++++++++++++-
 providers/jdbc/jni-wrapper.h        |    8 ++++-
 providers/jdbc/provider.java        |   10 ++++++
 8 files changed, 89 insertions(+), 43 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 84aad65..5e30fc9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -65,6 +65,7 @@ IT_PROG_INTLTOOL([0.40.6])
 AC_SUBST(INTLTOOL_XML_RULE)
 AC_CHECK_SIZEOF(unsigned int,0)
 AC_CHECK_SIZEOF(unsigned long int,0)
+AC_CHECK_SIZEOF([int *],0)
 AC_CHECK_TYPE(uint8_t, unsigned char)
 AC_CHECK_FUNCS(localtime_r localtime_s)
 AC_CHECK_HEADER(sys/mman.h,
diff --git a/providers/jdbc/GdaInputStream.c b/providers/jdbc/GdaInputStream.c
index 2a036ea..10beb57 100644
--- a/providers/jdbc/GdaInputStream.c
+++ b/providers/jdbc/GdaInputStream.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2010 David King <davidk openismus com>
  *
  * This library is free software; you can redistribute it and/or
@@ -36,7 +36,7 @@ JNIEXPORT jintArray
 JNICALL Java_GdaInputStream_readData (JNIEnv *jenv, G_GNUC_UNUSED jobject obj,
                                      jlong gda_blob_pointer, jlong offset, jlong size)
 {
-       GdaBlob *blob = (GdaBlob*) gda_blob_pointer;
+       GdaBlob *blob = (GdaBlob*) jni_jlong_to_cpointer (gda_blob_pointer);
        jintArray jdata;
        if (!blob) {
                jclass cls;
@@ -110,7 +110,7 @@ JNIEXPORT jbyteArray JNICALL
 Java_GdaInputStream_readByteData (JNIEnv *jenv, G_GNUC_UNUSED jobject obj,
                                      jlong gda_blob_pointer, jlong offset, jlong size)
 {
-       GdaBlob *blob = (GdaBlob*) gda_blob_pointer;
+       GdaBlob *blob = (GdaBlob*) jni_jlong_to_cpointer (gda_blob_pointer);
        jbyteArray jdata;
        if (!blob) {
                jclass cls;
@@ -159,7 +159,7 @@ Java_GdaInputStream_readByteData (JNIEnv *jenv, G_GNUC_UNUSED jobject obj,
                goto out;
        }
        
-       (*jenv)->SetByteArrayRegion (jenv, jdata, 0, real_size, raw_data);
+       (*jenv)->SetByteArrayRegion (jenv, jdata, 0, real_size, (const jbyte *) raw_data);
        if ((*jenv)->ExceptionCheck (jenv)) {
                jdata = NULL;
                (*jenv)->DeleteLocalRef (jenv, jdata);
diff --git a/providers/jdbc/GdaJValue.c b/providers/jdbc/GdaJValue.c
index c115ffb..80c9ee9 100644
--- a/providers/jdbc/GdaJValue.c
+++ b/providers/jdbc/GdaJValue.c
@@ -58,7 +58,7 @@ JNICALL Java_GdaJValue_initIDs (JNIEnv *env, jclass klass)
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCString (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer, jint col, 
jstring str)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gchar *tmp;
        gint len, ulen;
 
@@ -85,7 +85,7 @@ JNICALL Java_GdaJValue_getCString (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED job
 {
        const gchar *str;
        
-       str = g_value_get_string ((GValue *) c_pointer);
+       str = g_value_get_string ((GValue *) jni_jlong_to_cpointer (c_pointer));
        return (*jenv)->NewStringUTF (jenv, str);
 }
 
@@ -93,7 +93,7 @@ JNIEXPORT void
 JNICALL Java_GdaJValue_setCInt (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                jint col, jint i)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_INT);
        g_value_set_int (value, i);
 }
@@ -101,14 +101,14 @@ JNICALL Java_GdaJValue_setCInt (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobjec
 JNIEXPORT jint
 JNICALL Java_GdaJValue_getCInt (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jint) g_value_get_int ((GValue *) c_pointer);
+       return (jint) g_value_get_int ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCChar (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                 jint col, jbyte b)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_CHAR);
        g_value_set_schar (value, b);
 }
@@ -116,14 +116,14 @@ JNICALL Java_GdaJValue_setCChar (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobje
 JNIEXPORT jbyte
 JNICALL Java_GdaJValue_getCChar (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jbyte) g_value_get_schar ((GValue *) c_pointer);
+       return (jbyte) g_value_get_schar ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCDouble (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                   jint col, jdouble d)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_DOUBLE);
        g_value_set_double (value, d);
 }
@@ -131,14 +131,14 @@ JNICALL Java_GdaJValue_setCDouble (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED job
 JNIEXPORT jdouble
 JNICALL Java_GdaJValue_getCDouble (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jdouble) g_value_get_double ((GValue *) c_pointer);
+       return (jdouble) g_value_get_double ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCFloat (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                  jint col, jfloat f)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_FLOAT);
        g_value_set_float (value, f);
 }
@@ -146,14 +146,14 @@ JNICALL Java_GdaJValue_setCFloat (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobj
 JNIEXPORT jfloat
 JNICALL Java_GdaJValue_getCFloat (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jfloat) g_value_get_float ((GValue *) c_pointer);
+       return (jfloat) g_value_get_float ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCBoolean (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                    jint col, jboolean b)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_BOOLEAN);
        g_value_set_boolean (value, b);
 }
@@ -161,7 +161,7 @@ JNICALL Java_GdaJValue_setCBoolean (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jo
 JNIEXPORT jboolean
 JNICALL Java_GdaJValue_getCBoolean (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jboolean) g_value_get_boolean ((GValue *) c_pointer);
+       return (jboolean) g_value_get_boolean ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
@@ -172,7 +172,7 @@ JNICALL Java_GdaJValue_setCDate (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong
 
        date = g_date_new_dmy (day, month, year);
        if (g_date_valid (date)) {
-               GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+               GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
                gda_value_reset_with_type (value, G_TYPE_DATE);
                g_value_take_boxed (value, date);
        }
@@ -196,7 +196,7 @@ Java_GdaJValue_getCDate (JNIEnv *jenv, jobject obj, jlong c_pointer)
        const GDate *date;
        jobject jobj;
 
-       date = g_value_get_boxed ((GValue *) c_pointer);
+       date = g_value_get_boxed ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!date || ! g_date_valid (date)) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
@@ -228,7 +228,7 @@ JNICALL Java_GdaJValue_setCTime (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobje
        tim->minute = min;
        tim->second = sec;
 
-       value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, GDA_TYPE_TIME);
        g_value_take_boxed (value, tim);
 }
@@ -239,7 +239,7 @@ JNICALL Java_GdaJValue_getCTime (JNIEnv *jenv, jobject obj, jlong c_pointer)
        const GdaTime *tim;
        jobject jobj;
 
-       tim = g_value_get_boxed ((GValue *) c_pointer);
+       tim = g_value_get_boxed ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!tim) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
@@ -276,7 +276,7 @@ JNICALL Java_GdaJValue_setCTimestamp (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED
        ts->minute = min;
        ts->second = sec;
 
-       value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, GDA_TYPE_TIMESTAMP);
        g_value_take_boxed (value, ts);
 }
@@ -287,7 +287,7 @@ JNICALL Java_GdaJValue_getCTimestamp (JNIEnv *jenv, jobject obj, jlong c_pointer
        const GdaTimestamp *ts;
        jobject jobj;
 
-       ts = g_value_get_boxed ((GValue *) c_pointer);
+       ts = g_value_get_boxed ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!ts) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
@@ -323,7 +323,7 @@ JNICALL Java_GdaJValue_setCBinary (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlon
        bin->data = g_new (guchar, len);
        (*jenv)->GetByteArrayRegion(jenv, bytes, 0, len, (jbyte *) bin->data);
 
-       value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, GDA_TYPE_BINARY);
        g_value_take_boxed (value, bin);
 }
@@ -334,7 +334,7 @@ JNICALL Java_GdaJValue_getCBinary (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlon
        const GdaBinary *bin;
        jbyteArray jbytes;
 
-       bin = g_value_get_boxed ((GValue *) c_pointer);
+       bin = g_value_get_boxed ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!bin) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
@@ -365,9 +365,9 @@ JNICALL Java_GdaJValue_setCBlob (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong
        GValue *value;
 
        blob = g_new0 (GdaBlob, 1);
-       blob->op = gda_jdbc_blob_op_new_with_jblob (GDA_CONNECTION ((gpointer) cnc_c_pointer), jenv, blobop);
+       blob->op = gda_jdbc_blob_op_new_with_jblob (GDA_CONNECTION (jni_jlong_to_cpointer (cnc_c_pointer)), 
jenv, blobop);
 
-       value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, GDA_TYPE_BLOB);
        g_value_take_boxed (value, blob);
 }
@@ -377,7 +377,7 @@ JNICALL Java_GdaJValue_getCBlob (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong
 {
        const GdaBlob *blob;
 
-       blob = g_value_get_boxed ((GValue *) c_pointer);
+       blob = g_value_get_boxed ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!blob) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
@@ -409,7 +409,7 @@ JNICALL Java_GdaJValue_getCBlob (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong
                        (*jenv)->ThrowNew (jenv, cls, _("Can't get BLOB's size"));
                        return NULL;
                }
-               retobj = (*jenv)->NewObject (jenv, GdaInputStream__class, mid, (jlong) blob,
+               retobj = (*jenv)->NewObject (jenv, GdaInputStream__class, mid, jni_cpointer_to_jlong (blob),
                                             (jlong) size);
                if ((*jenv)->ExceptionCheck (jenv))
                        return NULL;
@@ -443,7 +443,7 @@ JNICALL Java_GdaJValue_getCBlob (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCLong (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer, 
jint col, jlong l)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_INT64);
        g_value_set_int64 (value, l);
 }
@@ -451,14 +451,14 @@ JNICALL Java_GdaJValue_setCLong (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobje
 JNIEXPORT jshort
 JNICALL Java_GdaJValue_getCLong (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jlong) g_value_get_int64 ((GValue *) c_pointer);
+       return (jlong) g_value_get_int64 ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
 JNICALL Java_GdaJValue_setCShort (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer,
                                  jint col, jshort s)
 {
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gda_value_reset_with_type (value, G_TYPE_INT64);
        gda_value_set_short (value, s);
 }
@@ -466,7 +466,7 @@ JNICALL Java_GdaJValue_setCShort (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobj
 JNIEXPORT jshort
 JNICALL Java_GdaJValue_getCShort (G_GNUC_UNUSED JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
-       return (jshort) gda_value_get_short ((GValue *) c_pointer);
+       return (jshort) gda_value_get_short ((GValue *) jni_jlong_to_cpointer (c_pointer));
 }
 
 JNIEXPORT void
@@ -474,7 +474,7 @@ JNICALL Java_GdaJValue_setCNumeric (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlo
                                    jstring str, jint precision, jint scale)
 {
        GdaNumeric *num;
-       GValue *value = gda_row_get_value (GDA_ROW ((gpointer) c_pointer), col);
+       GValue *value = gda_row_get_value (GDA_ROW (jni_jlong_to_cpointer (c_pointer)), col);
        gchar *tmp;
        gint len, ulen;
 
@@ -504,7 +504,7 @@ JNIEXPORT jobject
 JNICALL Java_GdaJValue_getCNumeric (JNIEnv *jenv, G_GNUC_UNUSED jobject obj, jlong c_pointer)
 {
        const GdaNumeric *num;
-       num = gda_value_get_numeric ((GValue *) c_pointer);
+       num = gda_value_get_numeric ((GValue *) jni_jlong_to_cpointer (c_pointer));
        if (!num) {
                jclass cls;
                cls = (*jenv)->FindClass (jenv, "java/lang/IllegalArgumentException");
diff --git a/providers/jdbc/gda-jdbc-provider.c b/providers/jdbc/gda-jdbc-provider.c
index dcbfabe..1ae5360 100644
--- a/providers/jdbc/gda-jdbc-provider.c
+++ b/providers/jdbc/gda-jdbc-provider.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 - 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2008 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  * Copyright (C) 2010 David King <davidk openismus com>
  *
@@ -1153,10 +1153,10 @@ gda_jdbc_provider_statement_prepare (GdaServerProvider *provider, GdaConnection
                        g_slist_free (param_ids);
                        goto out;
                }
-               
+
                GValue *jexec_res;
                jexec_res = jni_wrapper_method_call (jenv, GdaJPStmt__declareParamTypes,
-                                                    pstmt_obj, NULL, NULL, error, (jlong) cnc, jtypes);
+                                                    pstmt_obj, NULL, NULL, error, jni_cpointer_to_jlong 
(cnc), jtypes);
                (*jenv)->DeleteLocalRef (jenv, jtypes);
                g_free (ctypes);
                
diff --git a/providers/jdbc/gda-jdbc-recordset.c b/providers/jdbc/gda-jdbc-recordset.c
index 182903e..ef35fab 100644
--- a/providers/jdbc/gda-jdbc-recordset.c
+++ b/providers/jdbc/gda-jdbc-recordset.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  * Copyright (C) 2010 David King <davidk openismus com>
  * Copyright (C) 2011 Murray Cumming <murrayc murrayc com>
@@ -383,9 +383,9 @@ gda_jdbc_recordset_new (GdaConnection *cnc, GdaJdbcPStmt *ps, GdaSet *exec_param
                gda_value_free (rs_value);
                return NULL;
        }
-       
+
        jexec_res = jni_wrapper_method_call (jenv, GdaJResultSet__declareColumnTypes,
-                                            rs_value, &error_code, &sql_state, &error, (jlong) cnc, jtypes);
+                                            rs_value, &error_code, &sql_state, &error, jni_cpointer_to_jlong 
(cnc), jtypes);
        (*jenv)->DeleteLocalRef (jenv, jtypes);
        g_free (ctypes);
        
@@ -430,7 +430,7 @@ fetch_next_jdbc_row (GdaJdbcRecordset *model, JNIEnv *jenv, gboolean do_store, G
 
        jexec_res = jni_wrapper_method_call (jenv, GdaJResultSet__fillNextRow,
                                             model->priv->rs_value, &error_code, &sql_state, &lerror,
-                                            (jlong) prow);
+                                            jni_cpointer_to_jlong (prow));
        if (!jexec_res) {
                if (error && lerror)
                        *error = g_error_copy (lerror);
diff --git a/providers/jdbc/jni-wrapper.c b/providers/jdbc/jni-wrapper.c
index f8f808f..144b8ae 100644
--- a/providers/jdbc/jni-wrapper.c
+++ b/providers/jdbc/jni-wrapper.c
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 - 2011 Murray Cumming <murrayc murrayc com>
- * Copyright (C) 2008 - 2012 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
  * Copyright (C) 2009 Bas Driessen <bas driessen xobas com>
  *
  * This library is free software; you can redistribute it and/or
@@ -1136,3 +1136,32 @@ gda_jni_object_free (gpointer boxed)
        }
        g_free (jnio);
 }
+
+jlong
+jni_cpointer_to_jlong (gconstpointer c_pointer)
+{
+       jlong retval;
+
+#if SIZEOF_INT_P == 4
+       gint32 i32;
+       i32 = (gint32) c_pointer;
+       retval = i32;
+#else
+       retval = (jlong) c_pointer;
+#endif
+       return retval;
+}
+
+gconstpointer
+jni_jlong_to_cpointer (jlong value)
+{
+       gconstpointer retval;
+#if SIZEOF_INT_P == 4
+       gint32 i32;
+       i32 = (gint32) value;
+       retval = (gconstpointer) i32;
+#else
+       retval = (gconstpointer) value;
+#endif
+       return retval;
+}
diff --git a/providers/jdbc/jni-wrapper.h b/providers/jdbc/jni-wrapper.h
index 79bbbf5..1dfc6fa 100644
--- a/providers/jdbc/jni-wrapper.h
+++ b/providers/jdbc/jni-wrapper.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008 - 2011 Vivien Malerba <malerba gnome-db org>
+ * Copyright (C) 2008 - 2013 Vivien Malerba <malerba gnome-db org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -27,6 +27,12 @@
 #define __JNI_WRAPPER__
 
 /*
+ * Conversion method
+ */
+jlong             jni_cpointer_to_jlong (gconstpointer c_pointer);
+gconstpointer     jni_jlong_to_cpointer (jlong value);
+
+/*
  * general functions
  */
 typedef jint (*CreateJavaVMFunc) (JavaVM **, void **, void *);
diff --git a/providers/jdbc/provider.java b/providers/jdbc/provider.java
index 9634890..90c70e1 100644
--- a/providers/jdbc/provider.java
+++ b/providers/jdbc/provider.java
@@ -3,6 +3,16 @@ import java.util.*;
 import java.io.*;
 
 /*
+ * Note:
+ * This provider invokes JNI in the following way: a C API calls some Java code through JNI, which in turn 
calls
+ * some C code as native method. To exchange pointers, the C pointers are converted to the "long" java type, 
which is mapped
+ * to the "jlong" C type which is always 64 bits long, refer to 
http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/types.html
+ *
+ * In C code, when passing a C pointer to a method, it needs to be converted to a jlong, and the 
jni_cpointer_to_jlong()
+ * function must be used.
+ */
+
+/*
  * This class will be instantiated once for each GdaJdbcProvider created.
  */
 class GdaJProvider {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]