Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Patch to ocaml-mysql
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Artem Prisyaznuk <tema@s...>
Subject: [Caml-list] Patch to ocaml-mysql
Hello 

I found in  Ocaml-MySql binding 0.1.1 some bugs. 
It broken garbage collector,
because it's not correct operate with Ocaml/C interface.
If during working program, GC run major cycle, program 
don't working properly after what. 

It's problem explained here: 

	http://caml.inria.fr/archives/200002/msg00065.html

I change some part of code, now it's working Ok.

Diff output like this:


diff -u -r ocaml-mysql-0.1.1/configure ocaml-mysql-0.1.2/configure
--- ocaml-mysql-0.1.1/configure	Mon Apr 22 22:38:01 2002
+++ ocaml-mysql-0.1.2/configure	Tue Jul  2 15:56:46 2002
@@ -2173,6 +2173,7 @@
 echo "$as_me: checking for MySQL libraries..." >&6;}
 dirs="/usr/local/lib/mysql
       /usr/local/mysql/lib
+	  /usr/local/mysql/lib/mysql
       /usr/local/lib
       /usr/lib
       /usr/lib/mysql"
diff -u -r ocaml-mysql-0.1.1/ocmysql.c ocaml-mysql-0.1.2/ocmysql.c
--- ocaml-mysql-0.1.1/ocmysql.c	Mon May  6 02:15:39 2002
+++ ocaml-mysql-0.1.2/ocmysql.c	Fri Jul  5 10:42:17 2002
@@ -99,8 +99,8 @@
     v = alloc_string(length);
     memcpy(String_val(v), s, length);
     
-    res = alloc_small(1,SOME);
-    Field(res,0) = v; 
+    res = alloc(1,SOME);
+    Store_field(res,0,v); 
   }
   CAMLreturn(res);
 }
@@ -116,8 +116,8 @@
   CAMLlocal2(res, v);
         
   v = some;
-  res = alloc_small(1,SOME);
-  Field(res,0) = v;
+  res = alloc(1,SOME);
+  Store_field(res,0,v);
 
   CAMLreturn(res);
 }
@@ -175,8 +175,8 @@
       mysqlfailwith(mysql_error(init));
     } else {
       res = alloc_final(3, conn_finalize, 100,1000);
-      Store_field(res, 1, (value)mysql);
-      Store_field(res, 2, Val_true);
+      Field(res, 1) =  (value)mysql;
+      Field(res, 2) = Val_true;
     }
   }
   CAMLreturn(res);
@@ -224,15 +224,13 @@
   dbs = alloc_tuple(n); /* Array */
   i = 0;
   while ((row = mysql_fetch_row(res)) != NULL) {
-    CAMLlocal1(s);
-    s = copy_string(row[0]);
-    Store_field(dbs, i, s);
+    Store_field(dbs, i, copy_string(row[0]));
     i++;
   }
 
   mysql_free_result(res);
-  out = alloc_small(1, SOME);
-  Field(out, 0) = dbs;
+  out = alloc(1, SOME);
+  Store_field(out, 0, dbs);
   CAMLreturn(out);
 
 }
@@ -259,8 +257,8 @@
   CAMLparam1(dbd);
   check_dbd(dbd,"disconnect");
   mysql_close(DBDmysql(dbd));
-  Store_field(dbd, 1, Val_false);
-  Store_field(dbd, 2, Val_false); /* Mark closed */
+  Field(dbd, 1) = Val_false;
+  Field(dbd, 2) = Val_false; /* Mark closed */
   CAMLreturn0;
 }
 
@@ -313,7 +311,7 @@
     
   } else {
     res = alloc_final(2, res_finalize, 1, 20);    
-    Store_field(res, 1, (value) mysql_store_result(DBDmysql(dbd)));
+    Field(res, 1) = ((value) mysql_store_result(DBDmysql(dbd)));
   }
 
   CAMLreturn(res);
@@ -354,9 +352,7 @@
   length = mysql_fetch_lengths(res);      /* length[] */
   fields = alloc_tuple(n);                    /* array */
   for (i=0;i<n;i++) {
-    CAMLlocal1(s);
-    s = val_str_option(row[i], length[i]);
-    Store_field(fields, i, s);
+    Store_field(fields, i, val_str_option(row[i], length[i]));
   }
   
   CAMLreturn(val_some(fields));
@@ -456,13 +452,13 @@
   else
     size = (int64)(mysql_num_rows(res));
   
-  return copy_int64(size);
+  CAMLreturn(copy_int64(size));
 }
 
 EXTERNAL value
 db_affected(value dbd) {
   CAMLparam1(dbd);
-  return copy_int64(mysql_affected_rows(DBDmysql(dbd)));
+  CAMLreturn(copy_int64(mysql_affected_rows(DBDmysql(dbd))));
 }
 
 EXTERNAL value
@@ -653,12 +649,10 @@
 
   f = mysql_fetch_fields(res);
   for (i = 0; i < n; i++) {
-    CAMLlocal1(fi);
-    fi = make_field(f + i);
-    Store_field(f, i, fi);
+    Store_field(fields, i, make_field(f + i) );
   }
 
-  out = alloc_small(1, SOME);
-  Field(out, SOME) = fields;
+  out = alloc(1, SOME);
+  Store_field(out, SOME, fields);
   CAMLreturn(out);
 }

-- 
Artem Prisyaznuk
tema@sit.kiev.ua
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners