mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-28 20:03:43 +03:00
Dropped C API interface
I guess it was unused as it only contained two init functions. The Capsule should do things better now I guess.
This commit is contained in:
parent
7b2e8f0aa4
commit
8f17ccf784
|
@ -47,64 +47,12 @@ extern "C" {
|
|||
#define THREADSAFETY 2
|
||||
#define PARAMSTYLE "pyformat"
|
||||
|
||||
/* C API functions */
|
||||
#define psyco_errors_fill_NUM 0
|
||||
#define psyco_errors_fill_RETURN void
|
||||
#define psyco_errors_fill_PROTO (PyObject *dict)
|
||||
#define psyco_errors_set_NUM 1
|
||||
#define psyco_errors_set_RETURN void
|
||||
#define psyco_errors_set_PROTO (PyObject *type)
|
||||
|
||||
/* Total number of C API pointers */
|
||||
#define PSYCOPG_API_pointers 2
|
||||
|
||||
#ifdef PSYCOPG_MODULE
|
||||
|
||||
/** This section is used when compiling psycopgmodule.c & co. **/
|
||||
HIDDEN psyco_errors_fill_RETURN psyco_errors_fill psyco_errors_fill_PROTO;
|
||||
HIDDEN psyco_errors_set_RETURN psyco_errors_set psyco_errors_set_PROTO;
|
||||
|
||||
/* global exceptions */
|
||||
extern HIDDEN PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
|
||||
*InternalError, *OperationalError, *ProgrammingError,
|
||||
*IntegrityError, *DataError, *NotSupportedError;
|
||||
extern HIDDEN PyObject *QueryCanceledError, *TransactionRollbackError;
|
||||
|
||||
/* python versions and compatibility stuff */
|
||||
#ifndef PyMODINIT_FUNC
|
||||
#define PyMODINIT_FUNC void
|
||||
#endif
|
||||
|
||||
#else
|
||||
/** This section is used in modules that use psycopg's C API **/
|
||||
|
||||
static void **PSYCOPG_API;
|
||||
|
||||
#define psyco_errors_fill \
|
||||
(*(psyco_errors_fill_RETURN (*)psyco_errors_fill_PROTO) \
|
||||
PSYCOPG_API[psyco_errors_fill_NUM])
|
||||
#define psyco_errors_set \
|
||||
(*(psyco_errors_set_RETURN (*)psyco_errors_set_PROTO) \
|
||||
PSYCOPG_API[psyco_errors_set_NUM])
|
||||
|
||||
/* Return -1 and set exception on error, 0 on success. */
|
||||
static int
|
||||
import_psycopg(void)
|
||||
{
|
||||
PyObject *module = PyImport_ImportModule("psycopg");
|
||||
|
||||
if (module != NULL) {
|
||||
PyObject *c_api_object = PyObject_GetAttrString(module, "_C_API");
|
||||
if (c_api_object == NULL) return -1;
|
||||
if (PyCObject_Check(c_api_object))
|
||||
PSYCOPG_API = (void **)PyCObject_AsVoidPtr(c_api_object);
|
||||
Py_DECREF(c_api_object);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* postgresql<->python encoding map */
|
||||
extern HIDDEN PyObject *psycoEncodings;
|
||||
|
||||
|
|
|
@ -608,9 +608,7 @@ exit:
|
|||
return rv;
|
||||
}
|
||||
|
||||
/* psyco_errors_init, psyco_errors_fill (callable from C)
|
||||
|
||||
Initialize the module's exceptions and after that a dictionary with a full
|
||||
/* Initialize the module's exceptions and after that a dictionary with a full
|
||||
set of exceptions. */
|
||||
|
||||
PyObject *Error, *Warning, *InterfaceError, *DatabaseError,
|
||||
|
@ -710,23 +708,6 @@ psyco_errors_fill(PyObject *dict)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
psyco_errors_set(PyObject *type)
|
||||
{
|
||||
int i;
|
||||
char *name;
|
||||
|
||||
for (i = 0; exctable[i].name; i++) {
|
||||
if (NULL == exctable[i].exc) { continue; }
|
||||
|
||||
/* the name is the part after the last dot */
|
||||
name = strrchr(exctable[i].name, '.');
|
||||
name = name ? name + 1 : exctable[i].name;
|
||||
|
||||
PyObject_SetAttrString(type, name, *exctable[i].exc);
|
||||
}
|
||||
}
|
||||
|
||||
RAISES_NEG
|
||||
static int
|
||||
add_module_constants(PyObject *module)
|
||||
|
@ -892,14 +873,12 @@ static struct PyModuleDef psycopgmodule = {
|
|||
};
|
||||
#endif
|
||||
|
||||
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
||||
#define PyMODINIT_FUNC void
|
||||
#endif
|
||||
PyMODINIT_FUNC
|
||||
INIT_MODULE(_psycopg)(void)
|
||||
{
|
||||
#if PY_VERSION_HEX < 0x03020000
|
||||
static void *PSYCOPG_API[PSYCOPG_API_pointers];
|
||||
PyObject *c_api_object;
|
||||
#endif
|
||||
|
||||
PyObject *module = NULL, *dict;
|
||||
|
||||
#ifdef PSYCOPG_DEBUG
|
||||
|
@ -965,13 +944,6 @@ INIT_MODULE(_psycopg)(void)
|
|||
#endif
|
||||
if (!module) { goto exit; }
|
||||
|
||||
/* Create a CObject containing the API pointer array's address */
|
||||
#if PY_VERSION_HEX < 0x03020000
|
||||
c_api_object = PyCObject_FromVoidPtr((void *)PSYCOPG_API, NULL);
|
||||
if (c_api_object != NULL)
|
||||
PyModule_AddObject(module, "_C_API", c_api_object);
|
||||
#endif
|
||||
|
||||
/* other mixed initializations of module-level variables */
|
||||
if (!(psycoEncodings = PyDict_New())) { goto exit; }
|
||||
if (0 != psyco_encodings_fill(psycoEncodings)) { goto exit; }
|
||||
|
|
Loading…
Reference in New Issue
Block a user