diff --git a/modules/database/src/std/dev/devAaiSoft.c b/modules/database/src/std/dev/devAaiSoft.c index 55975bae0..aafdd1bcd 100644 --- a/modules/database/src/std/dev/devAaiSoft.c +++ b/modules/database/src/std/dev/devAaiSoft.c @@ -47,19 +47,15 @@ static long init_record(dbCommon *pcommon) aaiRecord *prec = (aaiRecord *)pcommon; DBLINK *plink = &prec->inp; - /* This is pass 0, link hasn't been initialized yet */ - dbInitLink(plink, DBF_INLINK); + /* Ask record to call us in pass 1 instead */ + if (prec->pact != 2) { + return 2; + } if (dbLinkIsConstant(plink)) { long nRequest = prec->nelm; long status; - /* Allocate a buffer, record support hasn't done that yet */ - if (!prec->bptr) { - prec->bptr = callocMustSucceed(nRequest, dbValueSize(prec->ftvl), - "devAaiSoft: buffer calloc failed"); - } - status = dbLoadLinkArray(plink, prec->ftvl, prec->bptr, &nRequest); if (!status) { prec->nord = nRequest; diff --git a/modules/database/src/std/rec/aaiRecord.c b/modules/database/src/std/rec/aaiRecord.c index c1410067c..157a48f5b 100644 --- a/modules/database/src/std/rec/aaiRecord.c +++ b/modules/database/src/std/rec/aaiRecord.c @@ -112,16 +112,18 @@ static long init_record(struct dbCommon *pcommon, int pass) prec->ftvl = DBF_UCHAR; prec->nord = (prec->nelm == 1); - /* we must call pdset->init_record in pass 0 - because it may set prec->bptr which must - not change after links are established before pass 1 - */ - + /* call pdset->init_record() in pass 0 so it can do its own + * memory allocation and set prec->bptr, which must be set by + * the end of pass 0. + */ if (pdset->common.init_record) { long status = pdset->common.init_record(pcommon); - /* init_record may set the bptr to point to the data */ - if (status) + if (status == 2) { + /* requesting pass 1 callback, remember to do that */ + prec->pact = 2; + } + else if (status) return status; } if (!prec->bptr) { @@ -132,6 +134,14 @@ static long init_record(struct dbCommon *pcommon, int pass) return 0; } + if (prec->pact == 2) { + /* device support asked for an init_record() callback in pass 1 */ + long status = pdset->common.init_record(pcommon); + if (status) + return status; + prec->pact = FALSE; + } + recGblInitSimm(pcommon, &prec->sscn, &prec->oldsimm, &prec->simm, &prec->siml); /* must have read_aai function defined */