The Racket repository
Go to file
Robby Findler 1b3fd890ad adjust 'dc' so that the ascent and descent arguments are independently
optional and add a contract that calls the 'draw' argument to make
sure it restores the dc state.

The call to the 'draw' function happens right when 'dc' is called and
it tests the property that 'draw' doesn't abuse the state only that
one time and only with x=0 and y=0. This seems likely to catch common
errors, however, since the mismanagement of the state is unlikely to
be related to the values of 'x' and 'y' and also unlikely to depend on
the timing of the the call (i.e., if it happens at all, it probably
always happens).

Another way we could enforce this contract would be to wrap the `draw'
argument so that each time it is called, we grab the state of the dc
and compare it to afterwards.  The current strategy is less expensive
and also catches errors earlier (in the case of slidehow specifically,
we'll get the errors during the startup of the presentation instead of
when we try to render a slide (in the middle of the presentation,
typically)).

This change slows down calls to 'dc'. For example, this program:

 #lang racket/gui
(require pict)

(define brush (send the-brush-list find-or-create-brush "black" 'solid))
(define (circ w h)
  (dc (λ (dc dx dy)
        (define orig-pen (send dc get-pen))
        (define orig-brush (send dc get-brush))
        (send dc set-pen "black" 1 'transparent)
        (send dc set-brush brush)
        (send dc draw-ellipse dx dy w h)
        (send dc set-pen orig-pen)
        (send dc set-brush orig-brush))
      w h))

(void
 (time
  (for/fold ([b (blank)]) ([i (in-range 10000)])
    (vc-append (circ (random 1000)
                     (random 1000))
               b))))

goes from
  cpu time: 16 real time: 17 gc time: 0
to
  cpu time: 2166 real time: 2172 gc time: 224
on my machine.

Still, that cost, when measured in a per-call-to-dc way is
only .21 msecs, which seems reasonable given the pain of
tracking down the kinds of bugs that this contract
helps detect.
2014-07-15 06:04:31 -05:00
native-pkgs@60c510ba85 win64: fix fixnum-to-extfl conversion 2014-06-19 05:28:16 +01:00
pkgs adjust 'dc' so that the ascent and descent arguments are independently 2014-07-15 06:04:31 -05:00
racket pkg/lib: fix pkg-directory->additional-installs 2014-07-15 10:39:53 +01:00
.gitattributes Don't include git files in archives. 2010-05-12 01:46:05 -04:00
.gitignore Add add-on to .gitignore. 2013-07-04 11:51:53 -04:00
.gitmodules access "native-pkgs" as a git submodule 2013-07-26 22:36:20 -06:00
.mailmap mailmap updates & fixes. 2013-04-03 18:10:22 -04:00
.travis.yml Enable OS X testing on Travis. 2014-05-14 11:00:24 -04:00
INSTALL.txt distro-build: add "versionless" option 2014-06-23 18:42:46 +01:00
Makefile make site: propagate package dependencies, modules, etc. to catalog 2014-07-04 08:48:46 +01:00
README.txt 2013 -> 2014 2014-01-21 15:02:21 -05:00

This is the source code for the main Racket distribution.  See
"INSTALL.txt" for information on building Racket.

License
-------

Racket
Copyright (c) 2010-2014 PLT Design Inc.

Racket is distributed under the GNU Lesser General Public License
(LGPL).  This means that you can link Racket into proprietary
applications, provided you follow the rules stated in the LGPL.  You can
also modify Racket; if you distribute a modified version, you must
distribute it under the terms of the LGPL, which in particular means
that you must release the source code for the modified software.  See
racket/src/COPYING_LESSER.txt for more information.