change type keyword to return a pointer to static location for better portability
This commit is contained in:
@ -775,11 +775,10 @@ class lammps(object):
|
|||||||
ptr = self.lib.lammps_last_thermo(self.lmp, c_char_p("keyword".encode()), i)
|
ptr = self.lib.lammps_last_thermo(self.lmp, c_char_p("keyword".encode()), i)
|
||||||
kw = cast(ptr, c_char_p).value.decode()
|
kw = cast(ptr, c_char_p).value.decode()
|
||||||
|
|
||||||
# temporarily switch return type since this stores an int in a pointer
|
|
||||||
self.lib.lammps_last_thermo.restype = c_int
|
|
||||||
with ExceptionCheck(self):
|
with ExceptionCheck(self):
|
||||||
typ = self.lib.lammps_last_thermo(self.lmp, c_char_p("type".encode()), i)
|
ptr = self.lib.lammps_last_thermo(self.lmp, c_char_p("type".encode()), i)
|
||||||
self.lib.lammps_last_thermo.restype = c_void_p
|
typ = cast(ptr, POINTER(c_int)).contents.value
|
||||||
|
|
||||||
with ExceptionCheck(self):
|
with ExceptionCheck(self):
|
||||||
ptr = self.lib.lammps_last_thermo(self.lmp, c_char_p("data".encode()), i)
|
ptr = self.lib.lammps_last_thermo(self.lmp, c_char_p("data".encode()), i)
|
||||||
|
|
||||||
|
|||||||
@ -765,6 +765,13 @@ of the last thermo output data and the corresponding keyword strings.
|
|||||||
The how to handle the return value depends on the value of the *what*
|
The how to handle the return value depends on the value of the *what*
|
||||||
argument string.
|
argument string.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
The *type* property points to a static location that is reassigned
|
||||||
|
with every call, so the returned pointer should be recast,
|
||||||
|
dereferenced, and assigned immediately. Otherwise, its value may be
|
||||||
|
changed with the next invocation of the function.
|
||||||
|
|
||||||
.. list-table::
|
.. list-table::
|
||||||
:header-rows: 1
|
:header-rows: 1
|
||||||
:widths: auto
|
:widths: auto
|
||||||
@ -787,7 +794,7 @@ argument string.
|
|||||||
- yes
|
- yes
|
||||||
* - type
|
* - type
|
||||||
- data type of thermo output column; see :cpp:enum:`_LMP_DATATYPE_CONST`
|
- data type of thermo output column; see :cpp:enum:`_LMP_DATATYPE_CONST`
|
||||||
- const int (**not** a pointer)
|
- pointer to static int
|
||||||
- yes
|
- yes
|
||||||
* - data
|
* - data
|
||||||
- actual field data for column
|
- actual field data for column
|
||||||
@ -808,6 +815,7 @@ void *lammps_last_thermo(void *handle, const char *what, int index)
|
|||||||
Thermo *th = lmp->output->thermo;
|
Thermo *th = lmp->output->thermo;
|
||||||
if (!th) return nullptr;
|
if (!th) return nullptr;
|
||||||
const int nfield = *th->get_nfield();
|
const int nfield = *th->get_nfield();
|
||||||
|
static int datatype;
|
||||||
|
|
||||||
BEGIN_CAPTURE
|
BEGIN_CAPTURE
|
||||||
{
|
{
|
||||||
@ -826,11 +834,14 @@ void *lammps_last_thermo(void *handle, const char *what, int index)
|
|||||||
if ((index < 0) || (index >= nfield)) return nullptr;
|
if ((index < 0) || (index >= nfield)) return nullptr;
|
||||||
const auto &field = th->get_fields()[index];
|
const auto &field = th->get_fields()[index];
|
||||||
if (field.type == multitype::INT) {
|
if (field.type == multitype::INT) {
|
||||||
val = (void *) LAMMPS_INT;
|
datatype = LAMMPS_INT;
|
||||||
|
val = (void *) &datatype;
|
||||||
} else if (field.type == multitype::BIGINT) {
|
} else if (field.type == multitype::BIGINT) {
|
||||||
val = (void *) LAMMPS_INT64;
|
datatype = LAMMPS_INT64;
|
||||||
|
val = (void *) &datatype;
|
||||||
} else if (field.type == multitype::DOUBLE) {
|
} else if (field.type == multitype::DOUBLE) {
|
||||||
val = (void *) LAMMPS_DOUBLE;
|
datatype = LAMMPS_DOUBLE;
|
||||||
|
val = (void *) &datatype;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (strcmp(what, "data") == 0) {
|
} else if (strcmp(what, "data") == 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user