MySQL and guile

Hal Roberts (hroberts@alumni.princeton.edu)
Sun, 15 Mar 1998 22:44:56 +0000

Hey all.

I've been working on a custom scheme implentatin for a year so, off and
on, but it appears guile will do everything I need, so it looks like
I'll just use guile instead of continuing development on my project.

As part of that project, I had implemented a scheme interface to the
mySQL db engine. I spent last night porting this interface to guile, and
everything went pretty smooth until I tried to use the interface to do a
really big query.

A few details. I'm running RH5.0 Linux with guile 1.2. The sql
interface basically works by putting the retrieved data into a matrix.
The first row of the matrix holds the names of the fields, and the
remaining rows hold the data. For relatively small queries, the program
works great, but when I get to around 5,000 vector elements, gh_vector
seg faults badly enough that the core returns garbage for all the frames
under the gh_vector call. Here's the relevant bit of code:

scm_fields = gh_vector(gh_int2scm(num_fields), gh_list(SCM_EOL));
/* code for filling up field vector snipped*/

/* fill up a vector with vectors of the retrieved data */
-> scm_rows = gh_vector(gh_int2scm(num_rows + 1), gh_list(SCM_EOL));
gh_vset(scm_rows, gh_int2scm(0), scm_fields);
for (r = 0; r < num_rows; r++) {
row = mysql_fetch_row(res);
-> scm_data = gh_vector(gh_int2scm(num_fields), gh_list(SCM_EOL));
/* create a row of data */
for (f = 0; f < num_fields; f++) {
gh_vset(scm_data, gh_int2scm(f),
gh_sql2scm(row, gh_sql_field_types, f));
}
gh_vset(scm_rows, gh_int2scm(r + 1), scm_data);
}

The two lines with arrows are where the program crashes. If I do a
really big query (~ 100,000 rows), it just crashes on the first marked
line. If I do a moderately large query (~1,000 rows), it crashes on the
second marked line after looping ~800 times. I've tried the function
with and without the SCM_DEFER_INT ... SCM_ALLOW_INT calls, in case the
mysql stuff is interacting goofily with the guile stuff, but that didn't
make any difference.

Is there some sort of limit on the size of guile vectors ? Am I
blatantly misusing the guile functions ?

-hal