summaryrefslogtreecommitdiff
path: root/drmaa/v1/low.scm
blob: 3003052b227c9179797e5b5f4a4e7b7cf88ae598 (about) (plain)
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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
;;; Guile DRMAA --- Guile bindings for DRMAA
;;; Copyright © 2020, 2021 Ricardo Wurmus <rekado@elephly.net>
;;;
;;; This file is part of Guile DRMAA.
;;;
;;; Guile DRMAA is free software; you can redistribute it and/or modify it
;;; under the terms of the GNU General Public License as published by
;;; the Free Software Foundation; either version 3 of the License, or (at
;;; your option) any later version.
;;;
;;; Guile DRMAA 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 General Public License for more details.
;;;
;;; You should have received a copy of the GNU General Public License
;;; along with Guile DRMAA.  If not, see <http://www.gnu.org/licenses/>.

(define-module (drmaa v1 low)
  #:use-module (drmaa v1 ffi)
  #:use-module (drmaa errors)
  #:use-module (bytestructures guile)
  #:use-module (system foreign)
  #:use-module (system ffi-help-rt)
  #:use-module (ice-9 match)
  #:use-module (rnrs bytevectors)
  #:use-module (rnrs enums)
  #:use-module (srfi srfi-34)
  #:use-module (srfi srfi-35)
  #:export (DRMAA

            get-next-attr-name!
            get-next-attr-value!
            get-next-job-id!
            get-num-attr-names
            get-num-attr-values
            get-num-job-ids
            release-attr-names!
            release-attr-values!
            release-job-ids!

            init-session!
            exit-session!

            allocate-job-template!
            delete-job-template!
            set-attribute!
            get-attribute
            set-vector-attribute!
            get-vector-attribute
            get-attribute-names
            get-vector-attribute-names

            run-job
            run-bulk-jobs

            control
            job-ps
            synchronize
            wait

            w-if-exited?
            w-exit-status
            w-if-signaled?
            w-termsig
            w-coredump?
            w-if-aborted?

            get-contact
            drmaa-version
            get-drm-system
            get-drmaa-implementation))

;; XXX: patch (drmaa v1 ffi) because it uses an undefined
;; procedure.  The generated code for drmaa_set_vector_attribute uses
;; unwrap~array, which is not implemented in ffi-help-rt.
;; (This may not be necessary for nyacc 1.03.1+.)
(module-define! (resolve-module '(drmaa v1 ffi))
                'unwrap~array
                (@@ (drmaa v1 ffi) unwrap~pointer))

(define (make-cstr-array string-list)
  "Return a bytevector containing pointers to each of the strings in
STRING-LIST."
  (let* ((n (length string-list))
         (pointers (map string->pointer string-list))
         (addresses (map pointer-address pointers))
         ;; Make it one item longer, because it needs to be a
         ;; NULL-terminated array.
	     (bv (make-bytevector (* (1+ n) (sizeof '*)) 0))
	     (bv-set! (case (sizeof '*)
		            ((4) bytevector-u32-native-set!)
		            ((8) bytevector-u64-native-set!))))
    (for-each (lambda (address index)
                (bv-set! bv (* (sizeof '*) index) address))
              addresses (iota n))
    bv))

(define-syntax-rule (return ret success error-message)
  (cond
   ((eq? ret (DRMAA 'ERRNO_SUCCESS)) success)
   (else
    (raise (condition
            (&drmaa-error (code ret))
            (&message
             (message
              (format #false "~a"
                      (char*->string error-message)))))))))

(define (DRMAA sym)
  (or (drmaa-v1-ffi-symbol-val (symbol-append 'DRMAA_ sym))
      (raise (condition
              (&message
               (message
                (format #false "Unknown DRMAA symbol: ~a" sym)))))))


;;; String vector helpers

(define (get-next-attr-name! names)
  (let* ((name
          (make-char* (bytevector->pointer
                       (make-bytevector (DRMAA 'ATTR_BUFFER)))))
         (ret (drmaa_get_next_attr_name
               names name
               (DRMAA 'ATTR_BUFFER))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (char*->string name))))

(define (get-next-attr-value! values)
  (let* ((value
          (make-char* (bytevector->pointer
                       (make-bytevector (DRMAA 'ATTR_BUFFER)))))
         (ret (drmaa_get_next_attr_value
               values value
               (DRMAA 'ATTR_BUFFER))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (char*->string value))))

(define (get-next-job-id! values)
  (let* ((value
          (make-char* (bytevector->pointer
                       ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
                       (make-bytevector (DRMAA 'JOBNAME_BUFFER)))))
         (ret (drmaa_get_next_job_id
               values value
               ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
               (DRMAA 'JOBNAME_BUFFER))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (char*->string value))))

(define (get-num-attr-names values)
  (let* ((size (make-size_t))
         (ret (drmaa_get_num_attr_names
               values (pointer-to size))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (fh-object-ref size))))

(define (get-num-attr-values values)
  (let* ((size (make-size_t))
         (ret (drmaa_get_num_attr_values
               values (pointer-to size))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (fh-object-ref size))))

(define (get-num-job-ids values)
  (let* ((size (make-size_t))
         (ret (drmaa_get_num_job_ids
               values (pointer-to size))))
    (and (eq? ret (DRMAA 'ERRNO_SUCCESS))
         (fh-object-ref size))))

(define (release-attr-names! values)
  (drmaa_release_attr_names values)
  #true)

(define (release-attr-values! values)
  (drmaa_release_attr_values values)
  #true)

(define (release-job-ids! values)
  (drmaa_release_job_ids values)
  #true)

(define (extract type)
  (define next
    (match type
      ('job-id get-next-job-id!)
      ('name   get-next-attr-name!)
      ('value  get-next-attr-value!)))
  (define release
    (match type
      ('job-id release-job-ids!)
      ('name   release-attr-names!)
      ('value  release-attr-values!)))
  (lambda (values)
    (let loop ((res '()))
      (let ((item (next values)))
        (if item
            (loop (cons item res))
            (begin
              (release values)
              (reverse res)))))))

(define extract-job-ids
  (extract 'job-id))
(define extract-names
  (extract 'name))
(define extract-values
  (extract 'value))


;;; Session management

(define* (init-session! #:optional contact)
  "Initialize the DRMAA library and create a new DRMAA session.  If
the binary module provides only one DRMAA implementation, the string
CONTACT need not be provided; in that case the default implementation
will be used."
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_init (or contact %null-pointer)
                        error-message
                        (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))

(define (exit-session!)
  "Terminate an existing DRMAA session.  Queued and running jobs will
not be affected by this."
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_exit error-message
                        (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))


;;; Job templates

(define (allocate-job-template!)
  (let ((template (make-drmaa_job_template_t*))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_allocate_job_template (pointer-to template)
                                         error-message
                                         (DRMAA 'ERROR_STRING_BUFFER))
            template
            error-message)))

(define (delete-job-template! template)
  ;; TODO: Call this in a finalizer.
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_delete_job_template template
                                       error-message
                                       (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))

(define (set-attribute! template name value)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_set_attribute template
                                 (string->pointer name) value
                                 error-message
                                 (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))

(define (get-attribute template name)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (value
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ATTR_BUFFER))))))
    (return (drmaa_get_attribute template
                                 (string->pointer name)
                                 value
                                 (DRMAA 'ATTR_BUFFER)
                                 error-message
                                 (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string value)
            error-message)))

(define (set-vector-attribute! template name . values)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (array (make-cstr-array values)))
    (return (drmaa_set_vector_attribute template
                                        name
                                        (bytevector->pointer array)
                                        error-message
                                        (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))

(define (get-vector-attribute template name)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (values (make-drmaa_attr_values_t*)))
    (return (drmaa_get_vector_attribute template
                                        name
                                        (pointer-to values)
                                        error-message
                                        (DRMAA 'ERROR_STRING_BUFFER))
            (extract-values values)
            error-message)))

(define (get-attribute-names)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (names (make-drmaa_attr_names_t*)))
    (return (drmaa_get_attribute_names (pointer-to names)
                                       error-message
                                       (DRMAA 'ERROR_STRING_BUFFER))
            (extract-names names)
            error-message)))

(define (get-vector-attribute-names)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (names (make-drmaa_attr_names_t*)))
    (return (drmaa_get_vector_attribute_names (pointer-to names)
                                              error-message
                                              (DRMAA 'ERROR_STRING_BUFFER))
            (extract-names names)
            error-message)))


;;; Job submission

(define (run-job template)
  "Submit a single job with the attributes defined in the job
template.  Upon success return the job identifier."
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (job-id
         (make-char* (bytevector->pointer
                      ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
                      (make-bytevector (DRMAA 'JOBNAME_BUFFER))))))
    (return (drmaa_run_job job-id
                           ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
                           (DRMAA 'JOBNAME_BUFFER)
                           template
                           error-message
                           (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string job-id)
            error-message)))

(define* (run-bulk-jobs template end
                        #:key
                        (start 1) (increment 1))
  "Submit a set of parametric jobs, which can be run concurrently.
The attributes defined in TEMPLATE are used for every job in the set.
Each job is identical except for its index.  The first job has an
index equal to START; the next has an index equal to the sum of START
and INCREMENT.  END is the maximum value of the index, but the value
of the last job's index may not be equal to END if the difference
between START and END is not evenly divisible by INCREMENT.

Return a list of job identifiers."
  (unless (positive? start)
    (raise (condition
            (&message
             (message "`start' must be greater than or equal to 1")))))
  (unless (<= start end)
    (raise (condition
            (&message
             (message "`start' must be less than or equal to `end'")))))
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (job-ids (make-drmaa_job_ids_t*)))
    (return (drmaa_run_bulk_jobs
             (pointer-to job-ids)
             template
             start end increment
             error-message
             (DRMAA 'ERROR_STRING_BUFFER))
            (extract-job-ids job-ids)
            error-message)))


;;; Job status and control

(define (control job-id action)
  "Enact the ACTION on the job identified by JOB-ID.  The following
symbols are considered valid actions: suspend, resume, hold, release,
and terminate.  If JOB-ID is the symbol *, all jobs submitted during
the current session will be affected."
  (unless (member action '(suspend resume hold release terminate))
    (raise (condition
            (&message
             (message
              (format #false "Invalid action: ~a" action))))))
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (action
         (DRMAA (symbol-append 'CONTROL_
                               (string->symbol
                                (string-upcase
                                 (symbol->string action)))))))
    (return (drmaa_control (match job-id
                             ('* (DRMAA 'JOB_IDS_SESSION_ALL))
                             (_ job-id))
                           action
                           error-message
                           (DRMAA 'ERROR_STRING_BUFFER))
            #true
            error-message)))

(define (job-status->symbol status-code)
  (cond
   ((eq? status-code (DRMAA 'PS_FAILED))
    'failed)
   ((eq? status-code (DRMAA 'PS_DONE))
    'done)
   ((eq? status-code (DRMAA 'PS_USER_SYSTEM_SUSPENDED))
    'user-system-suspended)
   ((eq? status-code (DRMAA 'PS_USER_SUSPENDED))
    'user-suspended)
   ((eq? status-code (DRMAA 'PS_RUNNING))
    'running)
   ((eq? status-code (DRMAA 'PS_USER_SYSTEM_ON_HOLD))
    'user-system-on-hold)
   ((eq? status-code (DRMAA 'PS_USER_ON_HOLD))
    'user-on-hold)
   ((eq? status-code (DRMAA 'PS_SYSTEM_ON_HOLD))
    'system-on-hold)
   ((eq? status-code (DRMAA 'PS_QUEUED_ACTIVE))
    'queued-active)
   ((eq? status-code (DRMAA 'PS_UNDETERMINED))
    'undetermined)
   (else
    (raise (condition
            (&message
             (message
              (format #false "Unexpected status: ~a" status-code))))))))

(define (job-ps job-id)
  (let ((error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER)))))
        (status-code (make-uint8)))
    (return (drmaa_job_ps job-id
                          (pointer-to status-code)
                          error-message
                          (DRMAA 'ERROR_STRING_BUFFER))
            (job-status->symbol status-code)
            error-message)))

(define (synchronize job-ids timeout dispose?)
  (let ((timeout
         (or timeout (DRMAA 'TIMEOUT_WAIT_FOREVER)))
        (job-ids (make-cstr-array job-ids))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_synchronize (bytevector->pointer job-ids)
                               timeout
                               (if dispose? 1 0)
                               error-message
                               (DRMAA 'ERROR_STRING_BUFFER))
            #true error-message)))

(define* (wait job-id #:optional timeout)
  "Wait for the completion of a job with identifier JOB-ID.  If the
JOB-ID is the special symbol '*, wait for the completion of any job
that has been submitted during this session.

TIMEOUT (an integer) specifies the number of seconds to block.  If it
is not provided or is #FALSE this procedure will block forever.

This procedure returns three values: the identifier of the job that
has completed, the status code of the job (an opaque value), and an
alist of resource usage statistics."
  (let ((timeout
         (or timeout (DRMAA 'TIMEOUT_WAIT_FOREVER)))
        (job-id-out
         (make-char* (bytevector->pointer
                      ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
                      (make-bytevector (DRMAA 'JOBNAME_BUFFER)))))
        (status-code (make-uint8))
        (rusage (make-drmaa_attr_values_t*))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wait (match job-id
                          ('* (DRMAA 'JOB_IDS_SESSION_ANY))
                          (_ job-id))
                        job-id-out
                        ;; TODO: Perhaps not correct to use JOBNAME_BUFFER here
                        (DRMAA 'JOBNAME_BUFFER)
                        (pointer-to status-code)
                        timeout
                        (pointer-to rusage)
                        error-message
                        (DRMAA 'ERROR_STRING_BUFFER))
            (values job-id-out
                    status-code
                    (map (lambda (value)
                           (or (and=> (string-index value #\=)
                                      (lambda (split-point)
                                        (cons (string-take value split-point)
                                              (string-drop value (1+ split-point)))))
                               (cons value value)))
                         (extract-values rusage)))
            error-message)))

(define (w-if-exited? status-code)
  (let ((exited (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wifexited (pointer-to exited)
                             status-code
                             error-message
                             (DRMAA 'ERROR_STRING_BUFFER))
            (positive? exited)
            error-message)))

(define (w-exit-status status-code)
  (let ((exit-status (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wexitstatus (pointer-to exit-status)
                               status-code
                               error-message
                               (DRMAA 'ERROR_STRING_BUFFER))
            exit-status
            error-message)))

(define (w-if-signaled? status-code)
  "Return #TRUE if the job was terminated because it received a signal."
  (let ((signaled (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wifsignaled (pointer-to signaled)
                               status-code
                               error-message
                               (DRMAA 'ERROR_STRING_BUFFER))
            (positive? signaled)
            error-message)))

(define (w-termsig status-code)
  "Return the name of the signal that terminated the job."
  (let ((signal
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'SIGNAL_BUFFER)))))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wtermsig signal
                            (DRMAA 'SIGNAL_BUFFER)
                            status-code
                            error-message
                            (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string signal)
            error-message)))

(define (w-coredump? status-code)
  "Return #TRUE if the STATUS-CODE indicates that a core image of the
terminated job was created."
  (let ((core-dumped (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wcoredump (pointer-to core-dumped)
                             status-code
                             error-message
                             (DRMAA 'ERROR_STRING_BUFFER))
            (positive? core-dumped)
            error-message)))

(define (w-if-aborted? status-code)
  "Return #TRUE if the STATUS-CODE indicates that the job ended before
entering the running state."
  (let ((aborted (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_wifaborted (pointer-to aborted)
                              status-code
                              error-message
                              (DRMAA 'ERROR_STRING_BUFFER))
            (positive? aborted)
            error-message)))


;;; Auxilliary functions

(define (get-contact)
  "When called before INIT-SESSION! return a string containing a
comma-delimited list of default DRMAA implementation contact strings,
one per DRM implementation provided.  If called after INIT-SESSION!
return the contact string for the DRM system for which the library has
been initialized."
  (let ((contact
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'CONTACT_BUFFER)))))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_get_DRM_system contact
                                  (DRMAA 'CONTACT_BUFFER)
                                  error-message
                                  (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string contact)
            error-message)))

(define (drmaa-version)
  "Return as a pair the major and minor version of the DRMAA C binding
specification implemented by the selected DRMAA implementation."
  (let ((major (make-uint8))
        (minor (make-uint8))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_version (pointer-to major)
                           (pointer-to minor)
                           error-message
                           (DRMAA 'ERROR_STRING_BUFFER))
            (cons (fh-object-ref major)
                  (fh-object-ref minor))
            error-message)))

(define (get-drm-system)
  "When called before INIT-SESSION! return a string containing a
comma-delimited list of DRM system identifiers, one per DRM system
implementation provided.  If called after INIT-SESSION! return the
selected DRM system."
  (let ((drm-system
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'DRM_SYSTEM_BUFFER)))))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_get_DRM_system drm-system
                                  (DRMAA 'DRM_SYSTEM_BUFFER)
                                  error-message
                                  (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string drm-system)
            error-message)))

(define (get-drmaa-implementation)
  "When called before INIT-SESSION! return a string containing a
comma-delimited list of DRMAA implementations, one per DRMAA
implementation provided.  If called after INIT-SESSION! return the
selected DRMAA implementation."
  (let ((drmaa-implementation
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'DRMAA_IMPL_BUFFER)))))
        (error-message
         (make-char* (bytevector->pointer
                      (make-bytevector (DRMAA 'ERROR_STRING_BUFFER))))))
    (return (drmaa_get_DRMAA_implementation drmaa-implementation
                                            (DRMAA 'DRMAA_IMPL_BUFFER)
                                            error-message
                                            (DRMAA 'ERROR_STRING_BUFFER))
            (char*->string drmaa-implementation)
            error-message)))