unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: KAction@gnu.org
To: guile-devel@gnu.org
Cc: Dmitry Bogatov <KAction@gnu.org>
Subject: [PATCH 20/25] Document with-pointer macro
Date: Mon, 18 Jul 2016 18:17:43 +0300	[thread overview]
Message-ID: <1468855068-7029-21-git-send-email-KAction@gnu.org> (raw)
In-Reply-To: <1468855068-7029-1-git-send-email-KAction@gnu.org>

From: Dmitry Bogatov <KAction@gnu.org>

---
 doc/ref/api-foreign.texi | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/doc/ref/api-foreign.texi b/doc/ref/api-foreign.texi
index 6b0e34c..7114225 100644
--- a/doc/ref/api-foreign.texi
+++ b/doc/ref/api-foreign.texi
@@ -1140,6 +1140,54 @@ As demonstrated by example, values can be arbitrary, but in most common
 each value have only one bit set.
 @end deffn
 
+Often, when working with C functions, you will have to work with output
+arguments. Usually, following macro can make life easier.
+
+@deffn {Scheme Macro} with-pointer bindings foreign-statement body
+This macro establishes bindings, that are pointers, when evaluating
+@code{foreign-statement} and are decoded Scheme values, when evaluating
+@code{body}. Every binding have one of following forms
+@enumerate
+@item
+@code{(type name = value)} -- encode @code{value} according to
+@code{<foreign-type>} record @code{type} and bind @code{name} to pointer
+to encoded value in @code{foreign-statement} and bind @code{name} to
+value, decoded back according to @code{type} in @code{body}. This form
+is used for input-output arguments.
+
+@item
+@code{(type name)} -- same as previous, but value, pointed by
+@code{name} in @code{foreign-statement} is unspecified. This form is
+used for output-only argument. For example, previously mentioned
+@code{ask-time} procedure can be defined as following:
+@example
+(define ask-time
+  (let ()
+    (define-foreign-function c-time ((*: t)) :: long:)
+    (lambda ()
+      (with-pointer ((long: t))
+        (c-time t)
+       t))))
+@end example
+
+@item
+With form @code{(name *--> bytevector)} @code{name} points to memory,
+underlying of @code{bytevector} in @code{foreign-statement}, with
+possibility to change it in-place. In @code{body} @code{name} refers to
+@code{bytevector}, probably modified. This form is used for input-output
+string or raw memory C functions arguments.
+
+@item
+Form @code{(name *--> length)} behaves same, as previous, but uses newly
+created bytevector of size @code{length}. This form is used for
+output-only string or raw memory C functions arguments.
+@end enumerate
+
+If @code{foreign-statement} has form @code{(name = expr)}, @code{name}
+will be bound to value of @code{expr} during evaluation of @code{body}.
+Otherwise value of @code{foreign-statement} is lost.
+@end deffn
+
 @c Local Variables:
 @c TeX-master: "guile.texi"
 @c End:
-- 
I may be not subscribed. Please, keep me in carbon copy.




  parent reply	other threads:[~2016-07-18 15:17 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-18 15:17 Foreign-declarative module KAction
2016-07-18 15:17 ` [PATCH 01/25] New module: system/foreign/declarative.scm KAction
2016-07-18 15:17 ` [PATCH 02/25] Define <ffi-type> structure KAction
2016-07-18 17:41   ` Nala Ginrut
2016-07-18 17:59     ` Dmitry Bogatov
2017-03-10  4:46       ` Thien-Thi Nguyen
2017-03-12  6:00         ` Dmitry Bogatov
2016-07-18 15:17 ` [PATCH 03/25] Mirror types from system/foreign as <foreign-type> KAction
2016-07-18 15:17 ` [PATCH 04/25] Write boilerplate for primitive types KAction
2016-07-18 15:17 ` [PATCH 05/25] Fix bug in `default' macro KAction
2016-07-18 15:17 ` [PATCH 06/25] Basic implementation of `define-foreign-function' KAction
2016-07-18 15:17 ` [PATCH 07/25] Introduce foreign-type predicates KAction
2016-07-18 15:17 ` [PATCH 08/25] Add keywords for `define-foreign-function' macro KAction
2016-07-18 15:17 ` [PATCH 09/25] system/foreign/declarative: rename `predicate' to `validate' KAction
2016-07-18 15:17 ` [PATCH 10/25] Refactor type validation in `define-foreign-function' KAction
2016-07-18 15:17 ` [PATCH 11/25] system/foreign/declarative: new macro KAction
2016-07-18 15:17 ` [PATCH 12/25] Improve deriving c symbol name from scheme one KAction
2016-07-18 15:17 ` [PATCH 13/25] system/foreign/declarative.scm: export string foreign type KAction
2016-07-18 15:17 ` [PATCH 14/25] foreign/declarative: mirror more primitive types KAction
2016-07-18 15:17 ` [PATCH 15/25] New macro: with-pointer KAction
2016-07-18 15:17 ` [PATCH 16/25] Configure emacs file-local indention KAction
2016-07-18 15:17 ` [PATCH 17/25] system/foreign/declarative: unexport internal macro KAction
2016-07-18 15:17 ` [PATCH 18/25] write documentation for (system foreign declarative) KAction
2016-07-18 19:41   ` Amirouche Boubekki
2016-07-18 20:11     ` Dmitry Bogatov
2016-07-19 14:41       ` Taylan Ulrich Bayırlı/Kammer
2016-07-19 15:12         ` Dmitry Bogatov
2016-07-18 15:17 ` [PATCH 19/25] Document define-foreign-bitmask macro KAction
2016-07-18 15:17 ` KAction [this message]
2016-07-18 15:17 ` [PATCH 21/25] new module: (ice-9 xattr) KAction
2016-07-18 15:17 ` [PATCH 22/25] ice-9/xattr: implement `xattr-get' function KAction
2016-07-18 15:17 ` [PATCH 23/25] Do not throw exception on missing xattr KAction
2016-07-18 15:17 ` [PATCH 24/25] Refactor defining foreign libattr function KAction
2016-07-18 15:17 ` [PATCH 25/25] ice9/attr: implement xattr-list procedure KAction
2017-03-09 20:33   ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1468855068-7029-21-git-send-email-KAction@gnu.org \
    --to=kaction@gnu.org \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).