From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 879077EE51 for ; Mon, 8 Apr 2013 15:22:08 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of matthieu.dubuget@gmail.com) identity=pra; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="matthieu.dubuget@gmail.com"; x-sender="matthieu.dubuget@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of matthieu.dubuget@gmail.com designates 74.125.83.50 as permitted sender) identity=mailfrom; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="matthieu.dubuget@gmail.com"; x-sender="matthieu.dubuget@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ee0-f50.google.com) identity=helo; client-ip=74.125.83.50; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="matthieu.dubuget@gmail.com"; x-sender="postmaster@mail-ee0-f50.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhUCAGLDYlFKfVMyk2dsb2JhbABRgz3CLhYOAQEBAQcLCwkUBCSCTQsBBQgBGxwCAxIQFhYYAwIBAgEREQEFASINCAEBh30BAw8EnACCcowvgnuEDgoZJw1ZiH4BBQySXwOWdIYDiSk/hDA X-IPAS-Result: AhUCAGLDYlFKfVMyk2dsb2JhbABRgz3CLhYOAQEBAQcLCwkUBCSCTQsBBQgBGxwCAxIQFhYYAwIBAgEREQEFASINCAEBh30BAw8EnACCcowvgnuEDgoZJw1ZiH4BBQySXwOWdIYDiSk/hDA X-IronPort-AV: E=Sophos;i="4.87,431,1363129200"; d="scan'208";a="12291712" Received: from mail-ee0-f50.google.com ([74.125.83.50]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 08 Apr 2013 15:22:08 +0200 Received: by mail-ee0-f50.google.com with SMTP id e53so2396236eek.9 for ; Mon, 08 Apr 2013 06:22:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:message-id:date:from:user-agent:mime-version:to:subject :content-type:content-transfer-encoding; bh=RkomiAPioBdF3dh9j0vBVEvyL6TC+zdhHdj3osZh2g8=; b=HgV7PjEznZrdvD3b52vw6Yzpg7VImFAudzK9Vb9/ttATN/0aIn2VwL278FHo6DKgVO 5Njt5nEvt9pVoRVpGnzcqnT33gTqqpZGqzc5445oc8RDFZJu/z4jZXq7A3u14q6Qyu7v OHylLgcFEwfnuiVEj6Znm4YhJItP7n/RFssiOt80XrTQ/IkMAkgsP6nF0iVGFHCCcHJi SewjzuMW/R6m6TRAjnvHY+RNG2yGSqc095yC6YxM6UjX/2k9hQnIa85wloSTZDIxR0Yu errdCQIcsi6HoTil1/Nqqv3mgIO1jS5ffl0DoVVx5zz76ZTJEZt7Fw4fhOSuIuys22ys fmUw== X-Received: by 10.14.183.198 with SMTP id q46mr49246576eem.1.1365427327606; Mon, 08 Apr 2013 06:22:07 -0700 (PDT) Received: from [172.17.1.30] (papillon.metalscan.fr. [93.95.58.150]) by mx.google.com with ESMTPS id f47sm32014592eep.13.2013.04.08.06.22.06 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Apr 2013 06:22:06 -0700 (PDT) Message-ID: <5162C483.2040409@gmail.com> Date: Mon, 08 Apr 2013 15:22:11 +0200 From: Matthieu Dubuget User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2 MIME-Version: 1.0 To: caml-list Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: [Caml-list] Is this C-binding correct? Hello, I'm playing with some access datafile. I just need to read some data from a small database. There is a C library mdbtools, that allow to read them. This C library is using glib. Here is the C binding I wrote. It seems to works, but I'm not sure this interface is correct. Especially the "datas = new_datas;" line. Thanks for your advices Matt The ML part: external ex : string -> string -> string array list = "mdb_extract" And the C one: #include "mdbtools.h" #include #include #include __declspec(dllexport) value mdb_extract(value base, value tbl){ CAMLparam2(base, tbl); CAMLlocal3(datas, new_datas, my_line); MdbHandle *mdb; MdbTableDef *table; char **bound_values; int *bound_lens; char *va; size_t length; int i; mdb = mdb_open(String_val(base), MDB_NOFLAGS); table = mdb_read_table_by_name(mdb, String_val(tbl), MDB_TABLE); mdb_read_columns(table); mdb_rewind_table(table); bound_values = (char **) g_malloc(table->num_cols * sizeof(char *)); bound_lens = (int *) g_malloc(table->num_cols * sizeof(int)); for (i=0;inum_cols;i++){ bound_values[i] = (char *)g_malloc0(MDB_BIND_SIZE); mdb_bind_column(table, i+1, bound_values[i], &bound_lens[i]); }; /* Liste vide */ datas = Val_int(0); while (mdb_fetch_row(table)){ /* Allocation d’un tableau */ my_line = caml_alloc(table->num_cols, 0); for (i=0; inum_cols; i++){ MdbColumn *col = g_ptr_array_index(table->columns,i); if (col->col_type == MDB_OLE){ va = mdb_ole_read_full(mdb, col, &length); } else { va = bound_values[i]; }; Store_field(my_line, i, caml_copy_string(va)); if (col->col_type == MDB_OLE) free(va); } new_datas = caml_alloc(2,0); Store_field(new_datas, 0, my_line); Store_field(new_datas, 1, datas); datas = new_datas; } for (i=0;inum_cols;i++) { g_free(bound_values[i]); } g_free(bound_values); g_free(bound_lens); mdb_free_tabledef(table); mdb_close(mdb); CAMLreturn(datas); }