Skip to content

Commit 165dd64

Browse files
committed
Refactoring. Fix LLVM issue.
1 parent ffab34f commit 165dd64

File tree

11 files changed

+142
-140
lines changed

11 files changed

+142
-140
lines changed

src/dm_db.f90

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ module dm_db
2121

2222
type, public :: db_type
2323
!! SQLite database connectivity type.
24-
type(c_ptr) :: ctx = c_null_ptr !! C pointer to SQLite 3 database.
24+
type(c_ptr) :: context = c_null_ptr !! C pointer to SQLite 3 database.
2525
logical :: read_only = .false. !! Read-only flag.
2626
end type db_type
2727

2828
type, public :: db_stmt_type
2929
!! SQLite database statement type.
30-
type(c_ptr) :: ctx = c_null_ptr !! C pointer to SQLite 3 statement.
30+
type(c_ptr) :: context = c_null_ptr !! C pointer to SQLite 3 statement.
3131
end type db_stmt_type
3232

3333
abstract interface
@@ -217,21 +217,21 @@ logical function dm_db_column_is_float(dbs, index) result(is)
217217
type(db_stmt_type), intent(inout) :: dbs !! Database statement.
218218
integer, intent(in) :: index !! Column index.
219219

220-
is = (sqlite3_column_type(dbs%ctx, index) == SQLITE_FLOAT)
220+
is = (sqlite3_column_type(dbs%context, index) == SQLITE_FLOAT)
221221
end function dm_db_column_is_float
222222

223223
logical function dm_db_column_is_integer(dbs, index) result(is)
224224
type(db_stmt_type), intent(inout) :: dbs !! Database statement.
225225
integer, intent(in) :: index !! Column index.
226226

227-
is = (sqlite3_column_type(dbs%ctx, index) == SQLITE_INTEGER)
227+
is = (sqlite3_column_type(dbs%context, index) == SQLITE_INTEGER)
228228
end function dm_db_column_is_integer
229229

230230
logical function dm_db_column_is_text(dbs, index) result(is)
231231
type(db_stmt_type), intent(inout) :: dbs !! Database statement.
232232
integer, intent(in) :: index !! Column index.
233233

234-
is = (sqlite3_column_type(dbs%ctx, index) == SQLITE_TEXT)
234+
is = (sqlite3_column_type(dbs%context, index) == SQLITE_TEXT)
235235
end function dm_db_column_is_text
236236

237237
integer function dm_db_commit(db) result(rc)
@@ -270,7 +270,7 @@ integer function dm_db_error(db, sqlite_error) result(rc)
270270

271271
integer :: error
272272

273-
error = sqlite3_errcode(db%ctx)
273+
error = sqlite3_errcode(db%context)
274274
if (present(sqlite_error)) sqlite_error = error
275275

276276
select case (error)
@@ -299,7 +299,7 @@ function dm_db_error_message(db) result(message)
299299
type(db_type), intent(inout) :: db !! Database.
300300
character(:), allocatable :: message !! Error message.
301301

302-
message = sqlite3_errmsg(db%ctx)
302+
message = sqlite3_errmsg(db%context)
303303
end function dm_db_error_message
304304

305305
integer function dm_db_exec(db, query, error_message) result(rc)
@@ -313,7 +313,7 @@ integer function dm_db_exec(db, query, error_message) result(rc)
313313
integer :: stat
314314

315315
rc = E_DB_EXEC
316-
stat = sqlite3_exec(db%ctx, query, c_null_funptr, c_null_ptr, error_message)
316+
stat = sqlite3_exec(db%context, query, c_null_funptr, c_null_ptr, error_message)
317317
if (stat == SQLITE_OK) rc = E_NONE
318318
end function dm_db_exec
319319

@@ -327,14 +327,14 @@ logical function dm_db_is_connected(db) result(is)
327327
!! Returns `.true.` if database type has associated pointer.
328328
type(db_type), intent(inout) :: db !! Database.
329329

330-
is = c_associated(db%ctx)
330+
is = c_associated(db%context)
331331
end function dm_db_is_connected
332332

333333
logical function dm_db_is_prepared(dbs) result(prepared)
334334
!! Returns `.true.` if given statement has been prepared.
335335
type(db_stmt_type), intent(inout) :: dbs !! Database statement.
336336

337-
prepared = c_associated(dbs%ctx)
337+
prepared = c_associated(dbs%context)
338338
end function dm_db_is_prepared
339339

340340
logical function dm_db_is_read_only(db) result(is)
@@ -360,7 +360,7 @@ integer function dm_db_prepare(db, dbs, sql) result(rc)
360360
character(*), intent(in) :: sql !! SQL query.
361361

362362
rc = E_DB_PREPARE
363-
if (sqlite3_prepare_v2(db%ctx, sql, dbs%ctx) == SQLITE_OK) rc = E_NONE
363+
if (sqlite3_prepare_v2(db%context, sql, dbs%context) == SQLITE_OK) rc = E_NONE
364364
end function dm_db_prepare
365365

366366
integer function dm_db_release(db, name) result(rc)
@@ -376,7 +376,7 @@ integer function dm_db_reset(dbs) result(rc)
376376
type(db_stmt_type), intent(inout) :: dbs !! Database statement.
377377

378378
rc = E_DB
379-
if (sqlite3_reset(dbs%ctx) == SQLITE_OK) rc = E_NONE
379+
if (sqlite3_reset(dbs%context) == SQLITE_OK) rc = E_NONE
380380
end function dm_db_reset
381381

382382
integer function dm_db_rollback(db, name) result(rc)
@@ -416,7 +416,7 @@ integer function dm_db_set_busy_callback(db, callback, client_data) result(rc)
416416
type(c_ptr), intent(in) :: client_data !! C pointer to client data.
417417

418418
rc = E_DB
419-
if (sqlite3_busy_handler(db%ctx, c_funloc(callback), client_data) == SQLITE_OK) rc = E_NONE
419+
if (sqlite3_busy_handler(db%context, c_funloc(callback), client_data) == SQLITE_OK) rc = E_NONE
420420
end function dm_db_set_busy_callback
421421

422422
integer function dm_db_set_busy_timeout(db, msec) result(rc)
@@ -425,7 +425,7 @@ integer function dm_db_set_busy_timeout(db, msec) result(rc)
425425
integer, intent(in) :: msec !! Timeout in mseconds.
426426

427427
rc = E_DB
428-
if (sqlite3_busy_timeout(db%ctx, msec) == SQLITE_OK) rc = E_NONE
428+
if (sqlite3_busy_timeout(db%context, msec) == SQLITE_OK) rc = E_NONE
429429
end function dm_db_set_busy_timeout
430430

431431
integer function dm_db_set_log_callback(callback, client_data) result(rc)
@@ -455,9 +455,9 @@ integer function dm_db_set_update_callback(db, callback, client_data) result(rc)
455455
rc = E_DB
456456

457457
if (present(client_data)) then
458-
udp = sqlite3_update_hook(db%ctx, c_funloc(callback), client_data)
458+
udp = sqlite3_update_hook(db%context, c_funloc(callback), client_data)
459459
else
460-
udp = sqlite3_update_hook(db%ctx, c_funloc(callback), c_null_ptr)
460+
udp = sqlite3_update_hook(db%context, c_funloc(callback), c_null_ptr)
461461
end if
462462

463463
if (c_associated(udp)) rc = E_NONE
@@ -475,7 +475,7 @@ integer function dm_db_step(dbs) result(rc)
475475

476476
integer :: stat
477477

478-
stat = sqlite3_step(dbs%ctx)
478+
stat = sqlite3_step(dbs%context)
479479

480480
select case (stat)
481481
case (SQLITE_ROW); rc = E_DB_ROW
@@ -506,7 +506,7 @@ subroutine dm_db_column_size(dbs, index, value)
506506
integer, intent(in) :: index !! Column index.
507507
integer, intent(out) :: value !! Value.
508508

509-
value = sqlite3_column_bytes(dbs%ctx, index)
509+
value = sqlite3_column_bytes(dbs%context, index)
510510
end subroutine dm_db_column_size
511511

512512
subroutine dm_db_finalize(dbs, error)
@@ -517,9 +517,9 @@ subroutine dm_db_finalize(dbs, error)
517517
integer, intent(out), optional :: error !! Error code.
518518

519519
if (present(error)) error = E_NULL
520-
if (.not. c_associated(dbs%ctx)) return
520+
if (.not. c_associated(dbs%context)) return
521521
if (present(error)) error = E_DB_FINALIZE
522-
if (sqlite3_finalize(dbs%ctx) /= SQLITE_OK) return
522+
if (sqlite3_finalize(dbs%context) /= SQLITE_OK) return
523523
if (present(error)) error = E_NONE
524524
end subroutine dm_db_finalize
525525

@@ -555,7 +555,7 @@ integer function db_bind_double(dbs, index, value) result(rc)
555555
integer :: stat
556556

557557
rc = E_DB_BIND
558-
stat = sqlite3_bind_double(dbs%ctx, index, value)
558+
stat = sqlite3_bind_double(dbs%context, index, value)
559559
if (stat == SQLITE_OK) rc = E_NONE
560560
end function db_bind_double
561561

@@ -569,7 +569,7 @@ integer function db_bind_int(dbs, index, value) result(rc)
569569
integer :: stat
570570

571571
rc = E_DB_BIND
572-
stat = sqlite3_bind_int(dbs%ctx, index, value)
572+
stat = sqlite3_bind_int(dbs%context, index, value)
573573
if (stat == SQLITE_OK) rc = E_NONE
574574
end function db_bind_int
575575

@@ -583,7 +583,7 @@ integer function db_bind_int64(dbs, index, value) result(rc)
583583
integer :: stat
584584

585585
rc = E_DB_BIND
586-
stat = sqlite3_bind_int64(dbs%ctx, index, value)
586+
stat = sqlite3_bind_int64(dbs%context, index, value)
587587
if (stat == SQLITE_OK) rc = E_NONE
588588
end function db_bind_int64
589589

@@ -602,10 +602,10 @@ integer function db_bind_query(dbs, dbq) result(rc)
602602
do i = 1, dbq%nupdates
603603
associate (update => dbq%updates(i))
604604
select case (update%type)
605-
case (DB_QUERY_TYPE_DOUBLE); stat = sqlite3_bind_double(dbs%ctx, j, update%value_double)
606-
case (DB_QUERY_TYPE_INT); stat = sqlite3_bind_int (dbs%ctx, j, update%value_int)
607-
case (DB_QUERY_TYPE_INT64); stat = sqlite3_bind_int64 (dbs%ctx, j, update%value_int64)
608-
case (DB_QUERY_TYPE_TEXT); stat = sqlite3_bind_text (dbs%ctx, j, update%value_text)
605+
case (DB_QUERY_TYPE_DOUBLE); stat = sqlite3_bind_double(dbs%context, j, update%value_double)
606+
case (DB_QUERY_TYPE_INT); stat = sqlite3_bind_int (dbs%context, j, update%value_int)
607+
case (DB_QUERY_TYPE_INT64); stat = sqlite3_bind_int64 (dbs%context, j, update%value_int64)
608+
case (DB_QUERY_TYPE_TEXT); stat = sqlite3_bind_text (dbs%context, j, update%value_text)
609609
case default; stat = SQLITE_ERROR
610610
end select
611611

@@ -618,10 +618,10 @@ integer function db_bind_query(dbs, dbq) result(rc)
618618
do i = 1, dbq%nparams
619619
associate (param => dbq%params(i))
620620
select case (param%type)
621-
case (DB_QUERY_TYPE_DOUBLE); stat = sqlite3_bind_double(dbs%ctx, j, param%value_double)
622-
case (DB_QUERY_TYPE_INT); stat = sqlite3_bind_int (dbs%ctx, j, param%value_int)
623-
case (DB_QUERY_TYPE_INT64); stat = sqlite3_bind_int64 (dbs%ctx, j, param%value_int64)
624-
case (DB_QUERY_TYPE_TEXT); stat = sqlite3_bind_text (dbs%ctx, j, param%value_text)
621+
case (DB_QUERY_TYPE_DOUBLE); stat = sqlite3_bind_double(dbs%context, j, param%value_double)
622+
case (DB_QUERY_TYPE_INT); stat = sqlite3_bind_int (dbs%context, j, param%value_int)
623+
case (DB_QUERY_TYPE_INT64); stat = sqlite3_bind_int64 (dbs%context, j, param%value_int64)
624+
case (DB_QUERY_TYPE_TEXT); stat = sqlite3_bind_text (dbs%context, j, param%value_text)
625625
case default; stat = SQLITE_ERROR
626626
end select
627627

@@ -632,7 +632,7 @@ integer function db_bind_query(dbs, dbq) result(rc)
632632

633633
! LIMIT value.
634634
if (dbq%limit > 0) then
635-
stat = sqlite3_bind_int64(dbs%ctx, j, dbq%limit)
635+
stat = sqlite3_bind_int64(dbs%context, j, dbq%limit)
636636
if (stat /= SQLITE_OK) return
637637
end if
638638

@@ -649,7 +649,7 @@ integer function db_bind_text(dbs, index, value) result(rc)
649649
integer :: stat
650650

651651
rc = E_DB_BIND
652-
stat = sqlite3_bind_text(dbs%ctx, index, trim(value))
652+
stat = sqlite3_bind_text(dbs%context, index, trim(value))
653653
if (stat == SQLITE_OK) rc = E_NONE
654654
end function db_bind_text
655655

@@ -662,7 +662,7 @@ subroutine db_column_allocatable(dbs, index, value)
662662
integer, intent(in) :: index !! Column index.
663663
character(:), allocatable, intent(out) :: value !! Value.
664664

665-
value = sqlite3_column_text(dbs%ctx, index)
665+
value = sqlite3_column_text(dbs%context, index)
666666
end subroutine db_column_allocatable
667667

668668
subroutine db_changes_int32(db, n)
@@ -673,7 +673,7 @@ subroutine db_changes_int32(db, n)
673673
type(db_type), intent(inout) :: db !! Database.
674674
integer(i4), intent(out) :: n !! Number of changes.
675675

676-
n = sqlite3_changes(db%ctx)
676+
n = sqlite3_changes(db%context)
677677
end subroutine db_changes_int32
678678

679679
subroutine db_changes_int64(db, n)
@@ -684,7 +684,7 @@ subroutine db_changes_int64(db, n)
684684
type(db_type), intent(inout) :: db !! Database.
685685
integer(i8), intent(out) :: n !! Number of changes.
686686

687-
n = sqlite3_changes64(db%ctx)
687+
n = sqlite3_changes64(db%context)
688688
end subroutine db_changes_int64
689689

690690
subroutine db_column_double(dbs, index, value)
@@ -693,7 +693,7 @@ subroutine db_column_double(dbs, index, value)
693693
integer, intent(in) :: index !! Column index.
694694
real(r8), intent(out) :: value !! Value.
695695

696-
value = sqlite3_column_double(dbs%ctx, index)
696+
value = sqlite3_column_double(dbs%context, index)
697697
end subroutine db_column_double
698698

699699
subroutine db_column_int(dbs, index, value)
@@ -702,7 +702,7 @@ subroutine db_column_int(dbs, index, value)
702702
integer, intent(in) :: index !! Column index.
703703
integer(i4), intent(out) :: value !! Value.
704704

705-
value = sqlite3_column_int(dbs%ctx, index)
705+
value = sqlite3_column_int(dbs%context, index)
706706
end subroutine db_column_int
707707

708708
subroutine db_column_int64(dbs, index, value)
@@ -711,7 +711,7 @@ subroutine db_column_int64(dbs, index, value)
711711
integer, intent(in) :: index !! Column index.
712712
integer(i8), intent(out) :: value !! Value.
713713

714-
value = sqlite3_column_int64(dbs%ctx, index)
714+
value = sqlite3_column_int64(dbs%context, index)
715715
end subroutine db_column_int64
716716

717717
subroutine db_column_text(dbs, index, value, n)
@@ -721,7 +721,7 @@ subroutine db_column_text(dbs, index, value, n)
721721
character(*), intent(inout) :: value !! Value.
722722
integer, intent(out) :: n !! Actual string length.
723723

724-
value = sqlite3_column_text (dbs%ctx, index)
725-
n = sqlite3_column_bytes(dbs%ctx, index)
724+
value = sqlite3_column_text (dbs%context, index)
725+
n = sqlite3_column_bytes(dbs%context, index)
726726
end subroutine db_column_text
727727
end module dm_db

src/dm_db_api.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ integer function dm_db_backup(db, path, wal, callback, nsteps, sleep_time) resul
368368

369369
sql_block: block
370370
rc = E_DB_BACKUP
371-
ptr = sqlite3_backup_init(backup%ctx, 'main', db%ctx, 'main')
371+
ptr = sqlite3_backup_init(backup%context, 'main', db%context, 'main')
372372
if (.not. c_associated(ptr)) exit sql_block
373373

374374
do
@@ -1820,7 +1820,7 @@ integer function dm_db_open(db, path, cache_size, create, foreign_keys, read_onl
18201820

18211821
! Open database.
18221822
rc = E_IO
1823-
if (sqlite3_open_v2(trim(path), db%ctx, flag) /= SQLITE_OK) return
1823+
if (sqlite3_open_v2(trim(path), db%context, flag) /= SQLITE_OK) return
18241824

18251825
! Set cache size.
18261826
rc = dm_db_set_cache_size(db, -1 * cache_size_)
@@ -3603,7 +3603,7 @@ subroutine dm_db_close(db, optimize, error)
36033603
if (dm_is_error(rc)) exit db_block
36043604
end if
36053605

3606-
stat = sqlite3_close(db%ctx)
3606+
stat = sqlite3_close(db%context)
36073607

36083608
rc = E_DB_BUSY
36093609
if (stat == SQLITE_BUSY) exit db_block
@@ -3612,8 +3612,8 @@ subroutine dm_db_close(db, optimize, error)
36123612
if (stat /= SQLITE_OK) exit db_block
36133613

36143614
rc = E_COMPILER
3615-
db%ctx = c_null_ptr
3616-
if (c_associated(db%ctx)) exit db_block
3615+
db%context = c_null_ptr
3616+
if (c_associated(db%context)) exit db_block
36173617

36183618
rc = E_NONE
36193619
end block db_block

src/dm_ipc_mutex.f90

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module dm_ipc_mutex
1111
type, public :: ipc_mutex_type
1212
!! Opaque IPC mutex type.
1313
private
14-
type(c_ptr) :: ctx = c_null_ptr !! NNG mutex context.
14+
type(c_ptr) :: context = c_null_ptr !! NNG mutex context.
1515
end type ipc_mutex_type
1616

1717
public :: dm_ipc_mutex_create
@@ -37,7 +37,7 @@ integer function dm_ipc_mutex_create(mutex) result(rc)
3737

3838
integer :: stat
3939

40-
stat= nng_mtx_alloc(mutex%ctx)
40+
stat= nng_mtx_alloc(mutex%context)
4141
rc = dm_ipc_error(stat)
4242
end function dm_ipc_mutex_create
4343

@@ -48,20 +48,20 @@ subroutine dm_ipc_mutex_destroy(mutex)
4848
!! Destroys NNG mutex.
4949
type(ipc_mutex_type), intent(inout) :: mutex !! IPC mutex.
5050

51-
call nng_mtx_free(mutex%ctx)
51+
call nng_mtx_free(mutex%context)
5252
end subroutine dm_ipc_mutex_destroy
5353

5454
subroutine dm_ipc_mutex_lock(mutex)
5555
!! Locks NNG mutex.
5656
type(ipc_mutex_type), intent(inout) :: mutex !! IPC mutex.
5757

58-
call nng_mtx_lock(mutex%ctx)
58+
call nng_mtx_lock(mutex%context)
5959
end subroutine dm_ipc_mutex_lock
6060

6161
subroutine dm_ipc_mutex_unlock(mutex)
6262
!! Unlocks NNG mutex.
6363
type(ipc_mutex_type), intent(inout) :: mutex !! IPC mutex.
6464

65-
call nng_mtx_unlock(mutex%ctx)
65+
call nng_mtx_unlock(mutex%context)
6666
end subroutine dm_ipc_mutex_unlock
6767
end module dm_ipc_mutex

0 commit comments

Comments
 (0)