1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-22 03:30:22 +02:00

string->pointer and pointer->string have optional encoding arg

* test-suite/tests/foreign.test ("pointer<->string"): Add test cases.

* libguile/foreign.c (scm_string_to_pointer, scm_pointer_to_string): Add
  optional encoding, and in the pointer->string case, length arguments.

* libguile/foreign.h: Update prototypes of internal functions.
  Shouldn't affect ABI as they are internal.

* doc/ref/api-foreign.texi (Void Pointers and Byte Access): Update
  docs.
This commit is contained in:
Andy Wingo 2011-04-01 13:31:26 +02:00
parent 13a78b0fd7
commit c6b08d2194
4 changed files with 90 additions and 26 deletions

View file

@ -626,20 +626,22 @@ Assuming @var{pointer} points to a memory region that holds a pointer,
return this pointer.
@end deffn
@deffn {Scheme Procedure} string->pointer string
@deffn {Scheme Procedure} string->pointer string [encoding]
Return a foreign pointer to a nul-terminated copy of @var{string} in the
current locale encoding. The C string is freed when the returned
foreign pointer becomes unreachable.
given @var{encoding}, defaulting to the current locale encoding. The C
string is freed when the returned foreign pointer becomes unreachable.
This is the Scheme equivalent of @code{scm_to_locale_string}.
This is the Scheme equivalent of @code{scm_to_stringn}.
@end deffn
@deffn {Scheme Procedure} pointer->string pointer
Return the string representing the C nul-terminated string
pointed to by @var{pointer}. The C string is assumed to be
in the current locale encoding.
@deffn {Scheme Procedure} pointer->string pointer [length] [encoding]
Return the string representing the C string pointed to by @var{pointer}.
If @var{length} is omitted or @code{-1}, the string is assumed to be
nul-terminated. Otherwise @var{length} is the number of bytes in memory
pointed to by @var{pointer}. The C string is assumed to be in the given
@var{encoding}, defaulting to the current locale encoding.
This is the Scheme equivalent of @code{scm_from_locale_string}.
This is the Scheme equivalent of @code{scm_from_stringn}.
@end deffn
@cindex wrapped pointer types