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 231BF7EE5B for ; Mon, 8 Apr 2013 15:42:21 +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=209.85.215.175; 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 209.85.215.175 as permitted sender) identity=mailfrom; client-ip=209.85.215.175; 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-ea0-f175.google.com) identity=helo; client-ip=209.85.215.175; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="matthieu.dubuget@gmail.com"; x-sender="postmaster@mail-ea0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhYCAE/IYlHRVdevlGdsb2JhbABRgz3BJ4EHFg4BAQEBBw0JCRQEJIIgAQUnCwEFCAEbHAIDDAYFCxYWDwkDAgECARERAQUBHAYNCAEBh30BAw8EnmKML4J7hA8KGScNWYh+AQUMjx6DQQOWdIYDiSk/hDA X-IPAS-Result: AhYCAE/IYlHRVdevlGdsb2JhbABRgz3BJ4EHFg4BAQEBBw0JCRQEJIIgAQUnCwEFCAEbHAIDDAYFCxYWDwkDAgECARERAQUBHAYNCAEBh30BAw8EnmKML4J7hA8KGScNWYh+AQUMjx6DQQOWdIYDiSk/hDA X-IronPort-AV: E=Sophos;i="4.87,432,1363129200"; d="scan'208";a="12295819" Received: from mail-ea0-f175.google.com ([209.85.215.175]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 08 Apr 2013 15:42:20 +0200 Received: by mail-ea0-f175.google.com with SMTP id r16so2269620ead.6 for ; Mon, 08 Apr 2013 06:42:20 -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 :references:in-reply-to:content-type:content-transfer-encoding; bh=Lj+NJ1KAHXjBAWZqvfVTxX4y85a6QvJsLUcwaj8ZuUM=; b=k9k70qcOKtvN7xazMHJjGcRnXavoilMzWaGHJ32IDBGm+geJXHjfAChsblwZ5rf1jk rnX9mwT0I/XpW/n3pGFsh87Q1dQF/zXnMMFWHpQSdCk3IrlLR2OHg5xMJI+jv583qMem 7OYohzvtIUxCuU6IZ+scOcKBPtv1o/NTfzjzzp0sdgRuguyGuypO79HlSzfSMFUC2604 CKc5IjaT4HokfTKiU0JrhLuUQc22CQ++suLQ6H4ggblDyUw2BRi/830N3Cmkh5KIEATa lU8RpuyfUfhoInRhBL00ue6JHBBqg2uH/V3UhfGEWLrpoep5Nc1UiSR41aFcd6zTiZCw xOnQ== X-Received: by 10.14.183.198 with SMTP id q46mr49421708eem.1.1365428539992; Mon, 08 Apr 2013 06:42:19 -0700 (PDT) Received: from [172.17.1.30] (papillon.metalscan.fr. [93.95.58.150]) by mx.google.com with ESMTPS id bc1sm32124342eeb.11.2013.04.08.06.42.19 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Apr 2013 06:42:19 -0700 (PDT) Message-ID: <5162C940.9050507@gmail.com> Date: Mon, 08 Apr 2013 15:42:24 +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 References: <5162C483.2040409@gmail.com> In-Reply-To: <5162C483.2040409@gmail.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit Subject: [Caml-list] Re: Is this C-binding correct? Matthieu Dubuget a écrit : > Thanks for your advices > This second try, using another function seems safer to me. But… is it? #include "mdbtools.h" #include #include #include value add_line(value datas, MdbHandle *mdb, MdbTableDef *table, char **bound_values){ CAMLparam1(datas); CAMLlocal2(my_line,new_datas); int i; MdbColumn *col; char *va; size_t length; /* Allocation d’un tableau */ my_line = caml_alloc(table->num_cols, 0); for (i=0; inum_cols; i++){ 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); CAMLreturn(new_datas); } __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; 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)) datas = add_line(datas, mdb, table, bound_values); 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); }