Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use global var for bdb_app_data #203

Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-12-11 Emilien Lemaire <[email protected]>

* fileio.c: Always use `bdb_app_data` global variable to save the
pointer to the collating sequence function
emilienlemaire marked this conversation as resolved.
Show resolved Hide resolved

2024-12-08 Simon Sobisch <[email protected]>

Expand Down
11 changes: 6 additions & 5 deletions libcob/fileio.c
GitMensch marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -690,15 +690,16 @@ static unsigned int bdb_lock_id = 0;
key.data = fld->data; \
key.size = (cob_dbtsize_t) fld->size

#if (DB_VERSION_MAJOR > 4) || ((DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR > 0))
GitMensch marked this conversation as resolved.
Show resolved Hide resolved
#define DBT_SET_APP_DATA(key,data) ((key)->app_data = (data))
#define DBT_GET_APP_DATA(key) ((key)->app_data)
#else
/* #if (DB_VERSION_MAJOR > 4) || ((DB_VERSION_MAJOR == 4) && (DB_VERSION_MINOR > 0))
#define DBT_SET_APP_DATA(key,data) ((key)->app_data = (data))
#define DBT_GET_APP_DATA(key) ((key)->app_data)
#else
*/
/* Workaround for older BDB versions that do not have app_data in DBT */
static void *bdb_app_data = NULL;
emilienlemaire marked this conversation as resolved.
Show resolved Hide resolved
#define DBT_SET_APP_DATA(key,data) ((void)(key), bdb_app_data = (data))
#define DBT_GET_APP_DATA(key) ((void)(key), bdb_app_data)
#endif
/* #endif */

struct indexed_file {
DB **db; /* Database handlers */
Expand Down
94 changes: 94 additions & 0 deletions tests/testsuite.src/run_file.at
Original file line number Diff line number Diff line change
Expand Up @@ -14653,3 +14653,97 @@ AT_CHECK([$COBCRUN_DIRECT ./prog2 > prog2.txt])
AT_CHECK([diff expected.txt prog2.txt])

AT_CLEANUP

emilienlemaire marked this conversation as resolved.
Show resolved Hide resolved
AT_SETUP([DELETE WITH COLLATING SEQUENCE])
AT_KEYWORDS([runfile WRITE DELETE READ EBCDIC])

AT_SKIP_IF([test "$COB_HAS_ISAM" != "db"])
AT_DATA([prog.cob], [
IDENTIFICATION DIVISION.
PROGRAM-ID. READDEL.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.

SELECT READDEL ASSIGN EXTERNAL READDEL
ORGANIZATION INDEXED
ACCESS MODE DYNAMIC
RECORD KEY READDEL-KEY
FILE STATUS STA-READDEL.

DATA DIVISION.
FILE SECTION.

FD READDEL.
01 READDEL-REC.
02 READDEL-KEY.
05 READDEL-KEY-NUM PIC S9(15).
02 READDEL-VALUE.
05 READDEL-STRING PIC X(10).
05 READDEL-NUM PIC S9(27) OCCURS 10 TIMES.
*>

*>----------------------*
WORKING-STORAGE SECTION.
*>----------------------*

01 STA-READDEL PIC X(2).
01 END-READDEL PIC 9(1).
01 WS-COUNT PIC S9(2) VALUE 0.

*>------------------*
PROCEDURE DIVISION.
*>------------------*
MOVE 0 TO END-READDEL.
OPEN OUTPUT READDEL.
PERFORM 20 TIMES
MOVE WS-COUNT TO READDEL-KEY-NUM
MOVE "READDELNUM" TO READDEL-STRING
MOVE WS-COUNT TO READDEL-NUM(1)
MOVE WS-COUNT TO READDEL-NUM(2)
MOVE WS-COUNT TO READDEL-NUM(3)
MOVE WS-COUNT TO READDEL-NUM(4)
MOVE WS-COUNT TO READDEL-NUM(5)
MOVE WS-COUNT TO READDEL-NUM(6)
MOVE WS-COUNT TO READDEL-NUM(7)
MOVE WS-COUNT TO READDEL-NUM(8)
MOVE WS-COUNT TO READDEL-NUM(9)
MOVE WS-COUNT TO READDEL-NUM(10)
WRITE READDEL-REC
INVALID KEY
DISPLAY "INVALID KEY " READDEL-KEY
STOP RUN
END-WRITE
ADD 1 TO WS-COUNT
END-PERFORM.
CLOSE READDEL.
MOVE LOW-VALUE TO READDEL-KEY.
OPEN I-O READDEL.
START READDEL KEY IS > READDEL-KEY
INVALID KEY
DISPLAY "ERR START READDEL=" STA-READDEL
MOVE 1 TO END-READDEL
END-START.
PERFORM UNTIL END-READDEL = 1
READ READDEL NEXT RECORD
AT END
MOVE 1 TO END-READDEL
NOT AT END
DELETE READDEL
INVALID KEY
DISPLAY "ERR DELETE KEY=" READDEL-KEY
" / STATUS=" STA-READDEL
END-DELETE
END-READ
END-PERFORM.
CLOSE READDEL.
STOP RUN.


])

AT_CHECK([$COMPILE -fdefault-file-colseq=EBCDIC prog.cob])
AT_CHECK([$COBCRUN_DIRECT ./prog])

AT_CLEANUP
Loading