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

Main merge of #405 on RC #406

Merged
merged 1 commit into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 16 additions & 15 deletions src/pdb_drv/silo_pdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4019,8 +4019,10 @@ db_pdb_GetMultimesh (DBfile *_dbfile, char const *objname)
* them into separate names.
*----------------------------------------*/

if ((tmpnames != NULL) && (mm->nblocks > 0)) {
db_StringListToStringArrayMBOpt(tmpnames, &(mm->meshnames), &(mm->meshnames_alloc), mm->nblocks);
if (tmpnames != NULL) {
if (mm->nblocks > 0)
db_StringListToStringArrayMBOpt(tmpnames, &(mm->meshnames), &(mm->meshnames_alloc), mm->nblocks);
FREE(tmpnames);
}
if ((tmpgnames != NULL) && (mm->lgroupings > 0)) {
mm->groupnames = DBStringListToStringArray(tmpgnames, &(mm->lgroupings), !skipFirstSemicolon);
Expand Down Expand Up @@ -4295,8 +4297,10 @@ db_pdb_GetMultivar (DBfile *_dbfile, char const *objname)
* them into separate names.
*----------------------------------------*/

if (tmpnames != NULL && mv->nvars > 0) {
db_StringListToStringArrayMBOpt(tmpnames, &(mv->varnames), &(mv->varnames_alloc), mv->nvars);
if (tmpnames != NULL) {
if (mv->nvars > 0)
db_StringListToStringArrayMBOpt(tmpnames, &(mv->varnames), &(mv->varnames_alloc), mv->nvars);
FREE(tmpnames);
}

if (rpnames != NULL)
Expand Down Expand Up @@ -4432,9 +4436,10 @@ db_pdb_GetMultimat (DBfile *_dbfile, char const *objname)
* them into separate names.
*----------------------------------------*/

if (tmpnames != NULL && mt->nmats > 0)
{
db_StringListToStringArrayMBOpt(tmpnames, &(mt->matnames), &(mt->matnames_alloc), mt->nmats);
if (tmpnames != NULL) {
if (mt->nmats > 0)
db_StringListToStringArrayMBOpt(tmpnames, &(mt->matnames), &(mt->matnames_alloc), mt->nmats);
FREE(tmpnames);
}

if (tmpmaterial_names && mt->nmatnos > 0)
Expand Down Expand Up @@ -4551,9 +4556,11 @@ db_pdb_GetMultimatspecies (DBfile *_dbfile, char const *objname)
* break them into separate names.
*----------------------------------------*/

if (tmpnames != NULL && mms->nspec > 0)
if (tmpnames != NULL)
{
db_StringListToStringArrayMBOpt(tmpnames, &(mms->specnames), &(mms->specnames_alloc), mms->nspec);
if (mms->nspec > 0)
db_StringListToStringArrayMBOpt(tmpnames, &(mms->specnames), &(mms->specnames_alloc), mms->nspec);
FREE(tmpnames);
}

if (tmpspecnames != NULL)
Expand Down Expand Up @@ -6808,17 +6815,11 @@ db_pdb_ReadMatVals(DBfile *_dbfile, char const *vname, int objtype,
if (mat->matlist[i] >= 0) continue;

mixidx = -(mat->matlist[i]);
printf("mixidx = %d\n", mixidx);
printf("dsname[1] = \"%s\"\n", dsnames[1]);
printf("dsname[2] = \"%s\"\n", dsnames[2]);
printf("dsname[3] = \"%s\"\n", dsnames[3]);

while (mixidx != 0)
{
ind[0] = mixidx-1; ind[1] = mixidx-1; ind[2] = 1;
PJ_read_alt(dbfile->pdb, (char*)dsnames[2], &mix_next, ind);
printf("ind[0]=%ld,ind[1]=%ld,ind[2]=%ld\n",ind[0],ind[1],ind[2]);
printf("mix_next = %d\n",mix_next);
PJ_read_alt(dbfile->pdb, (char*)dsnames[1], &mix_vf, ind);
if (memcmp(halfa,halfc,halfn) == 0 || memcmp(halfb,halfd,halfn) == 0)
{
Expand Down
31 changes: 18 additions & 13 deletions src/silo/silo_json.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,11 @@ static void json_object_set_deleter(json_object *jso,
void
json_object_extptr_delete(struct json_object *jso)
{
void *extptr = json_object_get_extptr_ptr(jso);
void *extptr = json_object_get_strptr(jso);
if (extptr) free(extptr);
json_object_put(jso);
free(jso->o.c_string.str);
printbuf_free(jso->_pb);
free(jso);
}

static int
Expand Down Expand Up @@ -238,14 +240,18 @@ struct json_object *
json_object_new_strptr(void *p)
{
static char tmp[32];
struct json_object *retval;

if (sizeof(p) == sizeof(unsigned))
snprintf(tmp, sizeof(tmp), "0x%016x", (unsigned) ((unsigned long long) p));
else if (sizeof(p) == sizeof(unsigned long))
snprintf(tmp, sizeof(tmp), "0x%016lx", (unsigned long) ((unsigned long long) p));
else if (sizeof(p) == sizeof(unsigned long long))
snprintf(tmp, sizeof(tmp), "0x%016llx", (unsigned long long) p);

return json_object_new_string(tmp);
retval = json_object_new_string(tmp);
json_object_set_deleter(retval, json_object_extptr_delete);
return retval;
}

void *
Expand All @@ -265,17 +271,17 @@ json_object_new_extptr(void *p, int ndims, int const *dims, int datatype)
int i;
struct json_object *jobj = json_object_new_object();
struct json_object *jarr = json_object_new_array();
struct json_object *jptr = json_object_new_strptr(p);

json_object_set_serializer(jobj, json_object_extptr_to_json_string, 0, 0);
json_object_set_deleter(jobj, json_object_extptr_delete);

for (i = 0; i < ndims; i++)
json_object_array_add(jarr, json_object_new_int(dims[i]));

json_object_object_add(jobj, "ptr", json_object_new_strptr(p));
json_object_object_add(jobj, "datatype", json_object_new_int(datatype));
json_object_object_add(jobj, "ndims", json_object_new_int(ndims));
json_object_object_add(jobj, "dims", jarr);
json_object_object_add(jobj, "ptr", jptr);

return jobj;
}
Expand Down Expand Up @@ -412,8 +418,7 @@ json_object_from_binary_buf_recurse(struct json_object *jso, void *buf)
p = malloc(nvals*db_GetMachDataSize(datatype));
memcpy(p, buf+offset, nvals*db_GetMachDataSize(datatype));
json_object_object_del(iter.val,"ptr");
snprintf(strptr, sizeof(strptr), "%p", p);
json_object_object_add(iter.val, "ptr", json_object_new_string(strptr));
json_object_object_add(iter.val, "ptr", json_object_new_strptr(p));
}
else
{
Expand Down Expand Up @@ -608,6 +613,7 @@ json_object_reconstitute_extptrs(struct json_object *obj)
json_object_object_add(pobj, mname,
json_object_new_extptr(pdata, ndims, dims, datatype));

free(dims);
free(mname);
}
}
Expand Down Expand Up @@ -1770,8 +1776,6 @@ int DBWriteJsonObject(DBfile *dbfile, struct json_object *jobj)
break;
}

/* warning STRDUPS ARE LEAKS */

case json_type_object: /* must be extptr array reference */
{
if (json_object_object_get_ex(mobj, "ptr", 0) &&
Expand All @@ -1783,12 +1787,13 @@ int DBWriteJsonObject(DBfile *dbfile, struct json_object *jobj)
long dims[32];
void *p = json_object_get_strptr(json_object_object_get(mobj, "ptr"));
int datatype = json_object_get_int(json_object_object_get(mobj, "datatype"));
char *dtstr = db_GetDatatypeString(datatype);
int ndims = json_object_get_int(json_object_object_get(mobj, "ndims"));
struct json_object *darr = json_object_object_get(mobj, "dims");
for (i = 0; i < ndims; i++)
dims[i] = (long) json_object_get_int(json_object_array_get_idx(darr, i));
DBWriteComponent(dbfile, sobj, mname, strdup(objnm),
db_GetDatatypeString(datatype), p, ndims, dims);
DBWriteComponent(dbfile, sobj, mname, objnm, dtstr, p, ndims, dims);
free(dtstr);
}
else
{
Expand All @@ -1800,9 +1805,9 @@ int DBWriteJsonObject(DBfile *dbfile, struct json_object *jobj)
snprintf(tmp, sizeof(tmp), "anon_%d", cnt);

if (has_silo_name && has_silo_type)
DBAddStrComponent(sobj, mname, strdup(json_object_get_string(silo_name_subobj)));
DBAddStrComponent(sobj, mname, json_object_get_string(silo_name_subobj));
else
DBAddStrComponent(sobj, mname, strdup(tmp));
DBAddStrComponent(sobj, mname, tmp);
DBWriteJsonObject(dbfile, mobj);
}

Expand Down
1 change: 1 addition & 0 deletions tests/empty.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ main(int argc, char *argv[])
/*ASSERT(DBWrite(dbfile,"empty_writeb",0, 0,ZZ,DB_FLOAT),retval<0,retval==0);*/
}

DBFreeOptlist(ol);
DBClose(dbfile);
dbfile = 0;

Expand Down
3 changes: 2 additions & 1 deletion tests/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ main(int argc, char *argv[])

/* Example of getting a Silo object from a silo file as a json object */
jsilo_obj = DBGetJsonObject(dbfile, "hex");
printf("%s\n", json_object_to_json_string_ext(jsilo_obj, 0));
DBClose(dbfile);
printf("%s\n", json_object_to_json_string_ext(jsilo_obj, 0));

/* Test interface to query extptr members from jsilo_obj */
{
Expand Down Expand Up @@ -194,6 +194,7 @@ main(int argc, char *argv[])
/* Example of taking a standard silo object and adding some arbitrary stuff to it */
json_object_to_file("onehex.json", jsilo_obj);
json_object_put(jsilo_obj);

fil_obj = json_object_from_file("onehex.json");
json_object_reconstitute_extptrs(fil_obj);
printf("fil_obj=%s\n", json_object_to_json_string(fil_obj));
Expand Down
2 changes: 2 additions & 0 deletions tests/multi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3391,6 +3391,8 @@ build_block_ucd3d(DBfile *dbfile, char dirnames[MAXBLOCKS][STRLEN],
FREE(mix_next);
FREE(mix_mat);
FREE(mix_zone);
FREE(mix_zone2);
FREE(mix_zone_map);
FREE(matlist2);
FREE(ghost);

Expand Down