diff --git a/core/String.carp b/core/String.carp index 881b9c6b..eec367c3 100644 --- a/core/String.carp +++ b/core/String.carp @@ -461,9 +461,13 @@ ) (defmodule Pointer - (register str (Fn [(Ptr a)] String) "Pointer_str") + (register strp (Fn [(Ptr a)] String) "Pointer_strp") + + (defn str [a] (Pointer.strp a)) (implements str Pointer.str) - (defn prn [a] (Pointer.str a)) + + (defn prn [a] (Pointer.strp a)) + (implements prn Pointer.prn) ) (defndynamic build-str* [forms] @@ -474,4 +478,4 @@ (list 'ref (list 'String.append (list 'ref (list 'str (car forms))) (build-str* (cdr forms))))))) (defmacro str* [:rest forms] - (list 'copy (build-str* forms))) \ No newline at end of file + (list 'copy (build-str* forms))) diff --git a/core/carp_string.h b/core/carp_string.h index b9251069..b291b02d 100644 --- a/core/carp_string.h +++ b/core/carp_string.h @@ -362,7 +362,7 @@ int String_index_MINUS_of(const String *s, char c) { return String_index_MINUS_of_MINUS_from(s, c, -1); } -String Pointer_str(void *in) { +String Pointer_strp(void *in) { int size = snprintf(NULL, 0, "%p", in) + 1; String buffer = CARP_MALLOC(size); sprintf(buffer, "%p", in); diff --git a/test/pointer.carp b/test/pointer.carp index 03cbe617..df561848 100644 --- a/test/pointer.carp +++ b/test/pointer.carp @@ -10,6 +10,12 @@ (defn ref-to-ptr [r] (the (Ptr a) (Unsafe.coerce (the (Ref a) r)))) +;; Just make sure the 'str' for a Pointer compiles +;; (testing out its contents is platform specific) +(defn pointer-to-str [] + (let [p (the (Ptr CChar) NULL)] + (str p))) + ; these tests are sadly a little unsafe (deftest test (assert-equal test @@ -42,5 +48,5 @@ (to-value (ref-to-ptr &123)) 123 "Pointer.to-value works as expected" - ) + ) )