Skip to content

Commit

Permalink
Add const to mjsDefault when used as function argument.
Browse files Browse the repository at this point in the history
Fixes #2197.

PiperOrigin-RevId: 692346264
Change-Id: Iddb9be1377a7d59c86911802d8c5563f6bf6b043
  • Loading branch information
quagla authored and copybara-github committed Nov 2, 2024
1 parent 47ebb06 commit ebe60b9
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 111 deletions.
28 changes: 14 additions & 14 deletions doc/includes/references.h
Original file line number Diff line number Diff line change
Expand Up @@ -3567,22 +3567,22 @@ mjsFrame* mjs_attachFrame(mjsBody* parent, const mjsFrame* child,
mjsBody* mjs_attachToSite(mjsSite* parent, const mjsBody* child,
const char* prefix, const char* suffix);
int mjs_detachBody(mjSpec* s, mjsBody* b);
mjsBody* mjs_addBody(mjsBody* body, mjsDefault* def);
mjsSite* mjs_addSite(mjsBody* body, mjsDefault* def);
mjsJoint* mjs_addJoint(mjsBody* body, mjsDefault* def);
mjsBody* mjs_addBody(mjsBody* body, const mjsDefault* def);
mjsSite* mjs_addSite(mjsBody* body, const mjsDefault* def);
mjsJoint* mjs_addJoint(mjsBody* body, const mjsDefault* def);
mjsJoint* mjs_addFreeJoint(mjsBody* body);
mjsGeom* mjs_addGeom(mjsBody* body, mjsDefault* def);
mjsCamera* mjs_addCamera(mjsBody* body, mjsDefault* def);
mjsLight* mjs_addLight(mjsBody* body, mjsDefault* def);
mjsGeom* mjs_addGeom(mjsBody* body, const mjsDefault* def);
mjsCamera* mjs_addCamera(mjsBody* body, const mjsDefault* def);
mjsLight* mjs_addLight(mjsBody* body, const mjsDefault* def);
mjsFrame* mjs_addFrame(mjsBody* body, mjsFrame* parentframe);
void mjs_delete(mjsElement* element);
mjsActuator* mjs_addActuator(mjSpec* s, mjsDefault* def);
mjsActuator* mjs_addActuator(mjSpec* s, const mjsDefault* def);
mjsSensor* mjs_addSensor(mjSpec* s);
mjsFlex* mjs_addFlex(mjSpec* s);
mjsPair* mjs_addPair(mjSpec* s, mjsDefault* def);
mjsPair* mjs_addPair(mjSpec* s, const mjsDefault* def);
mjsExclude* mjs_addExclude(mjSpec* s);
mjsEquality* mjs_addEquality(mjSpec* s, mjsDefault* def);
mjsTendon* mjs_addTendon(mjSpec* s, mjsDefault* def);
mjsEquality* mjs_addEquality(mjSpec* s, const mjsDefault* def);
mjsTendon* mjs_addTendon(mjSpec* s, const mjsDefault* def);
mjsWrap* mjs_wrapSite(mjsTendon* tendon, const char* name);
mjsWrap* mjs_wrapGeom(mjsTendon* tendon, const char* name, const char* sidesite);
mjsWrap* mjs_wrapJoint(mjsTendon* tendon, const char* name, double coef);
Expand All @@ -3593,19 +3593,19 @@ mjsTuple* mjs_addTuple(mjSpec* s);
mjsKey* mjs_addKey(mjSpec* s);
mjsPlugin* mjs_addPlugin(mjSpec* s);
mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, const mjsDefault* parent);
mjsMesh* mjs_addMesh(mjSpec* s, mjsDefault* def);
mjsMesh* mjs_addMesh(mjSpec* s, const mjsDefault* def);
mjsHField* mjs_addHField(mjSpec* s);
mjsSkin* mjs_addSkin(mjSpec* s);
mjsTexture* mjs_addTexture(mjSpec* s);
mjsMaterial* mjs_addMaterial(mjSpec* s, mjsDefault* def);
mjsMaterial* mjs_addMaterial(mjSpec* s, const mjsDefault* def);
mjSpec* mjs_getSpec(mjsElement* element);
mjSpec* mjs_findSpec(mjSpec* spec, const char* name);
mjsBody* mjs_findBody(mjSpec* s, const char* name);
mjsElement* mjs_findElement(mjSpec* s, mjtObj type, const char* name);
mjsBody* mjs_findChild(mjsBody* body, const char* name);
mjsFrame* mjs_findFrame(mjSpec* s, const char* name);
mjsDefault* mjs_getDefault(mjsElement* element);
mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
const mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
mjsDefault* mjs_getSpecDefault(mjSpec* s);
int mjs_getId(mjsElement* element);
mjsElement* mjs_firstChild(mjsBody* body, mjtObj type, int recurse);
Expand All @@ -3625,7 +3625,7 @@ void mjs_setDouble(mjDoubleVec* dest, const double* array, int size);
void mjs_setPluginAttributes(mjsPlugin* plugin, void* attributes);
const char* mjs_getString(const mjString* source);
const double* mjs_getDouble(const mjDoubleVec* source, int* size);
void mjs_setDefault(mjsElement* element, mjsDefault* def);
void mjs_setDefault(mjsElement* element, const mjsDefault* def);
void mjs_setFrame(mjsElement* dest, mjsFrame* frame);
const char* mjs_resolveOrientation(double quat[4], mjtByte degree, const char* sequence,
const mjsOrientation* orientation);
Expand Down
28 changes: 14 additions & 14 deletions include/mujoco/mujoco.h
Original file line number Diff line number Diff line change
Expand Up @@ -1421,25 +1421,25 @@ MJAPI int mjs_detachBody(mjSpec* s, mjsBody* b);
//---------------------------------- Tree elements -------------------------------------------------

// Add child body to body, return child.
MJAPI mjsBody* mjs_addBody(mjsBody* body, mjsDefault* def);
MJAPI mjsBody* mjs_addBody(mjsBody* body, const mjsDefault* def);

// Add site to body, return site spec.
MJAPI mjsSite* mjs_addSite(mjsBody* body, mjsDefault* def);
MJAPI mjsSite* mjs_addSite(mjsBody* body, const mjsDefault* def);

// Add joint to body.
MJAPI mjsJoint* mjs_addJoint(mjsBody* body, mjsDefault* def);
MJAPI mjsJoint* mjs_addJoint(mjsBody* body, const mjsDefault* def);

// Add freejoint to body.
MJAPI mjsJoint* mjs_addFreeJoint(mjsBody* body);

// Add geom to body.
MJAPI mjsGeom* mjs_addGeom(mjsBody* body, mjsDefault* def);
MJAPI mjsGeom* mjs_addGeom(mjsBody* body, const mjsDefault* def);

// Add camera to body.
MJAPI mjsCamera* mjs_addCamera(mjsBody* body, mjsDefault* def);
MJAPI mjsCamera* mjs_addCamera(mjsBody* body, const mjsDefault* def);

// Add light to body.
MJAPI mjsLight* mjs_addLight(mjsBody* body, mjsDefault* def);
MJAPI mjsLight* mjs_addLight(mjsBody* body, const mjsDefault* def);

// Add frame to body.
MJAPI mjsFrame* mjs_addFrame(mjsBody* body, mjsFrame* parentframe);
Expand All @@ -1451,7 +1451,7 @@ MJAPI void mjs_delete(mjsElement* element);
//---------------------------------- Non-tree elements ---------------------------------------------

// Add actuator.
MJAPI mjsActuator* mjs_addActuator(mjSpec* s, mjsDefault* def);
MJAPI mjsActuator* mjs_addActuator(mjSpec* s, const mjsDefault* def);

// Add sensor.
MJAPI mjsSensor* mjs_addSensor(mjSpec* s);
Expand All @@ -1460,16 +1460,16 @@ MJAPI mjsSensor* mjs_addSensor(mjSpec* s);
MJAPI mjsFlex* mjs_addFlex(mjSpec* s);

// Add contact pair.
MJAPI mjsPair* mjs_addPair(mjSpec* s, mjsDefault* def);
MJAPI mjsPair* mjs_addPair(mjSpec* s, const mjsDefault* def);

// Add excluded body pair.
MJAPI mjsExclude* mjs_addExclude(mjSpec* s);

// Add equality.
MJAPI mjsEquality* mjs_addEquality(mjSpec* s, mjsDefault* def);
MJAPI mjsEquality* mjs_addEquality(mjSpec* s, const mjsDefault* def);

// Add tendon.
MJAPI mjsTendon* mjs_addTendon(mjSpec* s, mjsDefault* def);
MJAPI mjsTendon* mjs_addTendon(mjSpec* s, const mjsDefault* def);

// Wrap site using tendon.
MJAPI mjsWrap* mjs_wrapSite(mjsTendon* tendon, const char* name);
Expand Down Expand Up @@ -1505,7 +1505,7 @@ MJAPI mjsDefault* mjs_addDefault(mjSpec* s, const char* classname, const mjsDefa
//---------------------------------- Assets --------------------------------------------------------

// Add mesh.
MJAPI mjsMesh* mjs_addMesh(mjSpec* s, mjsDefault* def);
MJAPI mjsMesh* mjs_addMesh(mjSpec* s, const mjsDefault* def);

// Add height field.
MJAPI mjsHField* mjs_addHField(mjSpec* s);
Expand All @@ -1517,7 +1517,7 @@ MJAPI mjsSkin* mjs_addSkin(mjSpec* s);
MJAPI mjsTexture* mjs_addTexture(mjSpec* s);

// Add material.
MJAPI mjsMaterial* mjs_addMaterial(mjSpec* s, mjsDefault* def);
MJAPI mjsMaterial* mjs_addMaterial(mjSpec* s, const mjsDefault* def);


//---------------------------------- Find and get utilities ----------------------------------------
Expand All @@ -1544,7 +1544,7 @@ MJAPI mjsFrame* mjs_findFrame(mjSpec* s, const char* name);
MJAPI mjsDefault* mjs_getDefault(mjsElement* element);

// Find default in model by class name.
MJAPI mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);
MJAPI const mjsDefault* mjs_findDefault(mjSpec* s, const char* classname);

// Get global default from model.
MJAPI mjsDefault* mjs_getSpecDefault(mjSpec* s);
Expand Down Expand Up @@ -1614,7 +1614,7 @@ MJAPI const double* mjs_getDouble(const mjDoubleVec* source, int* size);
//---------------------------------- Spec utilities ------------------------------------------------

// Set element's default.
MJAPI void mjs_setDefault(mjsElement* element, mjsDefault* def);
MJAPI void mjs_setDefault(mjsElement* element, const mjsDefault* def);

// Set element's enclosing frame.
MJAPI void mjs_setFrame(mjsElement* dest, mjsFrame* frame);
Expand Down
28 changes: 14 additions & 14 deletions introspect/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9072,7 +9072,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand All @@ -9094,7 +9094,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand All @@ -9116,7 +9116,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9154,7 +9154,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand All @@ -9176,7 +9176,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand All @@ -9198,7 +9198,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9256,7 +9256,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9310,7 +9310,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9348,7 +9348,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand All @@ -9370,7 +9370,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9596,7 +9596,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9666,7 +9666,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down Expand Up @@ -9822,7 +9822,7 @@
FunctionDecl(
name='mjs_findDefault',
return_type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
parameters=(
FunctionParameterDecl(
Expand Down Expand Up @@ -10262,7 +10262,7 @@
FunctionParameterDecl(
name='def',
type=PointerType(
inner_type=ValueType(name='mjsDefault'),
inner_type=ValueType(name='mjsDefault', is_const=True),
),
),
),
Expand Down
2 changes: 1 addition & 1 deletion python/mujoco/specs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ PYBIND11_MODULE(_specs, m) {
py::return_value_policy::reference_internal);
mjSpec.def(
"find_default",
[](MjSpec& self, std::string& classname) -> raw::MjsDefault* {
[](MjSpec& self, std::string& classname) -> const raw::MjsDefault* {
return mjs_findDefault(self.ptr, classname.c_str());
},
py::return_value_policy::reference_internal);
Expand Down
Loading

0 comments on commit ebe60b9

Please sign in to comment.