From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tom Jakubowski Newsgroups: gmane.lisp.guile.user Subject: dynamic-ffi: Responsibility for freeing returned pointers? Date: Fri, 10 Nov 2017 21:06:33 +0000 Message-ID: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1510348028 32546 195.159.176.226 (10 Nov 2017 21:07:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Fri, 10 Nov 2017 21:07:08 +0000 (UTC) To: "guile-user@gnu.org" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Nov 10 22:07:05 2017 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eDGW0-0008Ct-Jy for guile-user@m.gmane.org; Fri, 10 Nov 2017 22:07:04 +0100 Original-Received: from localhost ([::1]:43501 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDGW6-00086N-DV for guile-user@m.gmane.org; Fri, 10 Nov 2017 16:07:10 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:33994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eDGVj-00086I-RA for guile-user@gnu.org; Fri, 10 Nov 2017 16:06:48 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eDGVi-0004IX-O0 for guile-user@gnu.org; Fri, 10 Nov 2017 16:06:47 -0500 Original-Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:52617) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eDGVi-0004Hf-Al for guile-user@gnu.org; Fri, 10 Nov 2017 16:06:46 -0500 Original-Received: by mail-wm0-x236.google.com with SMTP id t139so5167648wmt.1 for ; Fri, 10 Nov 2017 13:06:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oblong.com; s=google; h=mime-version:from:date:message-id:subject:to; bh=kkhN0Kk33sIY/khW9wzUudt5hp/w/yiWvA7Yvr25z/c=; b=IpexFuV488GbQSFvf4IMQe+K+mBAT26Pyt+hA4wpT/BcDuIVsTALJBj7bRzxAG4mJy 7gu4dSVIgWQ4Hv56rgatZ7JFDayRCQQAg+95TvWmebqA7/x390uypEp6EaOLvFYPpefK WNtnMLsC9sI2LnF0n1qB2rHcdokiwJ3e/985w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=kkhN0Kk33sIY/khW9wzUudt5hp/w/yiWvA7Yvr25z/c=; b=pmrHGPKFamPYIVg+PwZAH7Dm8nwdObsr6erw26ykwosuqiE4P16BHqFPqbGsLMMan8 ZYk9epttEGo4QyHjdaQ1T5mPIvww3/NetC2jPZgMbnkLOy95ws5RYy3Uev9FI0JnOXnu +PEBEZdczjJhvQfuyLTIuWSRMZgyKwIizDFGyGc4hi7Upw0h+Qoti3wgEwEzT+TZJ2+0 TIUfsGhbC0bbcBYWMdR8kTDqsPesTNDZBKp1HI6KUrc0SOeHMGPOfntqxtg8WEKBDKgQ yEL56kbVSji+EwUstUdm5nXnTvMTWTl/yZSUg9hefByw14mlbBha4PNTB7tPb9eUK8Ty Hghg== X-Gm-Message-State: AJaThX7LzkJN2L42kmoMYlHgochDiDuCxv102seD/ky1ynsp0XItqioX 67tVwG8Yh2o6TOYEFYVPqX//nkualk6s6o4/1AiKhHHX X-Google-Smtp-Source: AGs4zMbtJIueaTA35u5fPb+BPB3shz7i5oo0JGJMJ8do5zHoLAAU9SnV3uvOjEgJZgiPsApfP60fHS9exzOmRn4yWOE= X-Received: by 10.28.129.77 with SMTP id c74mr1101027wmd.124.1510348004292; Fri, 10 Nov 2017 13:06:44 -0800 (PST) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 X-Content-Filtered-By: Mailman/MimeDel 2.1.21 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:14238 Archived-At: Hi! Say I have a C function like this: char *tom_hello() { return strdup("hello!"); } And, in Guile land, I make a procedure c-tom-hello out of it using dynamic-ffi and wrap it in a function that returns a Scheme string: (define exe (dynamic-link)) (define c-tom-hello (pointer->procedure '* (dynamic-func "tom_hello" exe) '()) (define (tom-hello) (let ((str (pointer->string c-tom-hello))) ;; free pointer? str)) My assumption (supported by reading strings.c, but not in any docs I can find) is that pointer->string makes a copy of the string it's passed. This leaves open the question of freeing the original string returned by the tom_hello() C function. Is the usual technique here to use dynamic-ffi to make a procedure that's bound to C's free(), and call that on the C string after making the Guile string from it? It seems like the obvious choice, I'd just like to be sure I'm not missing some higher level approach I should use instead. Thanks! Tom