Changeset 549

Show
Ignore:
Timestamp:
06/17/08 11:52:48 (7 months ago)
Author:
weyrick
Message:

fix detection of references in serialize

Location:
trunk/pcc/runtime
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pcc/runtime/ext/standard/php-variable.scm

    r430 r549  
    163163   (let ((refhash (make-grasstable)) 
    164164         (varcount 0)) 
    165       (letrec ((fork-it   (lambda (v ref? key?) 
     165      (letrec ((fork-it   (lambda (v key?) 
    166166                             ; handle refs 
    167                              (let ((ref-loc (grasstable-get refhash v))) 
    168                                 (if (and ref-loc ref?)                                    
     167                             (let* ((c? (container? v)) 
     168                                    (ubv (if c? (container-value  v) v)) 
     169                                    (ref-loc (grasstable-get refhash v))) 
     170                                (if ref-loc 
    169171                                    (format "R:~a;" ref-loc) 
    170172                                    (begin 
     
    172174                                       (unless key? 
    173175                                          (set! varcount (+ varcount 1))) 
    174                                        (if ref? 
     176                                       (when (and c? (container-reference? v)) 
    175177                                          (grasstable-put! refhash v varcount)) 
    176178                                       (cond 
    177                                           ((is_bool v) (do-bool v)) 
    178                                           ((is_int v) (do-int v)) 
    179                                           ((is_float v) (do-float v)) 
    180                                           ((is_string v) (do-string v)) 
    181                                           ((is_array v) (do-array v)) 
    182                                           ((is_object v) (do-object v)) 
    183                                           ((is_null v) (do-null v)) 
     179                                          ((is_bool ubv) (do-bool ubv)) 
     180                                          ((is_int ubv) (do-int ubv)) 
     181                                          ((is_float ubv) (do-float ubv)) 
     182                                          ((is_string ubv) (do-string ubv)) 
     183                                          ((is_array ubv) (do-array ubv)) 
     184                                          ((is_object ubv) (do-object ubv)) 
     185                                          ((is_null ubv) (do-null ubv)) 
    184186                                          (else 
    185187                                           ;(php-warning "serialize: unknown type for " v) 
     
    196198                                (lambda () 
    197199                                   (display (format "a:~a:{" (php-hash-size v))) 
    198                                    (php-hash-for-each-with-ref-status v 
    199                                                                       (lambda (ak av r?) 
    200                                                                         ;(fprint (current-error-port) "doing " ak " => " av) 
    201                                                                          (display (fork-it ak #f #t)) 
    202                                                                          (display (fork-it av r? #f)))) 
     200                                   (php-hash-for-each-location v 
     201                                                               (lambda (ak av) 
     202                                                                  ;(fprint (current-error-port) "doing " ak " => " av) 
     203                                                                  (display (fork-it ak #t)) 
     204                                                                  (display (fork-it av #f)))) 
    203205                                   (display "}"))))) 
    204206               (do-object (lambda (v) 
     
    218220                                                                             (php-hash-size propshash) 
    219221                                                                             (php-hash-size ser-vars)))) 
    220                                                  (php-hash-for-each-with-ref-status 
     222                                                 (php-hash-for-each-location 
    221223                                                  propshash 
    222                                                   (lambda (ak av r?) 
     224                                                  (lambda (ak av) 
    223225                                                     (when (or (eqv? ser-vars 'all) 
    224226                                                             (php-hash-in-array? ser-vars ak #f)) 
    225                                                         (display (fork-it ak #f #t)) 
    226                                                         (display (fork-it av r? #f))))) 
     227                                                        (display (fork-it ak #t)) 
     228                                                        (display (fork-it av #f))))) 
    227229                                                 (display "}"))) 
    228230                                           ))))) 
     
    236238                             ;(fprint (current-error-port) "i'm a bool") 
    237239                             (if v "b:1;" "b:0;")))) 
    238          (fork-it var #f #f)))) 
     240         (fork-it var #f)))) 
    239241 
    240242; unserialize --  Creates a PHP value from a stored representation 
  • trunk/pcc/runtime/php-hash.scm

    r426 r549  
    4848           (php-hash-remove! hash key) 
    4949           (php-hash-for-each hash thunk::procedure) 
    50            (php-hash-for-each-with-ref-status hash thunk::procedure) 
     50           (php-hash-for-each-with-ref-status hash thunk::procedure)        
     51           (php-hash-for-each-location hash thunk::procedure) 
    5152           (php-hash-reverse-for-each hash thunk::procedure) 
    5253           (php-hash-for-each-ref hash thunk::procedure) 
     
    809810 
    810811(define (php-hash-for-each-with-ref-status hash thunk::procedure) 
    811    "Thunk will be called once on each key/value set. ref status is available to thunk" 
     812   "Thunk will be called once on each key/value set. the value will be the location container" 
    812813   (when (custom? hash) (set! hash (custom-read-entire hash))) 
    813814   (let loop ((entry (%php-hash-head hash))) 
     
    815816         (thunk (get-key-php-type-friendly entry) 
    816817                (container-value (%entry-value entry)) 
    817                 (container-reference? (%entry-value entry))) 
     818                (container-reference? (%entry-value entry))) 
     819         ;              (%entry-ref? entry)) 
     820         (loop (%entry-next entry))))) 
     821 
     822(define (php-hash-for-each-location hash thunk::procedure) 
     823   "Thunk will be called once on each key/value set. the value will be the location container" 
     824   (when (custom? hash) (set! hash (custom-read-entire hash))) 
     825   (let loop ((entry (%php-hash-head hash))) 
     826      (unless (sentinel? entry) 
     827         (thunk (get-key-php-type-friendly entry) 
     828                (%entry-value entry)) 
    818829         ;              (%entry-ref? entry)) 
    819830         (loop (%entry-next entry)))))