guile-dbi cores in mark_db_handle

2013-08-30 Thread Andrew Gaylard

Hi guile people,

I'm experiencing cores in guile-dbi.

This is on Solaris-10u10 on SPARC, with guile and guile-dbi compiled 
with -O2.

When compiled with -O0, the problem disappears.  I've also been unable to
replicate the problem on Linux x86_64. This suggests to me that the
underlying cause could be timing-related (my guile app does use threads).

This is what gdb shows:

Program terminated with signal 10, Bus error.
#0  0x75601c8c in mark_db_handle (g_db_handle_smob=0x10115efc0) 
at guile-dbi.c:114

114   scm_gc_mark(g_db_handle->bcknd);
(gdb) p g_db_handle
$1 = (gdbi_db_handle_t *) 0x304

That 0x304 is SCM_EOL. The only part of guile-dbi.c which looks like it 
could be

causing this is free_db_handle, which does this:

SCM_SETCDR (g_db_handle_smob, SCM_EOL);

If this is the cause, then why is mark_db_handle being called after the 
object

has already been free'd?

I can prevent the cores by adding this to the start of mark_db_handle:

if (g_db_handle == (gdbi_db_handle_t*) SCM_EOL) return SCM_UNSPECIFIED;

However, I'm concerned that this isn't the right fix; what if something 
really does need

to be marked, and isn't?  -- it'll be GC'd when it shouldn't, right?

--
Andrew




Re: Emacsy: Context Sensitive Commands Design Question

2013-08-30 Thread Thien-Thi Nguyen
() Shane Celis 
() Thu, 29 Aug 2013 16:57:00 -0400

   6. Tag commands as special procedures [...] Implement "command?"

   CON: Adding something to the procedure makes wrapping commands in
   other lambdas awkward.  Might necessitate a define-command,
   lambda-command, method-command, which I'd prefer to avoid.

Why would you prefer to avoid this?

   What would you do?

I'd explore option 6, starting w/:

 (define command? (make-object-property))

I think object properties are better suited than procedure properties
after observing this in the (Emacs) *scratch* buffer:

 (commandp [42])
 t

It would be cool for Emacsy to have good "keyboard macros" support.
Many a non-programmer fall into consciousness via such, in Emacs.

[cc trimmed]

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
  read my lisp: (responsep (questions 'technical)
   (not (via 'mailing-list)))
 => nil


pgpu3gbkKzdwO.pgp
Description: PGP signature


Re: Emacsy: Context Sensitive Commands Design Question

2013-08-30 Thread Ludovic Courtès
Mark H Weaver  skribis:

> Shane Celis  writes:
>
>> 6. Tag commands as special procedures perhaps by adding something to
>> their procedure properties.  Implement a "command?" procedure.  Export
>> commands and procedures to the same module. Then just pluck the
>> commands out of all the procedures by using command?.
>
> This is closest to what Emacs does, and probably the best solution, IMO.  See
> 
> which describes the 'commandp' predicate, whose definition is in eval.c.

I concur (Thien-Thi’s message shows how this can be achieved.)

So it’s a matter of extending Emacsy’s ‘define-interactive’ to add an
object property.

Then you could have a ‘fold-commands’ procedure that traverses all the
bindings of all the available modules (or a subset thereof), and
iterates on those that match ‘command?’.

Ludo’.



How to read integers from file faster?

2013-08-30 Thread Darren Hoo

It is way too slow to read numbers from a file simply by using `read' 

for example a txt file contains 10,000,000 line of numbers:

(define (gen-sample max k file)
  (with-output-to-file 
  file
(lambda ()
  (let lp ((k k))
(when (> k 0)
  (display (random max)) (newline)
  (lp (- k 1) ))
 
(gen-sample 9 1000 "rnd.txt")

 
And read the numbers in 

(define (read-test1)
  (with-input-from-file
  "rnd.txt"
(lambda ()
  (let lp ((i (read)))
(if (not (eof-object? i))
(lp (read)))

scheme@(guile-user)> ,time (read-test1)
;; 37.348000s real time, 37.34s run time.  0.45s spent in GC.


with rdelim's read-line, it's better but still slow.

(import (ice-9 rdelim))
(define (read-test2)
  (with-input-from-file
  "rnd.txt"
(lambda ()
  (let lp ((i (read-line)))
(if (not (eof-object? i))
(begin 
  (string->number i)
  (lp (read-line

scheme@(guile-user)> ,time (read-test2)
;; 11.943000s real time, 11.93s run time.  0.89s spent in GC.


it only takes 1.8 seconds by using fscanf

FILE *f = fopen("rnd.txt", "r");
if (f == NULL) {
  printf("open failed!");
  exit(1);
}
long long i;
while (fscanf(f, "%lld", &i) != EOF) {
  
}

$ time ./read 

real0m1.844s
user0m1.803s
sys 0m0.032s

Are there any primitives in Guile that is equivalent to C's scanf?




Re: How to read integers from file faster?

2013-08-30 Thread Mike Gran
> From: Darren Hoo 

>It is way too slow to read numbers from a file simply by using `read' 


The problem mostly lies in dealing with the locale or doing utf-8
conversion.  Also, your code creates and destroys a lot of strings.


You could push data through much more quickly if it were binary
and if you didn't create new objects.


(define (read-test1)
  (let* ((p (open-input-file "rnd.txt"))
 (buf (make-bytevector 10 0)))
    (let lp ((i (get-bytevector-n! p buf 0 10)))

  (if (not (eof-object? i))
  (lp (get-bytevector-n p 10))

But, alas, knowing that isn't really a solution to your problem.


-Mike