deprecated.scm 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. ;;;; Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
  2. ;;;;
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 2.1 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  16. ;;;;
  17. ;;;; Deprecated definitions.
  18. (define substring-move-left! substring-move!)
  19. (define substring-move-right! substring-move!)
  20. ;; This method of dynamically linking Guile Extensions is deprecated.
  21. ;; Use `load-extension' explicitly from Scheme code instead.
  22. (define (split-c-module-name str)
  23. (let loop ((rev '())
  24. (start 0)
  25. (pos 0)
  26. (end (string-length str)))
  27. (cond
  28. ((= pos end)
  29. (reverse (cons (string->symbol (substring str start pos)) rev)))
  30. ((eq? (string-ref str pos) #\space)
  31. (loop (cons (string->symbol (substring str start pos)) rev)
  32. (+ pos 1)
  33. (+ pos 1)
  34. end))
  35. (else
  36. (loop rev start (+ pos 1) end)))))
  37. (define (convert-c-registered-modules dynobj)
  38. (let ((res (map (lambda (c)
  39. (list (split-c-module-name (car c)) (cdr c) dynobj))
  40. (c-registered-modules))))
  41. (c-clear-registered-modules)
  42. res))
  43. (define registered-modules '())
  44. (define (register-modules dynobj)
  45. (set! registered-modules
  46. (append! (convert-c-registered-modules dynobj)
  47. registered-modules)))
  48. (define (warn-autoload-deprecation modname)
  49. (issue-deprecation-warning
  50. "Autoloading of compiled code modules is deprecated."
  51. "Write a Scheme file instead that uses `load-extension'.")
  52. (issue-deprecation-warning
  53. (simple-format #f "(You just autoloaded module ~S.)" modname)))
  54. (define (init-dynamic-module modname)
  55. ;; Register any linked modules which have been registered on the C level
  56. (register-modules #f)
  57. (or-map (lambda (modinfo)
  58. (if (equal? (car modinfo) modname)
  59. (begin
  60. (warn-autoload-deprecation modname)
  61. (set! registered-modules (delq! modinfo registered-modules))
  62. (let ((mod (resolve-module modname #f)))
  63. (save-module-excursion
  64. (lambda ()
  65. (set-current-module mod)
  66. (set-module-public-interface! mod mod)
  67. (dynamic-call (cadr modinfo) (caddr modinfo))
  68. ))
  69. #t))
  70. #f))
  71. registered-modules))
  72. (define (dynamic-maybe-call name dynobj)
  73. (catch #t ; could use false-if-exception here
  74. (lambda ()
  75. (dynamic-call name dynobj))
  76. (lambda args
  77. #f)))
  78. (define (dynamic-maybe-link filename)
  79. (catch #t ; could use false-if-exception here
  80. (lambda ()
  81. (dynamic-link filename))
  82. (lambda args
  83. #f)))
  84. (define (find-and-link-dynamic-module module-name)
  85. (define (make-init-name mod-name)
  86. (string-append "scm_init"
  87. (list->string (map (lambda (c)
  88. (if (or (char-alphabetic? c)
  89. (char-numeric? c))
  90. c
  91. #\_))
  92. (string->list mod-name)))
  93. "_module"))
  94. ;; Put the subdirectory for this module in the car of SUBDIR-AND-LIBNAME,
  95. ;; and the `libname' (the name of the module prepended by `lib') in the cdr
  96. ;; field. For example, if MODULE-NAME is the list (inet tcp-ip udp), then
  97. ;; SUBDIR-AND-LIBNAME will be the pair ("inet/tcp-ip" . "libudp").
  98. (let ((subdir-and-libname
  99. (let loop ((dirs "")
  100. (syms module-name))
  101. (if (null? (cdr syms))
  102. (cons dirs (string-append "lib" (symbol->string (car syms))))
  103. (loop (string-append dirs (symbol->string (car syms)) "/")
  104. (cdr syms)))))
  105. (init (make-init-name (apply string-append
  106. (map (lambda (s)
  107. (string-append "_"
  108. (symbol->string s)))
  109. module-name)))))
  110. (let ((subdir (car subdir-and-libname))
  111. (libname (cdr subdir-and-libname)))
  112. ;; Now look in each dir in %LOAD-PATH for `subdir/libfoo.la'. If that
  113. ;; file exists, fetch the dlname from that file and attempt to link
  114. ;; against it. If `subdir/libfoo.la' does not exist, or does not seem
  115. ;; to name any shared library, look for `subdir/libfoo.so' instead and
  116. ;; link against that.
  117. (let check-dirs ((dir-list %load-path))
  118. (if (null? dir-list)
  119. #f
  120. (let* ((dir (in-vicinity (car dir-list) subdir))
  121. (sharlib-full
  122. (or (try-using-libtool-name dir libname)
  123. (try-using-sharlib-name dir libname))))
  124. (if (and sharlib-full (file-exists? sharlib-full))
  125. (link-dynamic-module sharlib-full init)
  126. (check-dirs (cdr dir-list)))))))))
  127. (define (try-using-libtool-name libdir libname)
  128. (let ((libtool-filename (in-vicinity libdir
  129. (string-append libname ".la"))))
  130. (and (file-exists? libtool-filename)
  131. libtool-filename)))
  132. (define (try-using-sharlib-name libdir libname)
  133. (in-vicinity libdir (string-append libname ".so")))
  134. (define (link-dynamic-module filename initname)
  135. ;; Register any linked modules which have been registered on the C level
  136. (register-modules #f)
  137. (let ((dynobj (dynamic-link filename)))
  138. (dynamic-call initname dynobj)
  139. (register-modules dynobj)))
  140. (define (try-module-linked module-name)
  141. (init-dynamic-module module-name))
  142. (define (try-module-dynamic-link module-name)
  143. (and (find-and-link-dynamic-module module-name)
  144. (init-dynamic-module module-name)))
  145. (define (list* . args)
  146. (issue-deprecation-warning "'list*' is deprecated. Use 'cons*' instead.")
  147. (apply cons* args))
  148. ;; The strange prototype system for uniform arrays has been
  149. ;; deprecated.
  150. (define uniform-vector-fill! array-fill!)
  151. (define make-uniform-vector dimensions->uniform-array)
  152. (define (make-uniform-array prot . bounds)
  153. (dimensions->uniform-array bounds prot))
  154. (define (list->uniform-vector prot lst)
  155. (list->uniform-array 1 prot lst))