]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/db/postgresql/ffi/ffi.factor
use radix literals
[factor.git] / basis / db / postgresql / ffi / ffi.factor
index 93f93c9a13ce1952fbc7d1961155be7b13d9bfb7..9a05d6b1d9add30b7702aa7066280837535410c2 100644 (file)
@@ -1,54 +1,55 @@
 ! Copyright (C) 2007, 2008 Doug Coleman.
 ! See http://factorcode.org/license.txt for BSD license.
 ! tested on debian linux with postgresql 8.1
-USING: alien alien.syntax combinators system alien.libraries ;
+USING: alien alien.c-types alien.syntax combinators system
+alien.libraries ;
 IN: db.postgresql.ffi
 
 << "postgresql" {
-    { [ os winnt? ]  [ "libpq.dll" ] }
+    { [ os windows? ]  [ "libpq.dll" ] }
     { [ os macosx? ] [ "libpq.dylib" ] }
     { [ os unix?  ]  [ "libpq.so" ] }
-} cond "cdecl" add-library >>
+} cond cdecl add-library >>
 
 ! ConnSatusType
-CONSTANT: CONNECTION_OK                     HEX: 0
-CONSTANT: CONNECTION_BAD                    HEX: 1
-CONSTANT: CONNECTION_STARTED                HEX: 2
-CONSTANT: CONNECTION_MADE                   HEX: 3
-CONSTANT: CONNECTION_AWAITING_RESPONSE      HEX: 4
-CONSTANT: CONNECTION_AUTH_OK                HEX: 5
-CONSTANT: CONNECTION_SETENV                 HEX: 6
-CONSTANT: CONNECTION_SSL_STARTUP            HEX: 7
-CONSTANT: CONNECTION_NEEDED                 HEX: 8
+CONSTANT: CONNECTION_OK                     0x0
+CONSTANT: CONNECTION_BAD                    0x1
+CONSTANT: CONNECTION_STARTED                0x2
+CONSTANT: CONNECTION_MADE                   0x3
+CONSTANT: CONNECTION_AWAITING_RESPONSE      0x4
+CONSTANT: CONNECTION_AUTH_OK                0x5
+CONSTANT: CONNECTION_SETENV                 0x6
+CONSTANT: CONNECTION_SSL_STARTUP            0x7
+CONSTANT: CONNECTION_NEEDED                 0x8
 
 ! PostgresPollingStatusType
-CONSTANT: PGRES_POLLING_FAILED              HEX: 0
-CONSTANT: PGRES_POLLING_READING             HEX: 1
-CONSTANT: PGRES_POLLING_WRITING             HEX: 2
-CONSTANT: PGRES_POLLING_OK                  HEX: 3
-CONSTANT: PGRES_POLLING_ACTIVE              HEX: 4
+CONSTANT: PGRES_POLLING_FAILED              0x0
+CONSTANT: PGRES_POLLING_READING             0x1
+CONSTANT: PGRES_POLLING_WRITING             0x2
+CONSTANT: PGRES_POLLING_OK                  0x3
+CONSTANT: PGRES_POLLING_ACTIVE              0x4
 
 ! ExecStatusType;
-CONSTANT: PGRES_EMPTY_QUERY                 HEX: 0
-CONSTANT: PGRES_COMMAND_OK                  HEX: 1
-CONSTANT: PGRES_TUPLES_OK                   HEX: 2
-CONSTANT: PGRES_COPY_OUT                    HEX: 3
-CONSTANT: PGRES_COPY_IN                     HEX: 4
-CONSTANT: PGRES_BAD_RESPONSE                HEX: 5
-CONSTANT: PGRES_NONFATAL_ERROR              HEX: 6
-CONSTANT: PGRES_FATAL_ERROR                 HEX: 7
+CONSTANT: PGRES_EMPTY_QUERY                 0x0
+CONSTANT: PGRES_COMMAND_OK                  0x1
+CONSTANT: PGRES_TUPLES_OK                   0x2
+CONSTANT: PGRES_COPY_OUT                    0x3
+CONSTANT: PGRES_COPY_IN                     0x4
+CONSTANT: PGRES_BAD_RESPONSE                0x5
+CONSTANT: PGRES_NONFATAL_ERROR              0x6
+CONSTANT: PGRES_FATAL_ERROR                 0x7
 
 ! PGTransactionStatusType;
-CONSTANT: PQTRANS_IDLE                      HEX: 0
-CONSTANT: PQTRANS_ACTIVE                    HEX: 1
-CONSTANT: PQTRANS_INTRANS                   HEX: 2
-CONSTANT: PQTRANS_INERROR                   HEX: 3
-CONSTANT: PQTRANS_UNKNOWN                   HEX: 4
+CONSTANT: PQTRANS_IDLE                      0x0
+CONSTANT: PQTRANS_ACTIVE                    0x1
+CONSTANT: PQTRANS_INTRANS                   0x2
+CONSTANT: PQTRANS_INERROR                   0x3
+CONSTANT: PQTRANS_UNKNOWN                   0x4
 
 ! PGVerbosity;
-CONSTANT: PQERRORS_TERSE                    HEX: 0
-CONSTANT: PQERRORS_DEFAULT                  HEX: 1
-CONSTANT: PQERRORS_VERBOSE                  HEX: 2
+CONSTANT: PQERRORS_TERSE                    0x0
+CONSTANT: PQERRORS_DEFAULT                  0x1
+CONSTANT: PQERRORS_VERBOSE                  0x2
 
 CONSTANT: InvalidOid 0
 
@@ -58,18 +59,17 @@ TYPEDEF: int PostgresPollingStatusType
 TYPEDEF: int PGTransactionStatusType 
 TYPEDEF: int PGVerbosity 
 
-TYPEDEF: void* PGconn*
-TYPEDEF: void* PGresult*
-TYPEDEF: void* PGcancel*
+C-TYPE: PGconn
+C-TYPE: PGresult
+C-TYPE: PGcancel
 TYPEDEF: uint Oid
-TYPEDEF: uint* Oid*
 TYPEDEF: char pqbool
-TYPEDEF: void* PQconninfoOption*
-TYPEDEF: void* PGnotify*
-TYPEDEF: void* PQArgBlock*
-TYPEDEF: void* PQprintOpt*
-TYPEDEF: void* FILE*
-TYPEDEF: void* SSL*
+C-TYPE: PQconninfoOption
+C-TYPE: PGnotify
+C-TYPE: PQArgBlock
+C-TYPE: PQprintOpt
+C-TYPE: SSL
+C-TYPE: FILE
 
 LIBRARY: postgresql
 
@@ -77,15 +77,15 @@ LIBRARY: postgresql
 
 ! make a new client connection to the backend
 ! Asynchronous (non-blocking)
-FUNCTION: PGconn* PQconnectStart ( char* conninfo ) ;
+FUNCTION: PGconn* PQconnectStart ( c-string conninfo ) ;
 FUNCTION: PostgresPollingStatusType PQconnectPoll ( PGconn* conn ) ;
 
 ! Synchronous (blocking)
-FUNCTION: PGconn* PQconnectdb ( char* conninfo ) ;
-FUNCTION: PGconn* PQsetdbLogin ( char* pghost, char* pgport,
-             char* pgoptions, char* pgtty,
-             char* dbName,
-             char* login, char* pwd ) ;
+FUNCTION: PGconn* PQconnectdb ( c-string conninfo ) ;
+FUNCTION: PGconn* PQsetdbLogin ( c-string pghost, c-string pgport,
+             c-string pgoptions, c-string pgtty,
+             c-string dbName,
+             c-string login, c-string pwd ) ;
 
 : PQsetdb ( M_PGHOST M_PGPORT M_PGOPT M_PGTTY M_DBNAME -- PGconn* )
     f f PQsetdbLogin ;
@@ -116,24 +116,24 @@ FUNCTION: void PQfreeCancel ( PGcancel* cancel ) ;
 FUNCTION: int    PQrequestCancel ( PGconn* conn ) ;
 
 ! Accessor functions for PGconn objects
-FUNCTION: char* PQdb ( PGconn* conn ) ;
-FUNCTION: char* PQuser ( PGconn* conn ) ;
-FUNCTION: char* PQpass ( PGconn* conn ) ;
-FUNCTION: char* PQhost ( PGconn* conn ) ;
-FUNCTION: char* PQport ( PGconn* conn ) ;
-FUNCTION: char* PQtty ( PGconn* conn ) ;
-FUNCTION: char* PQoptions ( PGconn* conn ) ;
+FUNCTION: c-string PQdb ( PGconn* conn ) ;
+FUNCTION: c-string PQuser ( PGconn* conn ) ;
+FUNCTION: c-string PQpass ( PGconn* conn ) ;
+FUNCTION: c-string PQhost ( PGconn* conn ) ;
+FUNCTION: c-string PQport ( PGconn* conn ) ;
+FUNCTION: c-string PQtty ( PGconn* conn ) ;
+FUNCTION: c-string PQoptions ( PGconn* conn ) ;
 FUNCTION: ConnStatusType PQstatus ( PGconn* conn ) ;
 FUNCTION: PGTransactionStatusType PQtransactionStatus ( PGconn* conn ) ;
-FUNCTION: char* PQparameterStatus ( PGconn* conn,
-                  char* paramName ) ;
+FUNCTION: c-string PQparameterStatus ( PGconn* conn,
+                  c-string paramName ) ;
 FUNCTION: int PQprotocolVersion ( PGconn* conn ) ;
 ! FUNCTION: int PQServerVersion ( PGconn* conn ) ;
-FUNCTION: char* PQerrorMessage ( PGconn* conn ) ;
+FUNCTION: c-string PQerrorMessage ( PGconn* conn ) ;
 FUNCTION: int PQsocket ( PGconn* conn ) ;
 FUNCTION: int PQbackendPID ( PGconn* conn ) ;
 FUNCTION: int PQclientEncoding ( PGconn* conn ) ;
-FUNCTION: int PQsetClientEncoding ( PGconn* conn, char* encoding ) ;
+FUNCTION: int PQsetClientEncoding ( PGconn* conn, c-string encoding ) ;
 
 ! May not be compiled into libpq
 ! Get the SSL structure associated with a connection
@@ -153,7 +153,7 @@ FUNCTION: void PQuntrace ( PGconn* conn ) ;
 ! BROKEN
 ! Function types for notice-handling callbacks
 ! typedef void (*PQnoticeReceiver) (void *arg, PGresult *res);
-! typedef void (*PQnoticeProcessor) (void *arg, char* message);
+! typedef void (*PQnoticeProcessor) (void *arg, c-string message);
 ! ALIAS: void* PQnoticeReceiver
 ! ALIAS: void* PQnoticeProcessor
 
@@ -169,43 +169,43 @@ FUNCTION: void PQuntrace ( PGconn* conn ) ;
 ! === in fe-exec.c ===
 
 ! Simple synchronous query
-FUNCTION: PGresult* PQexec ( PGconn* conn, char* query ) ;
+FUNCTION: PGresult* PQexec ( PGconn* conn, c-string query ) ;
 FUNCTION: PGresult* PQexecParams ( PGconn* conn,
-             char* command,
+             c-string command,
              int nParams,
              Oid* paramTypes,
-             char** paramValues,
+             c-string* paramValues,
              int* paramLengths,
              int* paramFormats,
              int resultFormat ) ;
-FUNCTION: PGresult* PQprepare ( PGconn* conn, char* stmtName,
-        char* query, int nParams,
+FUNCTION: PGresult* PQprepare ( PGconn* conn, c-string stmtName,
+        c-string query, int nParams,
         Oid* paramTypes ) ;
 FUNCTION: PGresult* PQexecPrepared ( PGconn* conn,
-             char* stmtName,
+             c-string stmtName,
              int nParams,
-             char** paramValues,
+             c-string* paramValues,
              int* paramLengths,
              int* paramFormats,
              int resultFormat ) ;
 
 ! Interface for multiple-result or asynchronous queries
-FUNCTION: int PQsendQuery ( PGconn* conn, char* query ) ;
+FUNCTION: int PQsendQuery ( PGconn* conn, c-string query ) ;
 FUNCTION: int PQsendQueryParams ( PGconn* conn,
-                  char* command,
+                  c-string command,
                   int nParams,
                   Oid* paramTypes,
-                  char** paramValues,
+                  c-string* paramValues,
                   int* paramLengths,
                   int* paramFormats,
                   int resultFormat ) ;
-FUNCTION: PGresult* PQsendPrepare ( PGconn* conn, char* stmtName,
-            char* query, int nParams,
+FUNCTION: PGresult* PQsendPrepare ( PGconn* conn, c-string stmtName,
+            c-string query, int nParams,
             Oid* paramTypes ) ;
 FUNCTION: int PQsendQueryPrepared ( PGconn* conn,
-                  char* stmtName,
+                  c-string stmtName,
                   int nParams,
-                  char** paramValues,
+                  c-string* paramValues,
                   int *paramLengths,
                   int *paramFormats,
                   int resultFormat ) ;
@@ -219,15 +219,15 @@ FUNCTION: int    PQconsumeInput ( PGconn* conn ) ;
 FUNCTION: PGnotify* PQnotifies ( PGconn* conn ) ;
 
 ! Routines for copy in/out
-FUNCTION: int    PQputCopyData ( PGconn* conn, char* buffer, int nbytes ) ;
-FUNCTION: int    PQputCopyEnd ( PGconn* conn, char* errormsg ) ;
-FUNCTION: int    PQgetCopyData ( PGconn* conn, char** buffer, int async ) ;
+FUNCTION: int    PQputCopyData ( PGconn* conn, c-string buffer, int nbytes ) ;
+FUNCTION: int    PQputCopyEnd ( PGconn* conn, c-string errormsg ) ;
+FUNCTION: int    PQgetCopyData ( PGconn* conn, c-string* buffer, int async ) ;
 
 ! Deprecated routines for copy in/out
-FUNCTION: int    PQgetline ( PGconn* conn, char* string, int length ) ;
-FUNCTION: int    PQputline ( PGconn* conn, char* string ) ;
-FUNCTION: int    PQgetlineAsync ( PGconn* conn, char* buffer, int bufsize ) ;
-FUNCTION: int    PQputnbytes ( PGconn* conn, char* buffer, int nbytes ) ;
+FUNCTION: int    PQgetline ( PGconn* conn, c-string string, int length ) ;
+FUNCTION: int    PQputline ( PGconn* conn, c-string string ) ;
+FUNCTION: int    PQgetlineAsync ( PGconn* conn, c-string buffer, int bufsize ) ;
+FUNCTION: int    PQputnbytes ( PGconn* conn, c-string buffer, int nbytes ) ;
 FUNCTION: int    PQendcopy ( PGconn* conn ) ;
 
 ! Set blocking/nonblocking connection to the backend
@@ -251,25 +251,25 @@ FUNCTION: PGresult* PQfn ( PGconn* conn,
 
 ! Accessor functions for PGresult objects
 FUNCTION: ExecStatusType PQresultStatus ( PGresult* res ) ;
-FUNCTION: char* PQresStatus ( ExecStatusType status ) ;
-FUNCTION: char* PQresultErrorMessage ( PGresult* res ) ;
-FUNCTION: char* PQresultErrorField ( PGresult* res, int fieldcode ) ;
+FUNCTION: c-string PQresStatus ( ExecStatusType status ) ;
+FUNCTION: c-string PQresultErrorMessage ( PGresult* res ) ;
+FUNCTION: c-string PQresultErrorField ( PGresult* res, int fieldcode ) ;
 FUNCTION: int   PQntuples ( PGresult* res ) ;
 FUNCTION: int   PQnfields ( PGresult* res ) ;
 FUNCTION: int   PQbinaryTuples ( PGresult* res ) ;
-FUNCTION: char* PQfname ( PGresult* res, int field_num ) ;
-FUNCTION: int   PQfnumber ( PGresult* res, char* field_name ) ;
+FUNCTION: c-string PQfname ( PGresult* res, int field_num ) ;
+FUNCTION: int   PQfnumber ( PGresult* res, c-string field_name ) ;
 FUNCTION: Oid   PQftable ( PGresult* res, int field_num ) ;
 FUNCTION: int   PQftablecol ( PGresult* res, int field_num ) ;
 FUNCTION: int   PQfformat ( PGresult* res, int field_num ) ;
 FUNCTION: Oid   PQftype ( PGresult* res, int field_num ) ;
 FUNCTION: int   PQfsize ( PGresult* res, int field_num ) ;
 FUNCTION: int   PQfmod ( PGresult* res, int field_num ) ;
-FUNCTION: char* PQcmdStatus ( PGresult* res ) ;
-FUNCTION: char* PQoidStatus ( PGresult* res ) ;
+FUNCTION: c-string PQcmdStatus ( PGresult* res ) ;
+FUNCTION: c-string PQoidStatus ( PGresult* res ) ;
 FUNCTION: Oid   PQoidValue ( PGresult* res ) ;
-FUNCTION: char* PQcmdTuples ( PGresult* res ) ;
-! FUNCTION: char* PQgetvalue ( PGresult* res, int tup_num, int field_num ) ;
+FUNCTION: c-string PQcmdTuples ( PGresult* res ) ;
+! FUNCTION: c-string PQgetvalue ( PGresult* res, int tup_num, int field_num ) ;
 FUNCTION: void* PQgetvalue ( PGresult* res, int tup_num, int field_num ) ;
 FUNCTION: int   PQgetlength ( PGresult* res, int tup_num, int field_num ) ;
 FUNCTION: int   PQgetisnull ( PGresult* res, int tup_num, int field_num ) ;
@@ -292,16 +292,16 @@ FUNCTION: PGresult* PQmakeEmptyPGresult ( PGconn* conn, ExecStatusType status )
 
 ! Quoting strings before inclusion in queries.
 FUNCTION: size_t PQescapeStringConn ( PGconn* conn,
-                                    char* to, char* from, size_t length,
+                                    c-string to, c-string from, size_t length,
                                     int* error ) ;
-FUNCTION: uchar* PQescapeByteaConn ( PGconn* conn,
-                                    char* from, size_t length,
+FUNCTION: c-string PQescapeByteaConn ( PGconn* conn,
+                                    c-string from, size_t length,
                                     size_t* to_length ) ;
-FUNCTION: void* PQunescapeBytea ( uchar* strtext, size_t* retbuflen ) ;
-! FUNCTION: uchar* PQunescapeBytea ( uchar* strtext, size_t* retbuflen ) ;
+FUNCTION: void* PQunescapeBytea ( c-string strtext, size_t* retbuflen ) ;
+! FUNCTION: c-string PQunescapeBytea ( c-string strtext, size_t* retbuflen ) ;
 ! These forms are deprecated!
-FUNCTION: size_t PQescapeString ( void* to, char* from, size_t length ) ;
-FUNCTION: uchar* PQescapeBytea ( uchar* bintext, size_t binlen,
+FUNCTION: size_t PQescapeString ( void* to, c-string from, size_t length ) ;
+FUNCTION: c-string PQescapeBytea ( c-string bintext, size_t binlen,
               size_t* bytealen ) ;
 
 ! === in fe-print.c ===
@@ -312,7 +312,7 @@ FUNCTION: void PQprint ( FILE* fout, PGresult* res, PQprintOpt* ps ) ;
 FUNCTION: void PQdisplayTuples ( PGresult* res,
                                 FILE* fp,               
                                 int fillAlign,
-                                char* fieldSep,
+                                c-string fieldSep,
                                 int printHeader,
                                 int quiet ) ;
 
@@ -326,23 +326,23 @@ FUNCTION: void PQprintTuples ( PGresult* res,
 ! Large-object access routines
 FUNCTION: int    lo_open ( PGconn* conn, Oid lobjId, int mode ) ;
 FUNCTION: int    lo_close ( PGconn* conn, int fd ) ;
-FUNCTION: int    lo_read ( PGconn* conn, int fd, char* buf, size_t len ) ;
-FUNCTION: int    lo_write ( PGconn* conn, int fd, char* buf, size_t len ) ;
+FUNCTION: int    lo_read ( PGconn* conn, int fd, c-string buf, size_t len ) ;
+FUNCTION: int    lo_write ( PGconn* conn, int fd, c-string buf, size_t len ) ;
 FUNCTION: int    lo_lseek ( PGconn* conn, int fd, int offset, int whence ) ;
 FUNCTION: Oid    lo_creat ( PGconn* conn, int mode ) ;
 ! FUNCTION: Oid    lo_creat ( PGconn* conn, Oid lobjId ) ;
 FUNCTION: int    lo_tell ( PGconn* conn, int fd ) ;
 FUNCTION: int    lo_unlink ( PGconn* conn, Oid lobjId ) ;
-FUNCTION: Oid    lo_import ( PGconn* conn, char* filename ) ;
-FUNCTION: int    lo_export ( PGconn* conn, Oid lobjId, char* filename ) ;
+FUNCTION: Oid    lo_import ( PGconn* conn, c-string filename ) ;
+FUNCTION: int    lo_export ( PGconn* conn, Oid lobjId, c-string filename ) ;
 
 ! === in fe-misc.c ===
 
 ! Determine length of multibyte encoded char at *s
-FUNCTION: int    PQmblen ( uchar* s, int encoding ) ;
+FUNCTION: int    PQmblen ( c-string s, int encoding ) ;
 
 ! Determine display length of multibyte encoded char at *s
-FUNCTION: int    PQdsplen ( uchar* s, int encoding ) ;
+FUNCTION: int    PQdsplen ( c-string s, int encoding ) ;
 
 ! Get encoding id from environment variable PGCLIENTENCODING
 FUNCTION: int    PQenv2encoding ( ) ;