/usr/share/guile/site/g-wrap/gw-glib-spec.scm is in guile-g-wrap 1.9.14-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 | ;;;; File: gw-glib-spec.scm
;;;; Copyright (C) 2004-2006 Andreas Rottmann
;;;;
;;;; This program is free software; you can redistribute it and/or
;;;; modify it under the terms of the GNU Lesser General Public
;;;; License as published by the Free Software Foundation; either
;;;; version 2, or (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this software; see the file COPYING. If not,
;;;; write to the Free Software Foundation, 675 Mass Ave, Cambridge,
;;;; MA 02139, USA.
;;;;
;;; Commentary:
;;
; This module is provided for compatibility with G-Wrap 1.3.4. It is
; a stripped-down version of (gnome gw glib-spec) from guile-gnome,
; only providing support for the GList and GSList types.
;;
;;; Code:
(define-module (g-wrap gw-glib-spec)
#:use-module (g-wrap compat)
#:use-module (oop goops)
#:use-module (srfi srfi-34)
#:use-module (srfi srfi-35)
#:use-module (g-wrap)
#:use-module (g-wrap c-codegen)
#:use-module (g-wrap util)
#:use-module (g-wrap c-types)
#:use-module (g-wrap guile)
#:use-module (g-wrap guile ws standard))
(define-class <glib-wrapset> (<gw-guile-wrapset>)
#:id 'gw-glib #:dependencies '(standard))
(define-method (client-global-declarations-cg (ws <glib-wrapset>))
'("#include <glib.h>\n"))
(define-method (global-declarations-cg (ws <glib-wrapset>))
(list
(next-method)
"#include <glib.h>\n"))
(define-method (initialize (ws <glib-wrapset>) initargs)
(next-method ws (append '(#:module (g-wrap gw-glib) #:shlib-abs? #t) initargs))
(add-type! ws (make <glist-of-type> #:name 'glist-of
#:type-cname "GList*" #:func-prefix "g_list"))
(add-type! ws (make <glist-of-type> #:name 'gslist-of
#:type-cname "GSList*" #:func-prefix "g_slist")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ((glist-of (<gtk-window> gw:const) gw:const) win-list)
;; shamelessly stolen from upstream g-wrap so that we can use glib 2.0
(define-class <glist-of-type> (<gw-type>)
(type-cname #:getter type-cname #:init-keyword #:type-cname)
(func-prefix #:getter func-prefix #:init-keyword #:func-prefix))
(define-class <gw-collection-typespec> (<gw-typespec>)
(sub-typespec #:getter sub-typespec #:init-keyword #:sub-typespec))
(define-method (all-types (ts <gw-collection-typespec>))
(cons (type (sub-typespec ts)) (next-method)))
(define-method (c-type-name (type <glist-of-type>))
(type-cname type))
(define-method (c-type-name (type <glist-of-type>)
(typespec <gw-collection-typespec>))
(if (memq 'const (options typespec))
(list "const " (type-cname type))
(type-cname type)))
;; if this succeeds, the glist-of typespec-options will be
;; (sub-typespec (caller-owned | callee-owned) [const])
(define-method (make-typespec (type <glist-of-type>) (options <list>))
(if (null? options)
(raise (condition
(&gw-bad-typespec
(type type) (options options)
(message "Missing glist-of options form.")))))
(if (< (length options) 2)
(raise
(condition
(&gw-bad-typespec
(type type) (options options)
(message "glist-of options form must have at least 2 options.")))))
(let ((sub-typespec (car options))
(glist-options (cdr options))
(remainder (cdr options)))
(if (not (is-a? sub-typespec <gw-typespec>))
(raise (condition
(&gw-bad-typespec
(type type) (options options)
(message "glist-of options form must have a sub-typespec as first option.")))))
(set! remainder (delq 'const remainder))
(if (and (memq 'caller-owned remainder)
(memq 'callee-owned remainder))
(raise (condition
(&gw-bad-typespec
(type type) (options options)
(message
"Bad glist-of options form (caller and callee owned!).")))))
(if (not (or (memq 'caller-owned remainder)
(memq 'callee-owned remainder)))
(raise
(condition
(&gw-bad-typespec
(type type) (options options)
(message
"Bad glist-of options form (must be caller or callee owned!).")))))
(set! remainder (delq 'caller-owned remainder))
(set! remainder (delq 'callee-owned remainder))
(if (null? remainder)
(make <gw-collection-typespec>
#:type type
#:sub-typespec sub-typespec
#:options glist-options)
(raise (condition
(&gw-bad-typespec
(type type) (options options)
(message
(format #f "Bad glist-of options form - spurious options: ~S"
remainder))))))))
(define-method (unwrap-value-cg (glist-type <glist-of-type>)
(value <gw-value>)
status-var
(inlined? <boolean>))
(let* ((c-var (var value))
(scm-var (scm-var value))
(sub-typespec (sub-typespec (typespec value)))
(sub-type (type sub-typespec))
(tmp-rest-var (gen-c-tmp "scm_rest"))
(func-prefix (func-prefix glist-type))
(sub-item-c-type (c-type-name sub-type sub-typespec))
(tmp-sub-item-c-var (gen-c-tmp "c_item"))
(tmp-sub-item-scm-var (gen-c-tmp "scm_item"))
(tmp-sub-item (make <gw-value>
#:typespec sub-typespec
#:var tmp-sub-item-c-var
#:wrapped-var (string-append
"&" tmp-sub-item-scm-var)))
(tmp-cursor (gen-c-tmp "cursor")))
(list
"{\n"
" SCM " tmp-rest-var " = " scm-var ";\n"
" " c-var "= NULL;\n"
" while(!SCM_NULLP(" tmp-rest-var ")\n"
" && (! " `(gw:error? ,status-var) "))\n"
" {\n"
" " sub-item-c-type " " tmp-sub-item-c-var ";\n"
" SCM " tmp-sub-item-scm-var " = SCM_CAR(" tmp-rest-var ");\n"
"\n"
(unwrap-value-cg sub-type tmp-sub-item status-var #t)
"\n"
" if(! " `(gw:error? ,status-var) " )\n"
" {\n"
" " c-var " = " func-prefix "_prepend (" c-var ", (gpointer)" tmp-sub-item-c-var");\n"
" }\n"
" " tmp-rest-var " = SCM_CDR (" tmp-rest-var ");\n"
" }\n"
" if(!" `(gw:error? ,status-var) ")\n"
" {\n"
" " c-var " = " func-prefix "_reverse(" c-var ");\n"
" }\n"
" else\n"
" {\n"
" " (c-type-name glist-type (typespec value)) tmp-cursor " = " c-var ";\n"
" while(" tmp-cursor ")\n"
" {\n"
" " sub-item-c-type " " tmp-sub-item-c-var ";\n"
" " tmp-sub-item-c-var " = ( " sub-item-c-type ") "
(string-append tmp-cursor "->data") ";\n"
;; FIMXE: had force #t here
(destroy-value-cg sub-type tmp-sub-item status-var #t)
tmp-cursor " = " (string-append tmp-cursor "->next") ";\n"
" }\n"
" " func-prefix "_free(" c-var ");\n"
" " c-var " = NULL;\n"
" }\n"
"}\n")))
(define-method (wrap-value-cg (glist-type <glist-of-type>)
(value <gw-value>)
status-var
(inlined? <boolean>))
(let* ((c-var (var value))
(scm-var (scm-var value))
(sub-typespec (sub-typespec (typespec value)))
(sub-type (type sub-typespec))
(tmp-rest-var (gen-c-tmp "c_rest"))
(sub-item-c-type (c-type-name sub-type sub-typespec))
(tmp-sub-item-c-var (gen-c-tmp "c_item"))
(tmp-sub-item-scm-var (gen-c-tmp "scm_item"))
(tmp-sub-item (make <gw-value>
#:typespec sub-typespec
#:var tmp-sub-item-c-var
#:wrapped-var (string-append
"&" tmp-sub-item-scm-var))))
(list
(c-type-name glist-type (typespec value)) tmp-rest-var " = " c-var ";\n"
scm-var "= SCM_EOL;\n"
"while(" tmp-rest-var " && (! " `(gw:error? ,status-var) "))\n"
"{\n"
" " sub-item-c-type " " tmp-sub-item-c-var ";\n"
" SCM " tmp-sub-item-scm-var ";\n"
"\n"
" " tmp-sub-item-c-var " = ( " sub-item-c-type ") "
(string-append tmp-rest-var "->data") ";\n"
"\n"
(wrap-value-cg sub-type tmp-sub-item status-var #t)
"\n"
" if(! " `(gw:error? ,status-var) " )\n"
" {\n"
" " scm-var " = scm_cons (" tmp-sub-item-scm-var ", " scm-var ");\n"
" }\n"
" " tmp-rest-var " = " (string-append tmp-rest-var "->next") ";\n"
"}\n"
"if(!" `(gw:error? ,status-var) ")\n"
"{\n"
" " scm-var " = scm_reverse(" scm-var ");\n"
"}\n")))
(define-method (destroy-value-cg (glist-type <glist-of-type>)
(value <gw-value>)
status-var
(inlined? <boolean>))
(let* ((c-var (var value))
(scm-var (scm-var value))
(options (options (typespec value)))
(sub-typespec (sub-typespec (typespec value)))
(sub-type (type sub-typespec))
(func-prefix (func-prefix glist-type))
(sub-item-c-type (c-type-name sub-type sub-typespec))
(tmp-sub-item-c-var (gen-c-tmp "c_item"))
(tmp-sub-item (make <gw-value>
#:typespec sub-typespec
#:var tmp-sub-item-c-var))
(tmp-cursor (gen-c-tmp "cursor")))
(list
"{\n"
" " (c-type-name glist-type (typespec value)) tmp-cursor " = " c-var ";\n"
" while(" tmp-cursor ")\n"
" {\n"
" " sub-item-c-type " " tmp-sub-item-c-var ";\n"
" " tmp-sub-item-c-var " = ( " sub-item-c-type ") "
(string-append tmp-cursor "->data") ";\n"
(destroy-value-cg sub-type tmp-sub-item status-var #t)
tmp-cursor " = " (string-append tmp-cursor "->next") ";\n"
" }\n"
(if (memq 'caller-owned options)
(list " if(" c-var ")\n"
" {\n"
" " func-prefix "_free(" c-var ");\n"
" " c-var " = NULL;\n"
" }\n")
'())
"}\n")))
(gw:register-wrapset "gw-glib" 'gw-glib)
|