P
PapaTodd
Greetings all,
I've been fighting with this issue all day. This code is tried and
true on other OS's, but when I compile and test on AIX 5.3 using xlC_r,
I have problems.
Here is the code snippets giving a problem:
main.cpp
---------------------------------
mySchemaType *theSchema = NULL; // declared as global
// within main()
theSchema = prepareSchemaAndFilters(some strings showing files);
pRecord = theSchema->records;
pField = pRecord->fields;
mySpecificType *tmpRecord = (mySpecificType *)pField->specific;
printf("the specific db_type = %s\n",tmpRecord->db_type);
----------------------------------
At this point, db_type is shown to be garbage. This is my problem.
Here is what prepareSchemaAndFilters looks like:
makeschema.c
----------------------------------
mySchemaType *prepareSchemaAndFilters(the file strings)
{
mySchemaType *theSchema;
// code removed for clarity, essentially items are put into theSchema
myRecordType *pRecord = theSchema->records;
myFieldType *pField = pRecord->fields;
mySpecificType *tmpRecord = (mySpecificType *)pfield->specific;
printf("the specific db_type = %s\n",tmpRecord->db_type);
return theSchema;
}
----------------------------------
Within makeschema.c, the specific db_type is output the expected value.
Here are the type definitions:
schema.h
----------------------------------
typedef struct my_record myRecordType;
typedef struct my_field myFieldType;
typedef struct my_schema mySchemaType;
typedef struct my_specific mySpecificType;
struct my_specific {
char name[256];
char db_type[256];
int db_length;
void *additional_specific;
refKey* firstRefKey;
refKey* lastRefKey;
};
struct my_field {
char* name;
char* my_name;
myFieldType* fields;
bool is_key;
bool is_binary;
bool is_single;
FilterType filter;
void* specific;
stringList* values;
myFieldType* next;
}
struct my_record {
char* name;
char* my_name;
myFieldType* fields;
FilterType filter;
void* specific;
int seqno;
myRecordType* next;
int updateNumber;
};
struct my_schema {
mesRecord* records;
void* specific;
};
-------------------------------
So, finally to the source of my problem. When I am within mes_schema.c
(linked in as a library), I can cast the void* as a specific* and get
the different values. When I am back in main.cpp, if I do this, the
values that are part of specific* print correctly.
This appears to be a pointer error, and I suspect any of the following
possibilities:
1) Even though I'm explicitely compiling under 32-bit mode, somehow the
pointers are not being handled properly.
2) Some weird translation between the .c library and the .cpp file? We
are using an extern "C" { flag for the .c files, but maybe this isn't
good enough when we compile?
As I mentioned before, on this system (AIX 5L), we are seeing this
problem. On all others (HP-UX, Win, Solaris), we don't.
Any advice would be appreciated. Tonights task is to start wading
through dbx to verify that it is an invalid pointer issue, but if I
verify that, I'm not sure what the fix is going to be.
Thanks in advance,
Todd
I've been fighting with this issue all day. This code is tried and
true on other OS's, but when I compile and test on AIX 5.3 using xlC_r,
I have problems.
Here is the code snippets giving a problem:
main.cpp
---------------------------------
mySchemaType *theSchema = NULL; // declared as global
// within main()
theSchema = prepareSchemaAndFilters(some strings showing files);
pRecord = theSchema->records;
pField = pRecord->fields;
mySpecificType *tmpRecord = (mySpecificType *)pField->specific;
printf("the specific db_type = %s\n",tmpRecord->db_type);
----------------------------------
At this point, db_type is shown to be garbage. This is my problem.
Here is what prepareSchemaAndFilters looks like:
makeschema.c
----------------------------------
mySchemaType *prepareSchemaAndFilters(the file strings)
{
mySchemaType *theSchema;
// code removed for clarity, essentially items are put into theSchema
myRecordType *pRecord = theSchema->records;
myFieldType *pField = pRecord->fields;
mySpecificType *tmpRecord = (mySpecificType *)pfield->specific;
printf("the specific db_type = %s\n",tmpRecord->db_type);
return theSchema;
}
----------------------------------
Within makeschema.c, the specific db_type is output the expected value.
Here are the type definitions:
schema.h
----------------------------------
typedef struct my_record myRecordType;
typedef struct my_field myFieldType;
typedef struct my_schema mySchemaType;
typedef struct my_specific mySpecificType;
struct my_specific {
char name[256];
char db_type[256];
int db_length;
void *additional_specific;
refKey* firstRefKey;
refKey* lastRefKey;
};
struct my_field {
char* name;
char* my_name;
myFieldType* fields;
bool is_key;
bool is_binary;
bool is_single;
FilterType filter;
void* specific;
stringList* values;
myFieldType* next;
}
struct my_record {
char* name;
char* my_name;
myFieldType* fields;
FilterType filter;
void* specific;
int seqno;
myRecordType* next;
int updateNumber;
};
struct my_schema {
mesRecord* records;
void* specific;
};
-------------------------------
So, finally to the source of my problem. When I am within mes_schema.c
(linked in as a library), I can cast the void* as a specific* and get
the different values. When I am back in main.cpp, if I do this, the
values that are part of specific* print correctly.
This appears to be a pointer error, and I suspect any of the following
possibilities:
1) Even though I'm explicitely compiling under 32-bit mode, somehow the
pointers are not being handled properly.
2) Some weird translation between the .c library and the .cpp file? We
are using an extern "C" { flag for the .c files, but maybe this isn't
good enough when we compile?
As I mentioned before, on this system (AIX 5L), we are seeing this
problem. On all others (HP-UX, Win, Solaris), we don't.
Any advice would be appreciated. Tonights task is to start wading
through dbx to verify that it is an invalid pointer issue, but if I
verify that, I'm not sure what the fix is going to be.
Thanks in advance,
Todd