Re: [Chicken-hackers] [PATCH] Make tests work from symlinked paths

2013-05-25 Thread Moritz Heidkamp
Mario Domenech Goulart mario.goul...@gmail.com writes:
 Ah good catch, but unfortunately OpenBSD does not expose realpath
 as a shell command (or binary utility). Is there a way to do this
 portably? John, do you know?

 Maybe readlink -f ?

Thanks, that works, as well! Attached is an updated patch.

Moritz
From 2c9bbb077165ffc171411376a0f68e6ba6adf9f2 Mon Sep 17 00:00:00 2001
From: Moritz Heidkamp mor...@twoticketsplease.de
Date: Sat, 25 May 2013 01:46:02 +0200
Subject: [PATCH] Make tests work from symlinked paths

The private repository path tests didn't work when run from inside a
path containing symlinks because runtests.sh didn't expand symlinks
while the -private-repository mechanism does. This lead the test
assertion which compares the two paths to fail.
---
 tests/runtests.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tests/runtests.sh b/tests/runtests.sh
index 931e2f2..6a1d0e3 100755
--- a/tests/runtests.sh
+++ b/tests/runtests.sh
@@ -389,8 +389,8 @@ $compile -e embedded3.c embedded4.scm
 echo  private repository test ...
 mkdir -p tmp
 $compile private-repository-test.scm -private-repository -o tmp/xxx
-tmp/xxx $PWD/tmp
-PATH=$PWD/tmp:$PATH xxx $PWD/tmp
+tmp/xxx `readlink -f -- $PWD`/tmp
+PATH=$PWD/tmp:$PATH xxx `readlink -f -- $PWD`/tmp
 # this may crash, if the PATH contains a non-matching libchicken.dll on Windows:
 #PATH=$PATH:$PWD/tmp xxx $PWD/tmp
 rm -fr rev-app rev-app-2 reverser/*.import.* reverser/*.so
-- 
1.8.2.3

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


[Chicken-hackers] patch: argument-type check for getter-with-setter

2013-05-25 Thread Kristian Lein-Mathisen
Dear Chickeners,

With the help of C-Keen, I've been able to make small patch that prevents a
segfault. The patch is attached.

I hope it turns out useful,
K.


0001-Adds-argument-type-check-on-getter-with-setter.patch
Description: Binary data
___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH] Fix for #1014 and minor cleanup of posix{win, unix} implementations

2013-05-25 Thread Jim Ursetto

On May 25, 2013, at 4:46 AM, Peter Bex peter@xs4all.nl wrote:

 There are also some memsets still left in the code after your patch,
 so some get initialized using C_tm_init, and some using memset.

Only strptime gets initialized with C_tm_init, and the rest with memset.  
strptime produces a time vector (C_tm_get), while the others deconstruct one 
(C_tm_set).  So these initializations are for two different purposes, i.e.:

The memset zeroes out the struct before we copy *all* fields in from a Scheme 
vector (in case there are hidden fields).  The C_tm_init zeroes out the struct 
and sets a few sane default values.  It is only strptime that needs this extra 
initialization, as it's the only call for which we may have only partial 
information.  This is basically equivalent to creating a Scheme vector with 
sane default values and copying it in using C_tm_set(), like the others do, 
just implemented in C without needing a fresh default time vector.

Just want to make sure you are aware of this.  I assumed the existing code uses 
a static buffer for efficiency to minimize garbage.

Jim
___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


Re: [Chicken-hackers] [PATCH] Make tests work from symlinked paths

2013-05-25 Thread Moritz Heidkamp
Mario Domenech Goulart mario.goul...@gmail.com writes:
 Maybe readlink -f ?

OK, Peter found that even that is not portable so I changed the test
itself to do the path canonicalization. Turns out that while the posix
unit's read-symbolic-link has a CANONICALIZE option it doesn't quite
behave like the readlink(1) program. So I went ahead and adapted its
behavior to match that. I also noticed that the types.db entry for
read-symbolic-link did not include that optional argument so I took it
as an opportunity to fix this, as well.

Moritz

From e98ed45bcfeca57d8d0a293da4ee335ea8d1ff4b Mon Sep 17 00:00:00 2001
From: Moritz Heidkamp mor...@twoticketsplease.de
Date: Sat, 25 May 2013 17:08:09 +0200
Subject: [PATCH 1/3] Improve read-symbolic-link canonicalization

Passing #t for the CANONICALIZE option of read-symbolic-link now behaves
like the --canonicalize option of readlink(1), i.e. it recursively
follows every symlink in every component of the given path. When called
like this, read-symbolic-link like readlink(1) now verifies that all
components exist.
---
 posixunix.scm | 43 +--
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/posixunix.scm b/posixunix.scm
index a2776da..6cdb4ef 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -1241,21 +1241,36 @@ EOF
 
 (define-foreign-variable _filename_max int FILENAME_MAX)
 
-(define read-symbolic-link
+(define ##sys#read-symbolic-link
   (let ((buf (make-string (fx+ _filename_max 1
-(lambda (fname #!optional canonicalize)
-  (##sys#check-string fname 'read-symbolic-link)
-  (let ((len (##core#inline 
-		  C_do_readlink
-		  (##sys#make-c-string (##sys#expand-home-path fname) 'read-symbolic-link) buf)))
-	(if (fx len 0)
-	(if canonicalize
-		fname
-		(posix-error #:file-error 'read-symbolic-link cannot read symbolic link fname))
-	(let ((pathname (substring buf 0 len)))
-	  (if (and canonicalize (symbolic-link? pathname))
-		  (read-symbolic-link pathname 'canonicalize)
-		  pathname ) ) ) ) ) ) )
+(lambda (fname location)
+  (let ((len (##core#inline
+  C_do_readlink
+  (##sys#make-c-string fname location) buf)))
+(if (fx len 0)
+(posix-error #:file-error location cannot read symbolic link fname)
+(substring buf 0 len))
+
+(define (read-symbolic-link fname #!optional canonicalize)
+  (##sys#check-string fname 'read-symbolic-link)
+  (let ((fname (##sys#expand-home-path fname)))
+(if canonicalize
+(receive (base-origin base-directory directory-components) (decompose-directory fname)
+  (let loop ((components directory-components)
+ (result (string-append (or base-origin ) (or base-directory 
+(if (null? components)
+result
+(let ((pathname (make-pathname result (car components
+  (if (file-exists? pathname)
+  (loop (cdr components)
+(if (symbolic-link? pathname)
+(let ((target (##sys#read-symbolic-link pathname 'read-symbolic-link)))
+  (if (absolute-pathname? target)
+  link
+  (make-pathname result target)))
+pathname))
+  (##sys#signal-hook #:file-error 'read-symbolic-link could not canonicalize path with symbolic links, component does not exist pathname))
+(##sys#read-symbolic-link fname 'read-symbolic-link
 
 (define file-link
   (let ([link (foreign-lambda int link c-string c-string)])
-- 
1.8.2.3

From a7de20ed3d344f9fcaa981fd746091624869be60 Mon Sep 17 00:00:00 2001
From: Moritz Heidkamp mor...@twoticketsplease.de
Date: Sat, 25 May 2013 17:27:55 +0200
Subject: [PATCH 2/3] Fix read-symbolic-link types.db entry

The optional CANONICALIZE argument was missing.
---
 types.db | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/types.db b/types.db
index 01d84e2..c061092 100644
--- a/types.db
+++ b/types.db
@@ -1765,7 +1765,7 @@
 (prot/none fixnum)
 (prot/read fixnum)
 (prot/write fixnum)
-(read-symbolic-link (#(procedure #:clean #:enforce) read-symbolic-link (string) string))
+(read-symbolic-link (#(procedure #:clean #:enforce) read-symbolic-link (string #!optional boolean) string))
 (regular-file? (#(procedure #:clean #:enforce) regular-file? ((or string fixnum)) boolean))
 (seconds-local-time (#(procedure #:clean #:enforce) seconds-local-time (#!optional number) (vector fixnum fixnum fixnum fixnum fixnum fixnum fixnum fixnum boolean fixnum)))
 (seconds-string (#(procedure #:clean #:enforce) seconds-string (#!optional number) string))
-- 
1.8.2.3

From a3cea67616c7d50092e20374ebc47176c7fee660 Mon Sep 17 00:00:00 2001
From: Moritz Heidkamp mor...@twoticketsplease.de
Date: Sat, 25 May 2013 17:31:12 +0200
Subject: [PATCH 3/3] Make tests work 

Re: [Chicken-hackers] [PATCH] Fix for #1014 and minor cleanup of posix{win, unix} implementations

2013-05-25 Thread Peter Bex
On Sat, May 25, 2013 at 10:29:55AM -0500, Jim Ursetto wrote:
 
 On May 25, 2013, at 4:46 AM, Peter Bex peter@xs4all.nl wrote:
 
  There are also some memsets still left in the code after your patch,
  so some get initialized using C_tm_init, and some using memset.
 
 Only strptime gets initialized with C_tm_init, and the rest with memset.  
 strptime produces a time vector (C_tm_get), while the others deconstruct one 
 (C_tm_set).  So these initializations are for two different purposes, i.e.:
 
 The memset zeroes out the struct before we copy *all* fields in from a Scheme 
 vector (in case there are hidden fields).  The C_tm_init zeroes out the 
 struct and sets a few sane default values.  It is only strptime that needs 
 this extra initialization, as it's the only call for which we may have only 
 partial information.  This is basically equivalent to creating a Scheme 
 vector with sane default values and copying it in using C_tm_set(), like the 
 others do, just implemented in C without needing a fresh default time vector.
 
 Just want to make sure you are aware of this.  I assumed the existing code 
 uses a static buffer for efficiency to minimize garbage.

Yeah, I figured the same.  I doubt it's going to make much of a
difference in most cases.

What do the other -hackers think of this?

Cheers,
Peter
-- 
http://www.more-magic.net

___
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers


[Chicken-hackers] [PATCH] Add support for R7RS syntax-rules extensions

2013-05-25 Thread Peter Bex
Hi all,

An important part of getting R7RS-small support into Chicken is
extending a few things in core.

Here's a patch to add the new extensions for syntax-rules.  The first
is the ability to disable the special meaning of ellipsis in template
forms by starting a list subform with an ellipsis identifier, like

(syntax-rules () ((bla foo bar) (mooh (... ...
This will not give an error, but literally expand to (mooh ...).
This also works nested, like in (mooh (... (blabla haha ... hello)))

The second is a bit silly and strictly speaking it breaks backwards
compatibility: the underscore character has a special wildcard
meaning in R7RS syntax-rules.  This means it will match anything
and will just expand to a literal underscore in templates:

(syntax-rules () ((bla _) (mooh _))) will literally expand to (mooh _),
not to the second expression in a call to this macro.  I think this
happens so rarely this is not worth going through a Change Request
for this.  If you disagree, please say so.

Strictly speaking, extended syntax-rules could be provided as part
of an R7RS egg, but it makes more sense to add it to core, since it's
just a small tweak and it improves compatibility with other Schemes
which already support these extensions (like R6RS Schemes, and pre-R6RS
Racket and Chez Scheme).

The ellipsis patch works by simply threading the ellipsis? predicate
all the way through all the calls, and switching to (constantly #f)
for processing REST when it sees (... . REST).  I initially used a
fluid-let to do the switch, but then decided against it, as the explicit
passing of el? is cleaner and easier to understand, IMHO.

The underscores patch simply skips over _ in the input pattern
(ie, in process-pattern) and generates no matching code for it (since it
won't be visible in a bound pattern variable), just like it does for
elements of the keyword literals list (which are also only used for
matching).  While looking for meta-variables, it will simply not add
the underscore to the pattern variable list.  Finally, there's no
special handling in the expansion itself.  Because _ does not get
added to the meta-variables, it won't recognise them in your templates,
so it'll just get expanded to a free variable named _.

The patch also cleans up the syntax-rules implementation a little by
removing unused aliased names and using %syntax-error instead of the full
##sys#syntax-error-hook name.

Finally, these extensions appear to introduce some ambiguities when
combined.  I've sent a mail to scheme-reports about this:
http://lists.scheme-reports.org/pipermail/scheme-reports/2013-May/003499.html
I didn't get any satisfactory replies so far, so I guess these
ambiguities are just an unspecified corner in the R7RS document.
R6RS (of course) nails this down and explicitly states It is a syntax
violation if an ellipsis or underscore appears in (literal ...).
I've decided to just leave it semi-specified and not try to bend over
backwards to detect this error situation, instead just falling back
to do the obvious thing, which in the code is to just let the
ellipsis escape take precedence over literal keywords, and to let
ellipsis specifier take precedence over underscore wildcards.
I've added tests to prevent regression later when people start
inadvertently relying on this.

Cheers,
Peter
-- 
http://www.more-magic.net
From 4b65e8359ebf28e984580b7a61660ed9d4930576 Mon Sep 17 00:00:00 2001
From: Peter Bex peter@xs4all.nl
Date: Sat, 25 May 2013 13:37:44 +0200
Subject: [PATCH 1/2] syntax-rules R7RS-compatibility: Implement ellipsis
 escape syntax: (... TEMPLATE) is equivalent to TEMPLATE, except with the
 special meaning of the (current) ellipsis being disabled

---
 synrules.scm | 120 +++
 1 file changed, 64 insertions(+), 56 deletions(-)

diff --git a/synrules.scm b/synrules.scm
index cf8912e..5ecfc3b 100644
--- a/synrules.scm
+++ b/synrules.scm
@@ -117,41 +117,42 @@
 (null? (cddr rule)))
(let ((pattern (cdar rule))
  (template (cadr rule)))
- `((,%and ,@(process-match %tail pattern #f))
+ `((,%and ,@(process-match %tail pattern #f ellipsis?))
(,%let* ,(process-pattern pattern
  %tail
- (lambda (x) x) #f)
+ (lambda (x) x) #f ellipsis?)
,(process-template template
   0
-  (meta-variables pattern 0 '() #f)
+   ellipsis?
+  (meta-variables pattern 0 ellipsis? '() 
#f)
(##sys#syntax-error-hook ill-formed syntax rule rule)))
 
   ;; Generate code to test whether input expression matches pattern
 
-  (define (process-match input pattern seen-segment?)
+  (define (process-match input pattern seen-segment? el?)
 (cond ((symbol?