* uniform-array-read!
@ 2006-01-31 8:48 William Xu
2006-01-31 13:42 ` uniform-array-read! Ludovic Courtès
0 siblings, 1 reply; 16+ messages in thread
From: William Xu @ 2006-01-31 8:48 UTC (permalink / raw)
Hi there,
Is the following the correct way of using `uniform-array-read!'? Seems
it simply hangs there..
(let ((ar (make-uniform-array #\nul length)))
(uniform-array-read! ar sockfd))
Any ideas?
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 8:48 uniform-array-read! William Xu
@ 2006-01-31 13:42 ` Ludovic Courtès
2006-01-31 14:50 ` uniform-array-read! Jon Wilson
2006-01-31 14:54 ` uniform-array-read! William Xu
0 siblings, 2 replies; 16+ messages in thread
From: Ludovic Courtès @ 2006-01-31 13:42 UTC (permalink / raw)
Cc: guile-user
Hi,
William Xu <william.xwl@gmail.com> writes:
> Is the following the correct way of using `uniform-array-read!'? Seems
> it simply hangs there..
>
> (let ((ar (make-uniform-array #\nul length)))
> (uniform-array-read! ar sockfd))
In your example, it can very well be hanging because there is nothing to
read from SOCKFD (e.g., it's making a blocking `read' system call
beneath).
Using Guile 1.7:
guile> (define a (make-uniform-array #\nul 10))
guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
3
guile> a
#s8(1 2 3 32 51 10 -102 96 48 10)
guile>
IOW, it seems to work fine --- except that:
1. The array is not properly initialized;
2. The result is not a string as one would expect from the Guile 1.6
manual[*] (in fact it could hardly be a string since internally
strings may not contain null characters AFAIK).
So 1.7 is _not_ compatible with 1.6 in that respect. I guess we need to
fix this.
In 1.7, `make-uniform-array' is deprecated and replaced by
`make-typed-array' (BTW, this deprecation is not currently documented in
the 1.7 manual):
-- Scheme Procedure: make-typed-array type fill bound ...
-- C Function: scm_make_typed_array (type, fill, bounds)
Create and return an array that has as many dimensions as there are
BOUNDs and (maybe) fill it with FILL.
Hope this helps,
Ludovic.
[*] From node `Uniform Arrays':
Unshared uniform arrays of characters with a single zero-based dimension
are identical to strings:
(make-uniform-array #\a 3) =>
"aaa"
Unshared uniform arrays of booleans with a single zero-based dimension
are identical to *Note bit-vectors: Bit Vectors.
(make-uniform-array #t 3) =>
#*111
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 13:42 ` uniform-array-read! Ludovic Courtès
@ 2006-01-31 14:50 ` Jon Wilson
2006-02-01 8:08 ` uniform-array-read! Ludovic Courtès
2006-01-31 14:54 ` uniform-array-read! William Xu
1 sibling, 1 reply; 16+ messages in thread
From: Jon Wilson @ 2006-01-31 14:50 UTC (permalink / raw)
Hi y'all,
> Using Guile 1.7:
>
> guile> (define a (make-uniform-array #\nul 10))
> guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
> 3
> guile> a
> #s8(1 2 3 32 51 10 -102 96 48 10)
> guile>
>
> IOW, it seems to work fine --- except that:
>
> 1. The array is not properly initialized;
>
> 2. The result is not a string as one would expect from the Guile 1.6
> manual[*] (in fact it could hardly be a string since internally
> strings may not contain null characters AFAIK).
>
> So 1.7 is _not_ compatible with 1.6 in that respect. I guess we need to
> fix this.
Here is the same in 1.6, just for good measure:
guile> (define a (make-uniform-array #\nul 10))
guile> a
#y(0 0 0 0 0 0 0 0 0 0)
guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
3
guile> a
#y(1 2 3 0 0 0 0 0 0 0)
The result is not a string, probably because the array was originally
defined to be filled with null chars. If I define the array to originally
contain some valid character, then subsequently it displays as a string.
Regards,
Jon
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 13:42 ` uniform-array-read! Ludovic Courtès
2006-01-31 14:50 ` uniform-array-read! Jon Wilson
@ 2006-01-31 14:54 ` William Xu
2006-01-31 17:26 ` uniform-array-read! Ludovic Courtès
2006-02-03 0:22 ` uniform-array-read! Alan Bram
1 sibling, 2 replies; 16+ messages in thread
From: William Xu @ 2006-01-31 14:54 UTC (permalink / raw)
ludovic.courtes@laas.fr (Ludovic Courtès) writes:
> William Xu <william.xwl@gmail.com> writes:
>
>> Is the following the correct way of using `uniform-array-read!'? Seems
>> it simply hangs there..
>>
>> (let ((ar (make-uniform-array #\nul length)))
>> (uniform-array-read! ar sockfd))
>
> In your example, it can very well be hanging because there is nothing to
> read from SOCKFD (e.g., it's making a blocking `read' system call
> beneath).
Ooh, that was only partial of the codes. Actually i've also written the
codes in C first to make sure we could *read*.
> Using Guile 1.7:
Not in debian yet.. Guile 1.6.7 here.
> guile> (define a (make-uniform-array #\nul 10))
> guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
> 3
> guile> a
> #s8(1 2 3 32 51 10 -102 96 48 10)
> guile>
>
> IOW, it seems to work fine --- except that:
>
> 1. The array is not properly initialized;
It is.
> 2. The result is not a string as one would expect from the Guile 1.6
> manual[*] (in fact it could hardly be a string since internally
> strings may not contain null characters AFAIK).
What is that "result"? I noticed that in your example,
guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
The second argument for uniform-array-read! is a string. In my codes, i
tried to read binary data, precisely, a network packet. Does this
matter?
[...]
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 14:54 ` uniform-array-read! William Xu
@ 2006-01-31 17:26 ` Ludovic Courtès
2006-02-01 3:01 ` uniform-array-read! William Xu
2006-02-12 1:19 ` uniform-array-read! Marius Vollmer
2006-02-03 0:22 ` uniform-array-read! Alan Bram
1 sibling, 2 replies; 16+ messages in thread
From: Ludovic Courtès @ 2006-01-31 17:26 UTC (permalink / raw)
Cc: guile-user
William Xu <william.xwl@gmail.com> writes:
> Not in debian yet.. Guile 1.6.7 here.
Yeah, I know, unfortunately...
>> guile> (define a (make-uniform-array #\nul 10))
>> guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
>> 3
>> guile> a
>> #s8(1 2 3 32 51 10 -102 96 48 10)
>> guile>
>>
>> IOW, it seems to work fine --- except that:
>>
>> 1. The array is not properly initialized;
>
> It is.
Not with Guile 1.7, see above (it should only contain zeros starting
from the fourth element).
> What is that "result"?
See this comparison of Guile 1.6 and 1.7:
$ guile-1.6
guile> (make-uniform-array #\a 10)
"aaaaaaaaaa"
guile> (make-uniform-array #\nul 10)
#y(0 0 0 0 0 0 0 0 0 0)
guile> (make-uniform-array #\001 10)
""
$ guile-1.7
guile> (make-uniform-array #\a 10)
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
guile> (make-uniform-array #\nul 10)
#s8(15 -44 -17 16 16 4 118 8 0 0)
guile> (make-uniform-array #\001 10)
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
All the results differ. Notably, Guile 1.7 fails to properly initialize
the arrays returned.
However, note that Guile 1.6 already handles the `#\nul' case specially:
in that case, `make-uniform-array' doesn't return a string (as explained
in the manual) but an array.
> guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
>
> The second argument for uniform-array-read! is a string. In my codes, i
> tried to read binary data, precisely, a network packet. Does this
> matter?
The second argument is an input port, not a string: `open-input-string'
returns an input port, like `open-input-file'.
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 17:26 ` uniform-array-read! Ludovic Courtès
@ 2006-02-01 3:01 ` William Xu
2006-02-02 21:52 ` uniform-array-read! Kevin Ryde
2006-02-12 1:19 ` uniform-array-read! Marius Vollmer
1 sibling, 1 reply; 16+ messages in thread
From: William Xu @ 2006-02-01 3:01 UTC (permalink / raw)
ludovic.courtes@laas.fr (Ludovic Courtès) writes:
[...]
>> guile> (uniform-array-read! a (open-input-string (string #\001 #\002 #\003)))
>>
>> The second argument for uniform-array-read! is a string. In my codes, i
>> tried to read binary data, precisely, a network packet. Does this
>> matter?
>
> The second argument is an input port, not a string: `open-input-string'
> returns an input port, like `open-input-file'.
Hmm, then what could be the problem here.. I can do uniform-array-write
to that `sockfd'. And by using some network sniffer, i see the packet
successfully sent to the server, and also the packet sent from the
server. But uniform-array-read! won't read out the packet sent from
server.
any way to look into or trace, uniform-array-read! ?
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 14:50 ` uniform-array-read! Jon Wilson
@ 2006-02-01 8:08 ` Ludovic Courtès
0 siblings, 0 replies; 16+ messages in thread
From: Ludovic Courtès @ 2006-02-01 8:08 UTC (permalink / raw)
Cc: guile-user
Hi,
Jon Wilson <j85wilson@fastmail.fm> writes:
> The result is not a string, probably because the array was originally
> defined to be filled with null chars. If I define the array to
> originally contain some valid character, then subsequently it displays
> as a string.
Exactly.
Thanks,
Ludovic.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-01 3:01 ` uniform-array-read! William Xu
@ 2006-02-02 21:52 ` Kevin Ryde
0 siblings, 0 replies; 16+ messages in thread
From: Kevin Ryde @ 2006-02-02 21:52 UTC (permalink / raw)
Cc: guile-user
William Xu <william.xwl@gmail.com> writes:
>
> any way to look into or trace, uniform-array-read! ?
If you put it under gdb you should be able to ^C when it's hung and
find out where it is. There's won't be much info except the function
names, unless you build a guile with "CFLAGS=-g".
Otherwise post a complete failing sample program to bug-guile.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 14:54 ` uniform-array-read! William Xu
2006-01-31 17:26 ` uniform-array-read! Ludovic Courtès
@ 2006-02-03 0:22 ` Alan Bram
2006-02-03 4:35 ` uniform-array-read! William Xu
1 sibling, 1 reply; 16+ messages in thread
From: Alan Bram @ 2006-02-03 0:22 UTC (permalink / raw)
Cc: guile-user
Hi,
I've been following along on this topic only half-absentmindedly, so I
apologize if I missed something. But, just thought it might be a
useful data point to know:
Both of the following variants seem to be working just fine for me:
,--
| (define read-network-byte
| (lambda (port)
| (let ((v (make-uniform-vector 1 #\nul)))
| (uniform-vector-read! v port)
| (uniform-vector-ref v 0))))
|
|
| (define read-network-byte
| (lambda (port)
| (let ((v (make-uniform-array #\nul 1)))
| (uniform-array-read! v port)
| (uniform-vector-ref v 0))))
`--
Guile version 1.6.7 on Debian Linux i386.
Cheers,
- arb
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-03 0:22 ` uniform-array-read! Alan Bram
@ 2006-02-03 4:35 ` William Xu
2006-02-03 4:46 ` uniform-array-read! William Xu
2006-02-03 19:12 ` uniform-array-read! Alan Bram
0 siblings, 2 replies; 16+ messages in thread
From: William Xu @ 2006-02-03 4:35 UTC (permalink / raw)
Alan Bram <arb46@cornell.edu> writes:
[...]
> |
> | (define read-network-byte
> | (lambda (port)
> | (let ((v (make-uniform-array #\nul 1)))
^^^
when array size is 1, it works. But if i set it to 3, for instance. Then
it'll still block..
> | (uniform-array-read! v port)
> | (uniform-vector-ref v 0))))
> `--
And i made the following workaround, using `recv!'. At least it works as
expected.
(define (qq-read-binary-list sock length)
"Read at most LENGTH bytes from SOCK. Return a list of integers."
(let* ((buf (make-string length #\ ))
(count (recv! sock buf)))
(if (> count 0) ; we have read something.
(map
char->integer
(string->list (substring buf 0 count)))
lst)))
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-03 4:35 ` uniform-array-read! William Xu
@ 2006-02-03 4:46 ` William Xu
2006-02-03 19:12 ` uniform-array-read! Alan Bram
1 sibling, 0 replies; 16+ messages in thread
From: William Xu @ 2006-02-03 4:46 UTC (permalink / raw)
William Xu <william.xwl@gmail.com> writes:
> Alan Bram <arb46@cornell.edu> writes:
>
> [...]
>
>> |
>> | (define read-network-byte
>> | (lambda (port)
>> | (let ((v (make-uniform-array #\nul 1)))
> ^^^
> when array size is 1, it works. But if i set it to 3, for instance. Then
> it'll still block..
>
>> | (uniform-array-read! v port)
>> | (uniform-vector-ref v 0))))
>> `--
>
> And i made the following workaround, using `recv!'. At least it works as
> expected.
>
> (define (qq-read-binary-list sock length)
> "Read at most LENGTH bytes from SOCK. Return a list of integers."
> (let* ((buf (make-string length #\ ))
> (count (recv! sock buf)))
> (if (> count 0) ; we have read something.
> (map
> char->integer
> (string->list (substring buf 0 count)))
> lst)))
Oh, sorry. A minor mistake in the code. Here's updated,
(define (qq-read-list sock length)
"Read at most LENGTH bytes. Return a list of integers."
(let* ((buf (make-string length #\ ))
(count (recv! sock buf)))
(if (> count 0) ; we have read something.
(map
char->integer
(string->list (substring buf 0 count))))))
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-03 4:35 ` uniform-array-read! William Xu
2006-02-03 4:46 ` uniform-array-read! William Xu
@ 2006-02-03 19:12 ` Alan Bram
2006-02-04 2:43 ` uniform-array-read! William Xu
2006-02-04 13:31 ` uniform-array-read! Marius Vollmer
1 sibling, 2 replies; 16+ messages in thread
From: Alan Bram @ 2006-02-03 19:12 UTC (permalink / raw)
Cc: guile-user
Gee, that's strange. When I try it, even with a larger size, it still
works fine for me.
> > |
> > | (define read-network-byte
> > | (lambda (port)
> > | (let ((v (make-uniform-array #\nul 1)))
> ^^^
> when array size is 1, it works. But if i set it to 3, for instance. Then
> it'll still block..
>
> > | (uniform-array-read! v port)
> > | (uniform-vector-ref v 0))))
> > `--
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-03 19:12 ` uniform-array-read! Alan Bram
@ 2006-02-04 2:43 ` William Xu
2006-02-04 13:31 ` uniform-array-read! Marius Vollmer
1 sibling, 0 replies; 16+ messages in thread
From: William Xu @ 2006-02-04 2:43 UTC (permalink / raw)
Alan Bram <arb46@cornell.edu> writes:
> Gee, that's strange. When I try it, even with a larger size, it still
> works fine for me.
Hmm... well, it's 1.6.7 on Debian(unstable) ppc here.
--
William
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-03 19:12 ` uniform-array-read! Alan Bram
2006-02-04 2:43 ` uniform-array-read! William Xu
@ 2006-02-04 13:31 ` Marius Vollmer
2006-02-04 16:54 ` uniform-array-read! Alan Bram
1 sibling, 1 reply; 16+ messages in thread
From: Marius Vollmer @ 2006-02-04 13:31 UTC (permalink / raw)
Cc: guile-user
Alan Bram <arb46@cornell.edu> writes:
> Gee, that's strange. When I try it, even with a larger size, it
> still works fine for me.
The problem is likely that uniform-array-read! will try to fill the
whole array, if necessary by doing more than one call to read(2). The
first call will not block after select or poll has given the green
light for reading, but the second call might block (or not).
(In 1.8, uniform-vector-read! will make the guarantee to only call
read(2) once when you read from a file descriptor (and not a port)).
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-02-04 13:31 ` uniform-array-read! Marius Vollmer
@ 2006-02-04 16:54 ` Alan Bram
0 siblings, 0 replies; 16+ messages in thread
From: Alan Bram @ 2006-02-04 16:54 UTC (permalink / raw)
Cc: guile-user
> Alan Bram <arb46@cornell.edu> writes:
>
> > Gee, that's strange. When I try it, even with a larger size, it
> > still works fine for me.
>
> The problem is likely that uniform-array-read! will try to fill the
> whole array, if necessary by doing more than one call to read(2). The
> first call will not block after select or poll has given the green
> light for reading, but the second call might block (or not).
Sure. But if enough bytes are there, even if they arrive a moment
later, as I think William said they were, then even the second
select() should not block.
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: uniform-array-read!
2006-01-31 17:26 ` uniform-array-read! Ludovic Courtès
2006-02-01 3:01 ` uniform-array-read! William Xu
@ 2006-02-12 1:19 ` Marius Vollmer
1 sibling, 0 replies; 16+ messages in thread
From: Marius Vollmer @ 2006-02-12 1:19 UTC (permalink / raw)
Cc: guile-user
ludovic.courtes@laas.fr (Ludovic Courtès) writes:
> $ guile-1.7
> guile> (make-uniform-array #\a 10)
> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
> guile> (make-uniform-array #\nul 10)
> #s8(15 -44 -17 16 16 4 118 8 0 0)
> guile> (make-uniform-array #\001 10)
> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>
> All the results differ. Notably, Guile 1.7 fails to properly initialize
> the arrays returned.
Yep, that was a bug in dimensions->uniform-array, which didn't handle
an omitted 'fill' parameter correctly. The result was that not array
created with make-uniform-array was initialized.
Thanks for spotting this!
But note that make-uniform-array is deprecated in 1.7 and the
imminent 1.8; use make-typed-array instead:
guile> (make-typed-array 's8 0 10)
#s8(0 0 0 0 0 0 0 0 0 0)
--
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3 331E FAF8 226A D5D4 E405
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user
^ permalink raw reply [flat|nested] 16+ messages in thread
end of thread, other threads:[~2006-02-12 1:19 UTC | newest]
Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-31 8:48 uniform-array-read! William Xu
2006-01-31 13:42 ` uniform-array-read! Ludovic Courtès
2006-01-31 14:50 ` uniform-array-read! Jon Wilson
2006-02-01 8:08 ` uniform-array-read! Ludovic Courtès
2006-01-31 14:54 ` uniform-array-read! William Xu
2006-01-31 17:26 ` uniform-array-read! Ludovic Courtès
2006-02-01 3:01 ` uniform-array-read! William Xu
2006-02-02 21:52 ` uniform-array-read! Kevin Ryde
2006-02-12 1:19 ` uniform-array-read! Marius Vollmer
2006-02-03 0:22 ` uniform-array-read! Alan Bram
2006-02-03 4:35 ` uniform-array-read! William Xu
2006-02-03 4:46 ` uniform-array-read! William Xu
2006-02-03 19:12 ` uniform-array-read! Alan Bram
2006-02-04 2:43 ` uniform-array-read! William Xu
2006-02-04 13:31 ` uniform-array-read! Marius Vollmer
2006-02-04 16:54 ` uniform-array-read! Alan Bram
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).