<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2002/07/362b26b59e19e369fc41bedf17213b18"
  from="Artem Prisyaznuk &lt;tema@s...&gt;"
  author="Artem Prisyaznuk"
  date="2002-07-07T09:19:50"
  subject="[Caml-list] Patch to ocaml-mysql"
  prev="2002/07/d1b9c9518820db66620939f4ea73e1a4"
  next="2002/07/f3f66088ad1575a8c6b10b09ffdfcded"
  next-in-thread="2002/07/7a6ee632d474fca6535ff230e8cf2e20"
  prev-thread="2002/07/061b98c60a3aae3e13a775ccfea73028"
  next-thread="2002/07/bc2a965ab496aafdf2907a6d9bf85822"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="[Caml-list] Patch to ocaml-mysql">
<msg 
  url="2002/07/362b26b59e19e369fc41bedf17213b18"
  from="Artem Prisyaznuk &lt;tema@s...&gt;"
  author="Artem Prisyaznuk"
  date="2002-07-07T09:19:50"
  subject="[Caml-list] Patch to ocaml-mysql">
<msg 
  url="2002/07/7a6ee632d474fca6535ff230e8cf2e20"
  from="Shawn Wagner &lt;shawnw@s...&gt;"
  author="Shawn Wagner"
  date="2002-07-07T19:16:37"
  subject="Re: [Caml-list] Patch to ocaml-mysql">
</msg>
</msg>
</thread>

<contents>
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..." &gt;&amp;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&lt;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 &lt; 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

</contents>

</message>

