Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

symbol conflicts when loading a file #4

Open
phmarek opened this issue Feb 19, 2014 · 3 comments
Open

symbol conflicts when loading a file #4

phmarek opened this issue Feb 19, 2014 · 3 comments

Comments

@phmarek
Copy link

phmarek commented Feb 19, 2014

I tried loading a C file into SBCL 1.1.14-2 (debian, amd64), but got this error:

(vacietis:load-c-file "...")
read error during compile-file:

  use-package #<package "VACIETIS.LIBC.STDIO.H"> causes
  name-conflicts in #<package "COMMON-LISP-USER"> between the
  following symbols:
    vacietis.libc.stdio.h:remove, common-lisp:remove

Do you have a hint for me, please?

@phmarek
Copy link
Author

phmarek commented Feb 19, 2014

Loading in a completely empty package does work ... although I now get
Can't find libc include file sys/ioctl.h
Oh well, let's go on.

@phmarek
Copy link
Author

phmarek commented Feb 19, 2014

Is there some way to use files from /usr/include within Vacietis? Perhaps after some SWIG conversion?

I'd need some more include files, and I'd like to avoid writing that by hand.

@ramenbytes
Copy link

ramenbytes commented Feb 14, 2018

Hi! Not sure if you still need or want a solution but perhaps it will be helpful to others. I ran into the same problem but was able to solve it by wrapping the call to use-package with a handler-bind form that invokes the take-new restart. Below is the code for the function with my additions:

(defun include-libc-file (include-file)
  (let ((libc-package (find-package (format nil "VACIETIS.LIBC.~:@(~A~)"
                                            include-file))))
    (unless libc-package
      (error "Can't find libc include file ~a" include-file))
    (handler-bind ((sb-ext:name-conflict
                     (lambda (c)
                       (invoke-restart 'sb-impl::take-new))))
      (use-package libc-package))
    (awhen (and (boundp       (pp-defines libc-package))
                (symbol-value (pp-defines libc-package)))
      (maphash (lambda (name expansion)
                 (setf (gethash (intern (symbol-name name) *package*)
                                (compiler-state-pp *compiler-state*))
                       expansion))
               it))
    (awhen (probe-file
            (merge-pathnames
             (format nil "../libc/~a" include-file)
             #.(or *compile-file-truename* *load-truename*)))
      (%load-c-file it *compiler-state*))))

This was in compiler/libc-support.lisp. Note that this is SBCL specific due to symbols used. My guess is that it should be trivial to adapt to other CL implementations. Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants