codecheck修复

This commit is contained in:
qin86
2022-06-14 11:19:11 +08:00
parent 153a3c0238
commit 6254173a01
11 changed files with 62 additions and 68 deletions

View File

@ -130,7 +130,7 @@ struct connection* ecpg_get_connection(const char*);
char* ecpg_alloc(long, int);
char* ecpg_realloc(void*, long, int);
void ecpg_free(void*);
bool ecpg_init(const struct connection*, const char*, const int);
bool ecpg_init(const struct connection* con, const char* connection_name, const int lineno);
char* ecpg_strdup(const char*, int);
const char* ecpg_type_name(enum ECPGttype);
int ecpg_dynamic_type(Oid);
@ -145,7 +145,7 @@ struct descriptor* ecpg_find_desc(int line, const char* name);
struct prepared_statement* ecpg_find_prepared_statement(const char*, struct connection*, struct prepared_statement**);
bool ecpg_store_result(const PGresult* results, int act_field, const struct statement* stmt, struct variable* var);
bool ecpg_store_input(const int, const bool, const struct variable*, char**, bool);
bool ecpg_store_input(const int lineno, const bool force_indicator, const struct variable* var, char** tobeinserted_p, bool quote);
bool ecpg_check_PQresult(PGresult*, int, PGconn*, enum COMPAT_MODE);
void ecpg_raise(int line, int code, const char* sqlstate, const char* str);

View File

@ -342,8 +342,8 @@ typedef struct {
#define TIMESTAMP_IS_NOEND(j) ((j) == DT_NOEND)
#define TIMESTAMP_NOT_FINITE(j) (TIMESTAMP_IS_NOBEGIN(j) || TIMESTAMP_IS_NOEND(j))
int DecodeInterval(char**, const int*, int, int*, struct tm*, fsec_t*);
int DecodeTime(const char*, unsigned int*, struct tm*, fsec_t*);
int DecodeInterval2(char** field, const int* ftype, int nf, int* dtype, struct tm* tm, fsec_t* fsec);
int DecodeTime(const char* str, unsigned int* tmask, struct tm* tm, fsec_t* fsec);
int EncodeDateTime(
struct tm* tm, fsec_t fsec, bool print_tz, int tz, const char* tzn, int style, char* str, bool EuroDates);
int EncodeInterval(struct tm* tm, fsec_t fsec, int style, char* str);
@ -359,6 +359,9 @@ void GetCurrentDateTime(struct tm*);
int date2j(int, int, int);
void TrimTrailingZeros(char*);
void dt2time(double, int*, int*, int*, fsec_t*);
int PGTYPEStimestamp_defmt_scan(
char** str, char* fmt, timestamp* d, int* year, int* month, int* day, int* hour, int* minute, int* second, int* tz);
extern char* pgtypes_date_weekdays_short[];
extern char* pgtypes_date_months[];

View File

@ -2308,9 +2308,6 @@ static int pgtypes_defmt_scan(union un_fmt_comb* scan_val, int scan_type, char**
return err;
}
/* XXX range checking */
int PGTYPEStimestamp_defmt_scan(char**, char*, timestamp*, int*, int*, int*, int*, int*, int*, int*);
int PGTYPEStimestamp_defmt_scan(
char** str, char* fmt, timestamp* d, int* year, int* month, int* day, int* hour, int* minute, int* second, int* tz)
{

View File

@ -317,8 +317,8 @@ static int DecodeISO8601Interval(char* str, int* dtype, struct /* pg_ */ tm* tm,
*
* * Assert wasn't available so removed it.
*/
int DecodeInterval(char** field, const int* ftype, int nf, /* int range, */
int* dtype, struct /* pg_ */ tm* tm, fsec_t* fsec)
int DecodeInterval2(char** field, const int* ftype, int nf,
int* dtype, struct tm* tm, fsec_t* fsec)
{
int IntervalStyle = INTSTYLE_POSTGRES_VERBOSE;
int range = INTERVAL_FULL_RANGE;
@ -1006,7 +1006,7 @@ interval* PGTYPESinterval_from_asc(char* str, char** endptr)
}
if (ParseDateTime(str, lowstr, field, ftype, &nf, ptr) != 0 ||
(DecodeInterval(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
(DecodeInterval2(field, ftype, nf, &dtype, tm, &fsec) != 0 &&
DecodeISO8601Interval(str, &dtype, tm, &fsec) != 0)) {
errno = PGTYPES_INTVL_BAD_INTERVAL;
return NULL;

View File

@ -17,7 +17,6 @@
#include "pgtypes_timestamp.h"
#include "pgtypes_date.h"
int PGTYPEStimestamp_defmt_scan(char**, char*, timestamp*, int*, int*, int*, int*, int*, int*, int*);
#ifdef HAVE_INT64_TIMESTAMP
static int64 time2t(const int hour, const int min, const int sec, const fsec_t fsec)

View File

@ -100,8 +100,9 @@ void drop_descriptor(char* name, char* connection)
if ((!connection && !i->connection) ||
(connection && i->connection && strcmp(connection, i->connection) == 0)) {
*lastptr = i->next;
if (i->connection)
if (i->connection) {
free_current_memory(i->connection);
}
free_current_memory(i->name);
free_current_memory(i);
return;

View File

@ -50,10 +50,10 @@ extern struct ECPGstruct_member* struct_member_list[STRUCT_DEPTH];
extern const char* get_dtype(enum ECPGdtype);
extern void lex_init(void);
extern void output_line_number(void);
extern void output_statement(char*, int, enum ECPG_statement_type);
extern void output_prepare_statement(char*, char*);
extern void output_deallocate_prepare_statement(char*);
extern void output_simple_statement(char*);
extern void output_statement(char* stmt, int whenever_mode, enum ECPG_statement_type st);
extern void output_prepare_statement(char* name, char* stmt);
extern void output_deallocate_prepare_statement(char* name);
extern void output_simple_statement(char* stmt);
extern char* hashline_number(void);
extern int base_yyparse(void);
extern int base_yylex(void);
@ -63,29 +63,30 @@ extern char* mm_strdup(const char*);
extern void mmerror(int, enum errortype, const char*, ...)
/* This extension allows gcc to check the format string */
__attribute__((format(PG_PRINTF_ATTRIBUTE, 3, 4)));
extern void output_get_descr_header(char*);
extern void output_get_descr(char*, char*);
extern void output_set_descr_header(char*);
extern void output_set_descr(char*, char*);
extern void push_assignment(char*, enum ECPGdtype);
extern struct variable* find_variable(char*);
extern void whenever_action(int);
extern void add_descriptor(char*, char*);
extern void drop_descriptor(char*, char*);
extern struct descriptor* lookup_descriptor(char*, char*);
extern void output_get_descr_header(char* desc_name);
extern void output_get_descr(char* desc_name, char* index);
extern void output_set_descr_header(char* desc_name);
extern void output_set_descr(char* desc_name, char* index);
extern void push_assignment(char* var, enum ECPGdtype value);
extern struct variable* find_variable(char* name);
extern void whenever_action(int mode);
extern void add_descriptor(char* name, char* connection);
extern void drop_descriptor(char* name, char* connection);
extern struct descriptor* lookup_descriptor(char* name, char* connection);
extern struct variable* descriptor_variable(const char* name, int input);
extern struct variable* sqlda_variable(const char* name);
extern void add_variable_to_head(struct arguments**, struct variable*, struct variable*);
extern void add_variable_to_tail(struct arguments**, struct variable*, struct variable*);
extern void add_variable_to_head(struct arguments** list, struct variable* var, struct variable* ind);
extern void add_variable_to_tail(struct arguments** list, struct variable* var, struct variable* ind);
extern void remove_variable_from_list(struct arguments** list, struct variable* var);
extern void dump_variables(struct arguments*, int);
extern struct typedefs* get_typedef(char*);
extern void adjust_array(enum ECPGttype, char**, char**, char*, char*, int, bool);
extern void dump_variables(struct arguments* list, int mode);
extern struct typedefs* get_typedef(char* name);
extern void adjust_array(enum ECPGttype type_enum, char** dimension, char** length, char* type_dimension, char* type_index,
int pointer_len, bool type_definition);
extern void reset_variables(void);
extern void check_indicator(struct ECPGtype*);
extern void remove_typedefs(int);
extern void remove_variables(int);
extern struct variable* new_variable(const char*, struct ECPGtype*, int);
extern void check_indicator(struct ECPGtype* var);
extern void remove_typedefs(int brace_level);
extern void remove_variables(int brace_level);
extern struct variable* new_variable(const char* name, struct ECPGtype* type, int brace_level);
extern const ScanKeyword* ScanCKeywordLookup(const char*);
extern const ScanKeyword* ScanECPGKeywordLookup(const char* text);
extern void scanner_init(const char*);

View File

@ -4,7 +4,8 @@
#include "extern.h"
static void output_escaped_str(char* cmd, bool quoted);
static void output_escaped_str(char* str, bool quoted);
void output_line_number(void)
{

View File

@ -1,7 +1,7 @@
/* src/interfaces/ecpg/preproc/type.c */
#include "postgres_fe.h"
#include "type.h"
#include "extern.h"
#define indicator_set ind_type != NULL && ind_type->type != ECPGt_NO_INDICATOR
@ -15,7 +15,6 @@ void insert_current_memory(void *ptr)
{
if (ptr == NULL)
return;
//printf("insert ptr =%p\n", ptr);
struct Current_memory *pcm = (struct Current_memory *)malloc(sizeof(struct Current_memory));
pcm->p = ptr;
@ -30,14 +29,10 @@ void free_current_memory(void *ptr)
{
if (ptr == NULL)
return;
//printf("free ptr =%p\n", ptr);
struct Current_memory *pcm = Currentmemoryused;
struct Current_memory *pfront = NULL;
while(pcm)
{
if(pcm->p == ptr)
{
while (pcm) {
if (pcm->p == ptr) {
if (pfront)
pfront->next = pcm->next;
else
@ -55,8 +50,7 @@ void free_current_memory(void *ptr)
}
pcm = Currentmemoryused;
while(pcm)
{
while (pcm) {
printf("Currentmemoryused ptr =%p\n", pcm);
pcm = pcm->next;
}
@ -66,10 +60,7 @@ void free_current_memory(void *ptr)
void free_current_memory_all()
{
struct Current_memory *pcm = Currentmemoryused;
while(pcm)
{
//printf("free_current_memory_all ss num %d, %p\n",Currentmemoryused_num, pcm->p);
//fflush(stdout);
while (pcm) {
struct Current_memory *pfree = pcm;
pcm = pcm->next;
@ -80,8 +71,6 @@ void free_current_memory_all()
--Currentmemoryused_num;
}
Currentmemoryused = NULL;
//printf("free_current_memory_all num %d\n",Currentmemoryused_num);
//fflush(stdout);
}
/* malloc + error check */

View File

@ -13,8 +13,7 @@ struct ECPGstruct_member {
struct ECPGstruct_member* next;
};
struct Current_memory
{
struct Current_memory {
void *p;
struct Current_memory *next;
};
@ -37,18 +36,19 @@ struct ECPGtype {
};
/* Everything is malloced. */
void ECPGmake_struct_member(char*, struct ECPGtype*, struct ECPGstruct_member**);
struct ECPGtype* ECPGmake_simple_type(enum ECPGttype, char*, int);
struct ECPGtype* ECPGmake_array_type(struct ECPGtype*, char*);
struct ECPGtype* ECPGmake_struct_type(struct ECPGstruct_member*, enum ECPGttype, char*, char*);
void ECPGmake_struct_member(char* name, struct ECPGtype* type, struct ECPGstruct_member** start);
struct ECPGtype* ECPGmake_simple_type(enum ECPGttype type, char* size, int counter);
struct ECPGtype* ECPGmake_array_type(struct ECPGtype* type, char* size);
struct ECPGtype* ECPGmake_struct_type( struct ECPGstruct_member* rm, enum ECPGttype type, char* type_name, char* struct_sizeof);
struct ECPGstruct_member* ECPGstruct_member_dup(struct ECPGstruct_member*);
/* Frees a type. */
void ECPGfree_struct_member(struct ECPGstruct_member*);
void ECPGfree_type(struct ECPGtype*);
void ECPGfree_struct_member(struct ECPGstruct_member* rm);
void ECPGfree_type(struct ECPGtype* type);
void insert_current_memory(void *ptr);
void free_current_memory(void *ptr);
void free_current_memory_all();
void free_current_memory_all(void);
/* Dump a type.
The type is dumped as:
@ -60,8 +60,10 @@ void free_current_memory_all();
size is the maxsize in case it is a varchar. Otherwise it is the size of
the variable (required to do array fetches of structs).
*/
void ECPGdump_a_type(FILE*, const char*, struct ECPGtype*, const int, const char*, struct ECPGtype*, const int,
const char*, const char*, char*, const char*, const char*);
void ECPGdump_a_type(FILE* o, const char* name, struct ECPGtype* type, const int brace_level, const char* ind_name,
struct ECPGtype* ind_type, const int ind_brace_level, const char* prefix, const char* ind_prefix, char* arr_str_siz,
const char* struct_sizeof, const char* ind_struct_sizeof);
/* A simple struct to keep a variable and its type. */
struct ECPGtemp_type {

View File

@ -437,9 +437,10 @@ void dump_variables(struct arguments* list, int mode)
NULL);
/* Then release the list element. */
if (mode != 0)
if (mode != 0) {
free_current_memory(list);
}
}
void check_indicator(struct ECPGtype* var)
{