From 5f09513c854981138ff7765ffbb22f662c5cc253 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nirgal=20Vourg=C3=A8re?= Date: Thu, 9 Aug 2012 14:55:17 +0200 Subject: [PATCH] Deprecate more mdb_{init|remove}_backends These functions now use the __attribute__((constructor)) & destructor. Old names were keep for compatibility Also put __attribute__((deprecated)) in mdbtools.h for all deprecated functions. --- include/mdbtools.h | 12 ++++++------ src/libmdb/backend.c | 18 +++++++++++++----- src/libmdb/mem.c | 9 --------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/include/mdbtools.h b/include/mdbtools.h index 43c2ecd..d5ce7dd 100644 --- a/include/mdbtools.h +++ b/include/mdbtools.h @@ -416,8 +416,8 @@ typedef struct { } MdbSarg; /* mem.c */ -extern void mdb_init(); // DEPRECATED -extern void mdb_exit(); // DEPRECATED +extern void __attribute__((deprecated)) mdb_init(); +extern void __attribute__((deprecated)) mdb_exit(); /* file.c */ extern ssize_t mdb_read_pg(MdbHandle *mdb, unsigned long pg); @@ -487,14 +487,14 @@ extern int mdb_read_row(MdbTableDef *table, unsigned int row); extern void mdb_buffer_dump(const void *buf, int start, size_t len); /* backend.c */ -extern char* mdb_get_coltype_string(MdbBackend *backend, int col_type); /* obsolete */ -extern int mdb_coltype_takes_length(MdbBackend *backend, int col_type); /* obsolete */ +extern char* __attribute__((deprecated)) mdb_get_coltype_string(MdbBackend *backend, int col_type); +extern int __attribute__((deprecated)) mdb_coltype_takes_length(MdbBackend *backend, int col_type); extern const MdbBackendType* mdb_get_colbacktype(const MdbColumn *col); extern const char* mdb_get_colbacktype_string(const MdbColumn *col); extern int mdb_colbacktype_takes_length(const MdbColumn *col); -extern void mdb_init_backends(); +extern void __attribute__((deprecated)) mdb_init_backends(); extern void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendType *backend_type, MdbBackendType *type_shortdate, MdbBackendType *type_autonum, const char *short_now, const char *long_now, const char *charset_statement, const char *drop_statement, const char *constaint_not_empty_statement, const char *column_comment_statement, const char *table_comment_statement, gchar* (*quote_schema_name)(const gchar*, const gchar*)); -extern void mdb_remove_backends(); +extern void __attribute__((deprecated)) mdb_remove_backends(); extern int mdb_set_default_backend(MdbHandle *mdb, const char *backend_name); extern void mdb_print_schema(MdbHandle *mdb, FILE *outfile, char *tabname, char *dbnamespace, guint32 export_options); diff --git a/src/libmdb/backend.c b/src/libmdb/backend.c index 316ce87..95b77be 100644 --- a/src/libmdb/backend.c +++ b/src/libmdb/backend.c @@ -237,7 +237,7 @@ quote_with_squotes(const gchar* value) return quote_generic(value, '\'', '\''); } -/* deprecated */ char * +char * __attribute__((deprecated)) mdb_get_coltype_string(MdbBackend *backend, int col_type) { static int warn_deprecated = 0; @@ -255,7 +255,7 @@ mdb_get_coltype_string(MdbBackend *backend, int col_type) return backend->types_table[col_type].name; } -/* deprecated */ int +int __attribute__((deprecated)) mdb_coltype_takes_length(MdbBackend *backend, int col_type) { static int warn_deprecated = 0; @@ -303,13 +303,17 @@ mdb_colbacktype_takes_length(const MdbColumn *col) return type->needs_length; } +void __attribute__((deprecated)) mdb_init_backends() { + fprintf(stderr, "mdb_init_backends() is DEPRECATED and does nothing. Stop calling it.\n"); +} + /** - * mdb_init_backends + * _mdb_init_backends * * Initializes the mdb_backends hash and loads the builtin backends. * Use mdb_remove_backends() to destroy this hash when done. */ -void mdb_init_backends() +void __attribute__ ((constructor)) _mdb_init_backends() { mdb_backends = g_hash_table_new(g_str_hash, g_str_equal); @@ -382,12 +386,16 @@ void mdb_register_backend(char *backend_name, guint32 capabilities, MdbBackendTy g_hash_table_insert(mdb_backends, backend_name, backend); } +void __attribute__((deprecated)) mdb_remove_backends() { + fprintf(stderr, "mdb_remove_backends() is DEPRECATED and does nothing. Stop calling it.\n"); +} + /** * mdb_remove_backends * * Removes all entries from and destroys the mdb_backends hash. */ -void mdb_remove_backends() +void __attribute__ ((destructor)) _mdb_remove_backends() { g_hash_table_foreach_remove(mdb_backends, mdb_drop_backend, NULL); g_hash_table_destroy(mdb_backends); diff --git a/src/libmdb/mem.c b/src/libmdb/mem.c index 3ced998..49ee3f1 100644 --- a/src/libmdb/mem.c +++ b/src/libmdb/mem.c @@ -18,15 +18,6 @@ #include "mdbtools.h" -void __attribute__ ((constructor)) _mdb_init() -{ - mdb_init_backends(); -} -void __attribute__ ((destructor)) _mdb_exit() -{ - mdb_remove_backends(); -} - void __attribute__((deprecated)) mdb_init() { fprintf(stderr, "mdb_init() is DEPRECATED and does nothing. Stop calling it.\n");