branch: elpa/emacsql
commit 8dd25b030701c1f9c8fe6c38b89399a82dfa558b
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>

    Place declare-function at top-level
    
    As suggested by Stefan Monnier:
    
    > I just saw this code in emacsql:
    >
    >     (unless (require 'sqlite3 nil t)
    >       (declare-function sqlite3-open "sqlite3-api")
    >       (declare-function sqlite3-exec "sqlite3-api")
    >       (declare-function sqlite3-close "sqlite3-api"))
    >
    > This isn't right: the `require` and the `unless` will be executed only at
    > runtime, not during compilation, but that that time the
    > `declare-function`s will have disappeared, so you'll end up running
    >
    >     (unless (require 'sqlite3 nil t)
    >       )
    >
    > Also the effect of `declare-function` should be limited to "the current
    > scope", which could be argued to end at the end of the `unless` (I don't
    > know if that's how the byte-compiler currently treats it, but that's how
    > I think it should, ideally).
    >
    > So I think you want to just remove the `unless`.
    > This way both the `require` and the `declare-function`s will be at
    > top-level where the compiler likes them to be.
---
 emacsql-pg.el             | 14 +++++++-------
 emacsql-sqlite-builtin.el |  8 ++++----
 emacsql-sqlite-module.el  |  8 ++++----
 3 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/emacsql-pg.el b/emacsql-pg.el
index c039fde856..40dacbf2ec 100644
--- a/emacsql-pg.el
+++ b/emacsql-pg.el
@@ -21,13 +21,13 @@
 
 (require 'emacsql)
 
-(unless (require 'pg nil t)
-  (declare-function pg-connect "pg"
-                    ( dbname user &optional
-                      (password "") (host "localhost") (port 5432) (tls nil)))
-  (declare-function pg-disconnect "pg" (con))
-  (declare-function pg-exec "pg" (connection &rest args))
-  (declare-function pg-result "pg" (result what &rest arg)))
+(require 'pg nil t)
+(declare-function pg-connect "pg"
+                  ( dbname user &optional
+                    (password "") (host "localhost") (port 5432) (tls nil)))
+(declare-function pg-disconnect "pg" (con))
+(declare-function pg-exec "pg" (connection &rest args))
+(declare-function pg-result "pg" (result what &rest arg))
 
 (defclass emacsql-pg-connection (emacsql-connection)
   ((pgcon :reader emacsql-pg-pgcon :initarg :pgcon)
diff --git a/emacsql-sqlite-builtin.el b/emacsql-sqlite-builtin.el
index a5fadd2988..7d28339821 100644
--- a/emacsql-sqlite-builtin.el
+++ b/emacsql-sqlite-builtin.el
@@ -18,10 +18,10 @@
 
 (require 'emacsql)
 
-(unless (require 'sqlite nil t)
-  (declare-function sqlite-open "sqlite")
-  (declare-function sqlite-select "sqlite")
-  (declare-function sqlite-close "sqlite"))
+(require 'sqlite nil t)
+(declare-function sqlite-open "sqlite")
+(declare-function sqlite-select "sqlite")
+(declare-function sqlite-close "sqlite")
 
 (emacsql-register-reserved emacsql-sqlite-reserved)
 
diff --git a/emacsql-sqlite-module.el b/emacsql-sqlite-module.el
index 617cbc7d84..63fea3c7bf 100644
--- a/emacsql-sqlite-module.el
+++ b/emacsql-sqlite-module.el
@@ -18,10 +18,10 @@
 
 (require 'emacsql)
 
-(unless (require 'sqlite3 nil t)
-  (declare-function sqlite3-open "sqlite3-api")
-  (declare-function sqlite3-exec "sqlite3-api")
-  (declare-function sqlite3-close "sqlite3-api"))
+(require 'sqlite3 nil t)
+(declare-function sqlite3-open "sqlite3-api")
+(declare-function sqlite3-exec "sqlite3-api")
+(declare-function sqlite3-close "sqlite3-api")
 (defvar sqlite-open-readwrite)
 (defvar sqlite-open-create)
 

Reply via email to