问:
Weird behavior when modeling small multi-link object
I'm trying to model a small and light objects(the links of a rope). This is an example sdf. If I decrease the mass from 1.0 to 0.3 and adjust the inertias accordingly, it seems to disappear off the screen as soon as it touches the ground. With more links, I also get

```<code>RuntimeError: MultibodyPlant's discrete update solver failed to converge at simulation time =   0.004 with discrete update period =   0.001. This usually means that the plant's discrete update period is too large to resolve the system's dynamics for the given simulation conditions. This is often the case during abrupt collisions or during complex and fast changing contact configurations. Another common cause is the use of high gains in the simulation of closed loop systems. These might cause numerical instabilities given our discrete solver uses an explicit treatment of actuation inputs. Possible solutions include:
  1. reduce the discrete update period set at construction,
  2. decrease the high gains in your controller whenever possible,
  3. switch to a continuous model (discrete update period is zero),      though this might affect the simulation run time.
</code>```

or

```<code>terminated by signal SIGSEGV (Address boundary error)
</code>```

I can work around a lot of these issues if I don't compute physically accurate inertias or if I put a mass of 1(and large inertias) on the dummy link, but I'm wondering if there's a proper way to resolve these errors. I'll also add that I'm not seeing weird behavior for a single link.

SDF: 2 links with mass 1kg

```<code><sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>1.0</mass>
        <inertia>
          <ixx>0.0008395833333333335</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0008395833333333335</iyy>
          <iyz>0</iyz>
          <izz>1.25e-05</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>1.0</mass>
        <inertia>
          <ixx>0.0008395833333333335</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0008395833333333335</iyy>
          <iyz>0</iyz>
          <izz>1.25e-05</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose> 0 0 1.9 0 0 0 </pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-0.5</lower>
        <upper>0.5</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 0.0 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-0.5</lower>
        <upper>0.5</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 0.0 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>
</code>```

SDF: 2 links with mass 0.3kg

```<code><sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose>0 0 1.9 0 0 0</pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>
<sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose>0 0 1.9 0 0 0</pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>
</code>```

答:
That error is usually caused because our discrete solver fails. As the message suggests, did you attempt to reduce the discrete period (aka time step) at construction of the MultibodyPlant? What I imagine happens here is that your small links lead to fast dynamics and therefore you need smaller time steps to resolve it.

The link dissapearing is most likely due to the fact that the visualizer is already plotting a bad state (diverged, possibly with lots of NaNs). So the visualizer alone won't tell you much.

When setting up the discrete solver you always need an estimation of you system's time scale, stemming from the physics you want to resolve. For your case, and only because I don't know if you have applied forces, thinking of each link as a simple pendulum would allow you to estimate a time scale by for instance computing the period of that pendulum.

With your numbers, for a physical pendulum with inertia Iyy = 0.001 (about the link's end, motion about z seems restricted by your joints), m = 0.3, R=0.05 (distance to COM), I get a compound pendulum effective length of L = I/(m*R) = 0.0667 m. With this I get a period T = 2*pi*sqrt(L/g) = 0.52 seconds. Say I'd take 500 steps per period, then I'd estimate a time step of dt = 1ms.

That's a very rough estimate given I know nothing about your system or external forces. But summarizing, I believe your problem is the plant's time step.

Edit

What about penetration allowance? (MultibodyPlant::set_penetration_allowance()). When contact is present MultibodyPlant::get_contact_penalty_method_time_scale() will give you an estimate of the time scale due to contact. Usually you need to set a time step that is able to comfortably resolve that dynamics.

Body:
I'm trying to model a small and light objects(the links of a rope). This is an example sdf. If I decrease the mass from 1.0 to 0.3 and adjust the inertias accordingly, it seems to disappear off the screen as soon as it touches the ground. With more links, I also get

RuntimeError: MultibodyPlant's discrete update solver failed to converge at simulation time =   0.004 with discrete update period =   0.001. This usually means that the plant's discrete update period is too large to resolve the system's dynamics for the given simulation conditions. This is often the case during abrupt collisions or during complex and fast changing contact configurations. Another common cause is the use of high gains in the simulation of closed loop systems. These might cause numerical instabilities given our discrete solver uses an explicit treatment of actuation inputs. Possible solutions include:
  1. reduce the discrete update period set at construction,
  2. decrease the high gains in your controller whenever possible,
  3. switch to a continuous model (discrete update period is zero),      though this might affect the simulation run time.

or

terminated by signal SIGSEGV (Address boundary error)

I can work around a lot of these issues if I don't compute physically accurate inertias or if I put a mass of 1(and large inertias) on the dummy link, but I'm wondering if there's a proper way to resolve these errors. I'll also add that I'm not seeing weird behavior for a single link.

SDF: 2 links with mass 1kg

<sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>1.0</mass>
        <inertia>
          <ixx>0.0008395833333333335</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0008395833333333335</iyy>
          <iyz>0</iyz>
          <izz>1.25e-05</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>1.0</mass>
        <inertia>
          <ixx>0.0008395833333333335</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.0008395833333333335</iyy>
          <iyz>0</iyz>
          <izz>1.25e-05</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose> 0 0 1.9 0 0 0 </pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-0.5</lower>
        <upper>0.5</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 0.0 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-0.5</lower>
        <upper>0.5</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 0.0 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>

SDF: 2 links with mass 0.3kg

<sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose>0 0 1.9 0 0 0</pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>
<sdf version='1.6'>
    <model name='capsule'>
  <link name="capsule_1">
      <pose> 0 0 2.0 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_2">
      <pose> 0 0 1.9 0 0 0</pose>
      <inertial>
        <pose frame=''>0 0 -0.05 0 0 0</pose>
        <mass>0.3</mass>
        <inertia>
          <ixx>0.00025187500000000004</ixx>
          <ixy>0</ixy>
          <ixz>0</ixz>
          <iyy>0.00025187500000000004</iyy>
          <iyz>0</iyz>
          <izz>3.75e-06</izz>
        </inertia>
      </inertial>
      <visual name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>
        <material>
          <diffuse>0.5569 0.349 0.2353 1.0</diffuse>
        </material>
      </visual>

      <collision name='cylinder'>
        <pose frame=''> 0 0 -0.05 0 0 0 </pose>
        <geometry>
          <cylinder>
          <radius>0.005</radius>
          <length>0.1</length>
          </cylinder>
        </geometry>

        <surface>
          <friction>
          <ode>
            <mu>0.0</mu>
            <mu2>0.0</mu2>
          </ode>
          </friction>
        </surface>
      </collision>

  </link>
  <link name="capsule_1_extra">
    <pose>0 0 1.9 0 0 0</pose>
    <inertial>
      <pose frame=''>0 0 0 0 0 0 </pose>
      <mass>1e-10</mass>
      <inertia>
        <ixx>1e-10</ixx>
        <ixy>0</ixy>
        <ixz>0</ixz>
        <iyy>1e-10</iyy>
        <iyz>0</iyz>
        <izz>1e-10</izz>
      </inertia>
    </inertial>
  </link>
  <joint name="capsule_1_capsule_2_joint_x" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_2</child>
    <parent>capsule_1_extra</parent>
    <axis>
      <xyz> 1 0 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>

  <joint name="capsule_1_capsule_2_joint_y" type="revolute">
    <pose> 0 0 0 0 0 0 </pose>
    <child>capsule_1_extra</child>
    <parent>capsule_1</parent>
    <axis>
      <xyz> 0 1 0 </xyz>
      <limit>
        <effort>0</effort>
        <lower>-3.14</lower>
        <upper>3.14</upper>
      </limit>
      <dynamics>
        <damping> 1 </damping>
        <friction> 0 </friction>
        <spring_reference> 0 </spring_reference>
        <spring_stiffness> 10 </spring_stiffness>
      </dynamics>
      <use_parent_model_frame>1</use_parent_model_frame>
    </axis>
  </joint>
    </model>
</sdf>


来源: stackexchange

问:
RegEx for company name variations
I have a requirement to accept string values ONLY where they meet the following criteria :

1) Can start with special character if required

2) Must start with capital letter ( Even if the first character is a special character )

3) The string value must not have 2 special characters in a row ( consecutive )

4) The string value must not have 2 spaces in a row ( consecutive )

5) Accented characters are allowed ( eg: Faddas )

6) Enclosed values at the start of the string or at the end are valid but must be inside parenthesis ( ie: (Ltd) )

7) Numerics are allowed anywhere in the string value

I have the following regex value : ^(\(([^)]+)\))?[\@\#\$\%\&\*\(\)\-\_\+\]\[\'\;\:\?\.\,\!]?\p{Lu}+[\s'-]?\p{L}+(?:[\s'-]\p{L}+)+(\(([^)]+)\))*$

This works ok for the following tested values :

Éast-Shipping-ltd

Éast-Shipping(LTD)

But fails the next example :

Éast-123Shipping(LTD)

Is there any way to allow for numerics mid string ?

I have tried [0-9] variations, [A-Za-z09] variations and p{N} variations but to no avail.

Many thanks for your time.

答:
Here we have some characters acceptable for company names</p>

```<code>^[0-9A-Za-zÀ-ÿ\s,._+;()*~'#@!?&-]+$
</code>```

ContentLicense: CC BY-SA 3.0

Title: RegEx for company name variations

Body:
Here we have some characters acceptable for company names

^[0-9A-Za-zÀ-ÿ\s,._+;()*~'#@!?&-]+$

ContentLicense: CC BY-SA 4.0


问:
How to pass multiple template files to user_Data variable in terraform
assign multiple templates files to user_Data variable.
we dont want to merge this template in single file due to some architectural pattern . </p>

<p>I'm new to terraform so struggling on this. </p>

```<code>data "template_file" "userdata_lin1" {
  template = <<EOF
#!/bin/bash
crontab cronjobfileremote
EOF
}

data "template_file" "userdata_lin2" {
  template = <<EOF
#!/bin/bash
echo "hello"
EOF
}

 user_data  = "${data.template_file.user_data1.rendered}"
</code>```

答:
It is a fundamental constraint of most cloud platforms that "user data" or "custom metadata" etc (terminology varies by vendor) is a single opaque string of bytes. The interpretation of those bytes depends on what software you have installed in your virtual machine image that makes use of it.

A common choice of such software is cloud-init. If you are using cloud-init then the "user data" can be provided in a number of different formats.

The main way to provide multiple distinct sections to cloud-init is via a MIME-Multipart archive, which is a concatenation of several values interspersed with headers to allow cloud-init to identify the boundaries and understand how you intend each part to be interpreted.

Because cloud-init is a very common choice of software for interpreting "user data", Terraform has a cloudinit provider which includes a data source for constructing a MIME-Multipart archive.

```<code>data "cloudinit_config" "example" {
  gzip          = false
  base64_encode = false

  part {
    content_type = "text/x-shellscript"
    filename = "userdata_lin1"
    content  = <<-EOF
      #!/bin/bash
      crontab cronjobfileremote
    EOT
  }

  part {
    content_type = "text/x-shellscript"
    filename = "userdata_lin2"
    content  = <<-EOF
      #!/bin/bash
      echo "hello"
    EOT
  }
}
</code>```

You can then set your user_data argument to the output from this data source:

```<code>  user_data = data.cloudinit_config.example.rendered
</code>```

It's important to note that from the perspective of Terraform and from your cloud compute provider, the content of user_data is just an arbitrary string. Any issues in processing the string must be debugged within the target operating system itself, by reading the cloud-init logs to see how it interpreted the configuration and what happened when it tried to take those actions.

Body:
assign multiple templates files to user_Data variable.
we dont want to merge this template in single file due to some architectural pattern .

I'm new to terraform so struggling on this.

data "template_file" "userdata_lin1" {
  template = <<EOF
#!/bin/bash
crontab cronjobfileremote
EOF
}

data "template_file" "userdata_lin2" {
  template = <<EOF
#!/bin/bash
echo "hello"
EOF
}

 user_data  = "${data.template_file.user_data1.rendered}"

Body:
It is a fundamental constraint of most cloud platforms that "user data" or "custom metadata" etc (terminology varies by vendor) is a single opaque string of bytes. The interpretation of those bytes depends on what software you have installed in your virtual machine image that makes use of it.

A common choice of such software is cloud-init. If you are using cloud-init then the "user data" can be provided in a number of different formats.

The main way to provide multiple distinct sections to cloud-init is via a MIME-Multipart archive, which is a concatenation of several values interspersed with headers to allow cloud-init to identify the boundaries and understand how you intend each part to be interpreted.

Because cloud-init is a very common choice of software for interpreting "user data", Terraform has a cloudinit provider which includes a data source for constructing a MIME-Multipart archive.

data "cloudinit_config" "example" {
  gzip          = false
  base64_encode = false

  part {
    content_type = "text/x-shellscript"
    filename = "userdata_lin1"
    content  = <<-EOF
      #!/bin/bash
      crontab cronjobfileremote
    EOT
  }

  part {
    content_type = "text/x-shellscript"
    filename = "userdata_lin2"
    content  = <<-EOF
      #!/bin/bash
      echo "hello"
    EOT
  }
}

You can then set your user_data argument to the output from this data source:

  user_data = data.cloudinit_config.example.rendered

It's important to note that from the perspective of Terraform and from your cloud compute provider, the content of user_data is just an arbitrary string. Any issues in processing the string must be debugged within the target operating system itself, by reading the cloud-init logs to see how it interpreted the configuration and what happened when it tried to take those actions.


问:
Query Analysis Services Tabular Model Relationships
Is there a way to use DAX or MDX to query the Analysis Services Tabular Model Relationships?

I would like it to return the same tables that I get in Visual Studio when I do Manage Relationships...
     Active
     Table 1
     Cardinality
     Filter Direction
     Table 2

答: I'm afraid there's no DAX function where you can get the relationships, but there are DMVs for things like that: https://learn.microsoft.com/en-us/analysis-services/instances/use-dynamic-management-views-dmvs-to-monitor-analysis-services?view=asallproducts-allversions</p>


问:
Conan CMake and Embarcadero integration
I am trying to make Conan with CMake run with Embarcadero Tokyo 10.2.3 compiler. I can do CMake with Embarcadero following it's tutorial. But issue seems to happen with Conan. So I do the conan install. Then I do cmake .. -DCMAKE_CXX_COMPILER="bcc32c.exe" -DCMAKE_C_COMPILER="bcc32c.exe" -DCMAKE_VERBOSE_MAKEFILE=1 -G Ninja. I get the error

Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake
    detected 'Embarcadero'

The default conan profile shows compiler=Visual Studio which I believe is where the issue originates from. But dont know how to change it to Embarcadero (does not recognize) or if changing the default profile is the way to go. My CMakeLists.txt file looks like this (mostly default)

```<code>project(Timer)
cmake_minimum_required(VERSION 3.11)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(timer timer.cpp)
target_link_libraries(timer ${CONAN_LIBS})
</code>```

The full cmake output is below:

```<code>-- The C compiler identification is Embarcadero 7.30.36015
-- The CXX compiler identification is Embarcadero 7.30.36015
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Current conanbuildinfo.cmake directory: C:/Mathew Joy/Source/mytimer/build
CMake Error at build/conanbuildinfo.cmake:579 (message):
  **Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake
  detected 'Embarcadero'**
Call Stack (most recent call first):
  build/conanbuildinfo.cmake:237 (conan_check_compiler)
  CMakeLists.txt:5 (conan_basic_setup)
</code>```

答:
Visual Studio 2019 C++ is much better than Embarcadero. I have used both Tokyo and the Rio version, and there is no comparison. In addition you can download the Managed C++, which is called C++ CLR (not CLI), which will allow you to integrate .NET forms/consoles with native C++ applications.

Visual Studio 2019 C++ works well when creating Xamarin IOS libraries, which can easily be integrated with C# for Xamarin Forms. Xamarin Forms works for both Android and IOS (Xamarin).

In July 2019, Embarcadero finally added 64 bit Mac OS operating system, and MAC has been 64 bit since 2008.

That should tell you something right there.

Title: Conan CMake and Embarcadero integration

Body:
I am trying to make Conan with CMake run with Embarcadero Tokyo 10.2.3 compiler. I can do CMake with Embarcadero following it's tutorial. But issue seems to happen with Conan. So I do the conan install. Then I do cmake .. -DCMAKE_CXX_COMPILER="bcc32c.exe" -DCMAKE_C_COMPILER="bcc32c.exe" -DCMAKE_VERBOSE_MAKEFILE=1 -G Ninja. I get the error

Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake
    detected 'Embarcadero'

The default conan profile shows compiler=Visual Studio which I believe is where the issue originates from. But dont know how to change it to Embarcadero (does not recognize) or if changing the default profile is the way to go. My CMakeLists.txt file looks like this (mostly default)

project(Timer)
cmake_minimum_required(VERSION 3.11)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup()

add_executable(timer timer.cpp)
target_link_libraries(timer ${CONAN_LIBS})

The full cmake output is below:

-- The C compiler identification is Embarcadero 7.30.36015
-- The CXX compiler identification is Embarcadero 7.30.36015
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working C compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Embarcadero/Studio/19.0/bin/bcc32c.exe -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Current conanbuildinfo.cmake directory: C:/Mathew Joy/Source/mytimer/build
CMake Error at build/conanbuildinfo.cmake:579 (message):
  **Incorrect 'Visual Studio'.  Toolset specifies compiler as 'MSVC' but CMake
  detected 'Embarcadero'**
Call Stack (most recent call first):
  build/conanbuildinfo.cmake:237 (conan_check_compiler)
  CMakeLists.txt:5 (conan_basic_setup)


问:
How to convert string hhmm to time in python
How could I convert the below column Time 1 from string to time eg: Time2

Time1

438

448

1815

1758

Time2

04:38

04:48

18:15

17:58

Body:
You can use formatted strings:

Time1 = ['438','448','1815','1758']
Time2 = [f'{t[:-2]}:{t[-2:]}' for t in Time1]
print(Time2)

Output:

['4:38', '4:48', '18:15', '17:58']


问:
Visual Studio Code does not recognize OpenSSL that is already installed [ibp-vscode-extension]
I want to start using the IBM Blockchain Platform extension in Visual Studio Code 2017 using Windows 10.

After installing the extension, the prerequisites page informs that OpenSSL is not installed. However, I confirmed that OpenSSL is already installed in Windows.

I tried to find the answer to this problem online, but can't find it.
Is there a way to "allow" OpenSSL in Visual Studio Code? Or the problem is how I installed OpenSSL (through an .exe file)?

Thanks in advance!

答:
I had the same issue and this is how I resolved it! The info tab for OpenSSL explains where to install it!

Install to C:\OpenSSL-Win64


问:
Timeout issue during data transfer from MySQL to SQL Server using SSIS
I am trying to transfer 67,714,854 rows from MySQL to SQL Server using SSIS. The package times out after transferring 14,282,990 rows. I changed the time out property to 0 also, but that didn't help.

How do I resolve this issue?

答:
On your OLE DB Destination connection, what "Data access mode" have you selected.  If you have selected "Table or view - fast load" (this is the default), then there will be a "Maximum insert commit size" specified.  You can try one of two things:  1) change the commit size to a larger number; or 2) try the other data access mode "Table or vew".  Since you're getting a timeout error, I suspect that option 1 may not help (since you're already getting a timeout with a smaller value), so try option 2.  Although that will likely result in slower performance, it may actually complete successfully.  (You could then try @Siva's approach and split the output across multiple destinations to improve performance).

(Note: I'm referring to what's available in SQL Server 2008 R2, if you're using previous versions, it may be slightly different)

If none of the above work, you could also try to create a new SSIS package from scratch by running the SQL Server Import Wizard (right-click on your database in SQL Server Management Studio and select Tasks/Import Data.  Follow the wizard screens and near the end make sure you check the box to Save the SSIS package, and choose a file location to save it to.  Typically, the resulting SSIS package will be a functional package (and then you can also make whatever further modifications you like to it).


问:
LOAD DATA LOCAL INFILE forbidden in... PHP
I am trying to use LOAD DATA INFILE to insert some records into a table. Unfortunately, it's not working.

Here are some details

If I use this instruction:

```<code>LOAD DATA INFILE 'file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);
</code>```

It works using the MySQL client program and a PHP application. In this way it will look for the file in the Data Directory of my MySQL installation.

Now if I try to execute the instructions using the LOCAL option, it only works if I use the mysql client, but not from PHP:

```<code>LOAD DATA LOCAL INFILE 'path/to/file/file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);
</code>```

Again.. it works with MySQL client but not from the PHP application... I get this error:

```<code>LOAD DATA LOCAL INFILE forbidden in /path/to/my/application
</code>```

I read that the problem is related to the compilation of PHP and using mysqlnd. I am using PHP 5.3.8 and MySQL 5.5.15, but I haven't found a solution.

Additional information: until now the only help I've found was an open PHP bug:

答: uncomment 'mysqli.allow_local_infile = On' in php.ini.</p>

Body:
I am trying to use LOAD DATA INFILE to insert some records into a table. Unfortunately, it's not working.

Here are some details

If I use this instruction:

LOAD DATA INFILE 'file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);

It works using the MySQL client program and a PHP application. In this way it will look for the file in the Data Directory of my MySQL installation.

Now if I try to execute the instructions using the LOCAL option, it only works if I use the mysql client, but not from PHP:

LOAD DATA LOCAL INFILE 'path/to/file/file.txt'
INTO TABLE table_ex
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
(field1, field2, field3, field4);

Again.. it works with MySQL client but not from the PHP application... I get this error:

LOAD DATA LOCAL INFILE forbidden in /path/to/my/application

I read that the problem is related to the compilation of PHP and using mysqlnd. I am using PHP 5.3.8 and MySQL 5.5.15, but I haven't found a solution.

Additional information: until now the only help I've found was an open PHP bug:


问:
Only get interface fields of kotlin-object
I want to reduce an object down to its basic fields (comming from an interface):

override fun findBasicById(deliveryAddressId: Long): BasicDeliveryAddress? {
    val basicDeliveryAddress = findById(deliveryAddressId) as BasicDeliveryAddress? // returns a DeliveryAddress object
    return basicDeliveryAddress // Here I still get the full DeliveryAddress!
}
```

<p>However, <code>basicDeliveryAddress</code> still contains all fields from the class which implements the interface. How can I get rid of all fields, not declared in the interface (in this case the users-object)?</p>

<pre class="lang-kotlin prettyprint-override"><code>interface BasicDeliveryAddress {
    var street: String
    // some other fields
}
</code>```

data class DeliveryAddress (
        override var name: String,
        // override all other fields
) : BasicDeliveryAddress {
    var user: User? = null
}
```

答:
I don't know anything about SpringBoot, so I don't know if this resolves the root problem, but you can use an anonymous implementation that wraps it as a delegate to obscure the extra fields.</p>

```<code>fun BasicDeliveryAddress.toBasic() = object: BasicDeliveryAddress by this {}
</code>```

Body:
I want to reduce an object down to its basic fields (comming from an interface):

override fun findBasicById(deliveryAddressId: Long): BasicDeliveryAddress? {
    val basicDeliveryAddress = findById(deliveryAddressId) as BasicDeliveryAddress? // returns a DeliveryAddress object
    return basicDeliveryAddress // Here I still get the full DeliveryAddress!
}

However, basicDeliveryAddress still contains all fields from the class which implements the interface. How can I get rid of all fields, not declared in the interface (in this case the users-object)?

interface BasicDeliveryAddress {
    var street: String
    // some other fields
}

data class DeliveryAddress (
        override var name: String,
        // override all other fields
) : BasicDeliveryAddress {
    var user: User? = null
}

Body:
I don't know anything about SpringBoot, so I don't know if this resolves the root problem, but you can use an anonymous implementation that wraps it as a delegate to obscure the extra fields.

fun BasicDeliveryAddress.toBasic() = object: BasicDeliveryAddress by this {}


问:
Check if two arrays are equal or not ?? eg: {1,2,3,4,5} == {4,5,3,2,1}
Is there any problem with this approach ? or is it fine? we have to tell whether 2 arrays are equal
as in the digits in them and their frequencies must be same irrespective of their order.</p>

```<code>#include<bits/stdc++.h>
using namespace std;

main(){

int t,n,i,in;
vector<int> x;

cin>>t;
while(t--){

   unordered_map<int,int> a,b;
   cin>>n;

   for(i=0;i<n;i++){
       cin>>in;
       x.push_back(in);
       a[in]++;
   }

   for(i=0;i<n;i++){
       cin>>in;
       b[in]++;
   }

   for(i=0;i<n;i++){

       if(b.find(x[i]) == b.end()){
           cout<<"0"<<endl;
           goto x;
       }

       if(a[x[i]] != b[x[i]]){
           cout<<"0"<<endl;
           goto x;
       }
   }

   cout<<"1"<<endl;
   x : ;
   }
}
</code>```

答:
I don't know how new you are to C++, so here is a possible solution with a few explanations.

```<code>#include <map>
#include <vector>
#include <iostream>

//Avoid using namespace std as it can cause problems with conflicts of names
//and other sorts of nasty issues
using std::cout;
using std::cin;
using std::map;
using std::vector;
using std::endl;

//By using an ordered map you can more easily compare them
//The arguments are passed as const (you will never modify them)
//and also as reference (&) since you don't need to copy them.
bool CheckIfEqual (const vector<int> & V1, const vector<int> & V2) {
    //If the vectors don't have the same size you can just return false
    if (V1.size() != V2.size()) {
        return false;
    }
    map <int, size_t> M1;
    map <int, size_t> M2;
    //This type of loop goes through all elements of the vector and
    //either creates a corrisponding value in the map or, if it is
    //already present, it increases it to accout for repetitions.
    //Map is automatically sorted.
    for (auto & Elem : V1) {
        M1[Elem]++;
    }
    for (auto & Elem : V2) {
        M2[Elem]++;
    }
    return M1 == M2;
}

//The main function is used to provide some examples
int main () {
    //Expected output: true
    vector<int> V1 {1, 2, 3, 4, 5};
    vector<int> V2 {1, 2, 3, 4 ,5};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: true
    V1 = {1, 2, 3, 4, 5};
    V2 = {5, 3, 2, 1 ,4};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: false
    V1 =  {1, 2, 3};
    V2 =  {5, 3};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: false
    V1 =  {1, 2, 3, 4, 5};
    V2 = {5, 3, 2, 1 ,1};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: true
    V1 = {1, 5, 5, 4, 5};
    V2 = {5, 5, 5, 1 ,4};
    cout << CheckIfEqual(V1, V2) << endl;
}
</code>```

The output is

```<code>1
1
0
0
1
</code>```

Also please be very very careful when using goto, it is deprecated and only useful when you need to jump out of many nested loops all at once. A simple break would have worked better.

Body:
Is there any problem with this approach ? or is it fine? we have to tell whether 2 arrays are equal
as in the digits in them and their frequencies must be same irrespective of their order.

#include<bits/stdc++.h>
using namespace std;

main(){

int t,n,i,in;
vector<int> x;

cin>>t;
while(t--){

   unordered_map<int,int> a,b;
   cin>>n;

   for(i=0;i<n;i++){
       cin>>in;
       x.push_back(in);
       a[in]++;
   }

   for(i=0;i<n;i++){
       cin>>in;
       b[in]++;
   }

   for(i=0;i<n;i++){

       if(b.find(x[i]) == b.end()){
           cout<<"0"<<endl;
           goto x;
       }

       if(a[x[i]] != b[x[i]]){
           cout<<"0"<<endl;
           goto x;
       }
   }

   cout<<"1"<<endl;
   x : ;
   }
}

Body:
I don't know how new you are to C++, so here is a possible solution with a few explanations.

#include <map>
#include <vector>
#include <iostream>

//Avoid using namespace std as it can cause problems with conflicts of names
//and other sorts of nasty issues
using std::cout;
using std::cin;
using std::map;
using std::vector;
using std::endl;

//By using an ordered map you can more easily compare them
//The arguments are passed as const (you will never modify them)
//and also as reference (&) since you don't need to copy them.
bool CheckIfEqual (const vector<int> & V1, const vector<int> & V2) {
    //If the vectors don't have the same size you can just return false
    if (V1.size() != V2.size()) {
        return false;
    }
    map <int, size_t> M1;
    map <int, size_t> M2;
    //This type of loop goes through all elements of the vector and
    //either creates a corrisponding value in the map or, if it is
    //already present, it increases it to accout for repetitions.
    //Map is automatically sorted.
    for (auto & Elem : V1) {
        M1[Elem]++;
    }
    for (auto & Elem : V2) {
        M2[Elem]++;
    }
    return M1 == M2;
}

//The main function is used to provide some examples
int main () {
    //Expected output: true
    vector<int> V1 {1, 2, 3, 4, 5};
    vector<int> V2 {1, 2, 3, 4 ,5};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: true
    V1 = {1, 2, 3, 4, 5};
    V2 = {5, 3, 2, 1 ,4};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: false
    V1 =  {1, 2, 3};
    V2 =  {5, 3};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: false
    V1 =  {1, 2, 3, 4, 5};
    V2 = {5, 3, 2, 1 ,1};
    cout << CheckIfEqual(V1, V2) << endl;

    //Expected output: true
    V1 = {1, 5, 5, 4, 5};
    V2 = {5, 5, 5, 1 ,4};
    cout << CheckIfEqual(V1, V2) << endl;
}

The output is

1
1
0
0
1

Also please be very very careful when using goto, it is deprecated and only useful when you need to jump out of many nested loops all at once. A simple break would have worked better.


问:
Switching to First tab using Selenium Web Driver with Java
Using selenium web driver with java, i am trying to automate a functionality where i click on a link and it opens a new tab. I want to write a global method for first tab which when called in main test class switches to second tab. I have a separate method to do the assertions on second tab, after the assertions are complete. I want to write another global method which when called closed the second tab and switches back to the first one and resumes the tests on first window.

I have written the below methods and tests:

Main test:

```<code>@Test(enabled = true, dataProvider = "TestThis", description = "ClickThere", groups = {"hello" })

public void AttributeValidationOnHelpPage(TestData testData, String Id, String TableName) {

        menu.switch(Id);
        data = menu.clickData();
        data.selectNoneDateRange();
        TablePage = data.openTable(TableName);
        TablePage.clickAttTab();
        menuPage.clickOnHelpPage();

        // This method, when called will switch to second tab.
         helpPage = menu.switcToHelpPage();

        // After swicthing below is the assertions i want to do on the second tab.

        Assert.assertTrue(driver.getCurrentUrl().contains("Second page Url."));
        String actualValue = helpOnThisPage.getRefTableAttributes();
        Assert.assertEquals(actualValue, "Reference Table Attributes", "Reference Table Attributes Missing");

        // This method, will close the second tab and switches back to first tab and resumes the test.
        helpPage.switchBackTOMainApplication();

    }

    Global Method for Swicthing to second tab:

    public HelpPage switchToHelpPage() {
        String originalHandle = driver.getWindowHandle();
        try {
            TimeUnit.SECONDS.sleep(8);
        } catch (InterruptedException ignore) {
        }
        wait.until(ExpectedConditions.documentReady());
        wait.until(ExpectedConditions.isNotLoading());
        for (String handle : driver.getWindowHandles()) {
            if (!handle.equals(originalHandle)) {
                driver.switchTo().window(handle);
            }
        }
        return new HelpPage(driver);
    }

    Global Method for closing the second tab and swicthing back to first tab.

    public boolean switchBackTOMainApplication() {
        boolean isValid = false;
        String originalHandle = driver.getWindowHandle();
        for (String handle : driver.getWindowHandles()) {
            if (!handle.equals(originalHandle)) {
                driver.switchTo().window(handle);
            }
        }
        driver.close();
        driver.switchTo().window(originalHandle);
        return isValid;
    }
</code>```

Here is the problem i am facing. When "helpPage.switchBackTOMainApplication()" method is called its closing the first tab instead of switching to it. Is there any modification i need to do, which will close the second tab and continue the tests on first tab.

答:
The variable "originalHandle" in switchBackTOMainApplication() is having the handle for the second tab as the go back was performed with second tab as current window. The code s
hould be changed as :-</p>

```<code>public boolean switchBackTOMainApplication() {
    boolean isValid = false;
    String handleToClose = driver.getWindowHandle();
    String mainHandle;
    for (String handle : driver.getWindowHandles()) {
        if (!handle.equals(handleToClose)) {
            mainHandle=handle;
        }
    }
    driver.close();
    driver.switchTo().window(mainHandle);
    return isValid;
}
</code>```

Body:
Using selenium web driver with java, i am trying to automate a functionality where i click on a link and it opens a new tab. I want to write a global method for first tab which when called in main test class switches to second tab. I have a separate method to do the assertions on second tab, after the assertions are complete. I want to write another global method which when called closed the second tab and switches back to the first one and resumes the tests on first window.

I have written the below methods and tests:

Main test:

@Test(enabled = true, dataProvider = "TestThis", description = "ClickThere", groups = {"hello" })

public void AttributeValidationOnHelpPage(TestData testData, String Id, String TableName) {

        menu.switch(Id);
        data = menu.clickData();
        data.selectNoneDateRange();
        TablePage = data.openTable(TableName);
        TablePage.clickAttTab();
        menuPage.clickOnHelpPage();

        // This method, when called will switch to second tab.
         helpPage = menu.switcToHelpPage();

        // After swicthing below is the assertions i want to do on the second tab.

        Assert.assertTrue(driver.getCurrentUrl().contains("Second page Url."));
        String actualValue = helpOnThisPage.getRefTableAttributes();
        Assert.assertEquals(actualValue, "Reference Table Attributes", "Reference Table Attributes Missing");

        // This method, will close the second tab and switches back to first tab and resumes the test.
        helpPage.switchBackTOMainApplication();

    }

    Global Method for Swicthing to second tab:

    public HelpPage switchToHelpPage() {
        String originalHandle = driver.getWindowHandle();
        try {
            TimeUnit.SECONDS.sleep(8);
        } catch (InterruptedException ignore) {
        }
        wait.until(ExpectedConditions.documentReady());
        wait.until(ExpectedConditions.isNotLoading());
        for (String handle : driver.getWindowHandles()) {
            if (!handle.equals(originalHandle)) {
                driver.switchTo().window(handle);
            }
        }
        return new HelpPage(driver);
    }

    Global Method for closing the second tab and swicthing back to first tab.

    public boolean switchBackTOMainApplication() {
        boolean isValid = false;
        String originalHandle = driver.getWindowHandle();
        for (String handle : driver.getWindowHandles()) {
            if (!handle.equals(originalHandle)) {
                driver.switchTo().window(handle);
            }
        }
        driver.close();
        driver.switchTo().window(originalHandle);
        return isValid;
    }

Here is the problem i am facing. When "helpPage.switchBackTOMainApplication()" method is called its closing the first tab instead of switching to it. Is there any modification i need to do, which will close the second tab and continue the tests on first tab.

Body:
The variable "originalHandle" in switchBackTOMainApplication() is having the handle for the second tab as the go back was performed with second tab as current window. The code s
hould be changed as :-

public boolean switchBackTOMainApplication() {
    boolean isValid = false;
    String handleToClose = driver.getWindowHandle();
    String mainHandle;
    for (String handle : driver.getWindowHandles()) {
        if (!handle.equals(handleToClose)) {
            mainHandle=handle;
        }
    }
    driver.close();
    driver.switchTo().window(mainHandle);
    return isValid;
}


问:
How to override the parents padding while adding a border bottom
I am building a dropdown such that there is a line below the first option like:

This is what my HTML looks like right now:

               <svg aria-label="magnifier" class="icon_n7qd0i" fill="#8796A6" width="14" height="14" data-component-id="Icon">
                  <use xlink:href="#sprite_magnifier"></use>
               </svg>

            <input class="input_h63q7t-o_O-bodyM_1n94ib9-o_O-iconInput_1oxe2z4" id="input-5" type="text" maxlength="127" min="" max="" placeholder="Find a Field" value="">

 Select All multiselect

               <input id="toggle-input-0" class="checkbox_1u9fru1" type="checkbox">

 No

               <input id="toggle-input-2" class="checkbox_1u9fru1" type="checkbox">

```

Now I tried adding a border-bottom: 1px solid black on the div with fields class eg:  i.e each of the optios.

But because the parent adds a padding it is not able to match full widt.
How can I override it

答:
I think what you could do is add a negative margin to your child component like displayed below, but make the px === to the padding of the parent, then pad your child to adjust its content to the desired location.

 .parent{
   padding: 25px;
 }

.child{
  margin-left: -25px;
  margin-right: -25px;
}```

Body:
I am building a dropdown such that there is a line below the first option like:

This is what my HTML looks like right now:

               <svg aria-label="magnifier" class="icon_n7qd0i" fill="#8796A6" width="14" height="14" data-component-id="Icon">
                  <use xlink:href="#sprite_magnifier"></use>
               </svg>

            <input class="input_h63q7t-o_O-bodyM_1n94ib9-o_O-iconInput_1oxe2z4" id="input-5" type="text" maxlength="127" min="" max="" placeholder="Find a Field" value="">

 Select All multiselect

               <input id="toggle-input-0" class="checkbox_1u9fru1" type="checkbox">

 No

               <input id="toggle-input-2" class="checkbox_1u9fru1" type="checkbox">

Now I tried adding a border-bottom: 1px solid black on the div with fields class eg:  i.e each of the optios.

But because the parent adds a padding it is not able to match full widt.
How can I override it


问:
Export (but not save to) an audio file in PyDub?
The PyDub library, for me, is pretty much ideal for converting audio formats. I recently used  it to write a command line audio converter to convert about 200 audio files, and it saved me having to buy or look for an audio converter that would allow me to queue up songs and other audio files for conversion. But I quickly noticed that it replaced my audio files. Now, for me, this was ideal. This was great. But what if I didn't want PyDub to replace the audio files, but rather duplicate it but in a different format? I could just copy the files into the directory and convert them, but is there no way to do this from within PyDub? I looked into it and I couldn't find a way to do this, nor could I find a question on this, so maybe this isn't a very common thing to do.

Thanks!

答:
Hope this helps:</p>

```<code>    myaudio = AudioSegment.from_mp3("XXXXX/y.mp3")
    chunk_length_ms = 1000000  # pydub calculates in millisec
    chunks = make_chunks(myaudio, chunk_length_ms)  # Make chunks of one sec

    chunks.export('path where file needs to be exported' + chunks, format='mp3')
</code>```

Body:
Hope this helps:

    myaudio = AudioSegment.from_mp3("XXXXX/y.mp3")
    chunk_length_ms = 1000000  # pydub calculates in millisec
    chunks = make_chunks(myaudio, chunk_length_ms)  # Make chunks of one sec

    chunks.export('path where file needs to be exported' + chunks, format='mp3')


问:
Is there a way to get a complete string with spaces in c++?
So, i have a piece of code (c++) that gets the users name (in windows) and with the retrieved string the code creates respective directories...

```<code>BOOL DirectoryExists(const char* dirName) {

    TCHAR nameu[UNLEN + 1];
    DWORD size = UNLEN + 1;
    if (GetUserName((TCHAR*)nameu, &size))
    {
        TCHAR* t = nameu;
        wcout << t;
        //_getch();
        std::string str;
        std::wstring wStr = t;
        str = std::string(wStr.begin(), wStr.end());
        usr = str;

        dir[0] = (std::string("C:\\Users\\") + str + "\\Documents\\Folder").c_str();
    }

    DWORD attribs = ::GetFileAttributesA(dirName);
    if (attribs == INVALID_FILE_ATTRIBUTES) {
        return false;
    }
    return (attribs & FILE_ATTRIBUTE_DIRECTORY);
}
</code>```

here, the GetUserName() functions gets the user name and this piece of code works fine if the user name is just one straight string, but if the usr name had two parts split by space (eg: "example account"), then the code only takes the first part and leaves the 2nd part/name....

how do i solve this ?

答:
You have a lot of redundant and unnecessary string copies.

I'm fairly certain this is what you want to have:

```<code>wchar_t nameu[UNLEN + 1];
DWORD size = UNLEN + 1;
if (GetUserNameW(nameu, &size))
{
    dir[0] = L"C:\\Users\\" + std::wstring(nameu) + L"\\Documents\\Folder";
}
</code>```

Ideally dir[0] is of type wstring, not string.  You really should be using unicode everywhere when dealing with Windows APIs.  That will support users with unicode characters in their name properly.

Otherwise, if dir[0] is a string, then this:

```<code>char nameu[UNLEN + 1];
DWORD size = UNLEN + 1;
if (GetUserNameA(nameu, &size))
{
    dir[0] = "C:\\Users\\" + std::string(nameu) + "\\Documents\\Folder";
}
</code>```

And finally, hardcoded Documents at the end of the assumed user profile path is also the incorrect way to get the users default Documents folder.  There's lots of scenarios where users move their Documents folder elsewhere.

Use SHGetKnownFolderPath instead.  That might be what you really need after all. Just invoke SHGetKnownFolderPath(FOLDERID_Documents) and then append "Folder" to the end of it.

So this is what you really want:

```<code>wchar_t* path=nullptr;
SHGetKnownFolderPathW(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &path);
dir[0] = std::wstring(path) + L"\\Folder";
CoTaskMemFree(path);
</code>```

Or non-unicode:

```<code>char* path=nullptr;
SHGetKnownFolderPathA(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &path);
dir[0] = std::string(path) + "\\Folder";
CoTaskMemFree(path);
</code>```

Body:
So, i have a piece of code (c++) that gets the users name (in windows) and with the retrieved string the code creates respective directories...

BOOL DirectoryExists(const char* dirName) {

    TCHAR nameu[UNLEN + 1];
    DWORD size = UNLEN + 1;
    if (GetUserName((TCHAR*)nameu, &size))
    {
        TCHAR* t = nameu;
        wcout << t;
        //_getch();
        std::string str;
        std::wstring wStr = t;
        str = std::string(wStr.begin(), wStr.end());
        usr = str;

        dir[0] = (std::string("C:\\Users\\") + str + "\\Documents\\Folder").c_str();
    }

    DWORD attribs = ::GetFileAttributesA(dirName);
    if (attribs == INVALID_FILE_ATTRIBUTES) {
        return false;
    }
    return (attribs & FILE_ATTRIBUTE_DIRECTORY);
}

here, the GetUserName() functions gets the user name and this piece of code works fine if the user name is just one straight string, but if the usr name had two parts split by space (eg: "example account"), then the code only takes the first part and leaves the 2nd part/name....

how do i solve this ?

Body:
You have a lot of redundant and unnecessary string copies.

I'm fairly certain this is what you want to have:

wchar_t nameu[UNLEN + 1];
DWORD size = UNLEN + 1;
if (GetUserNameW(nameu, &size))
{
    dir[0] = L"C:\\Users\\" + std::wstring(nameu) + L"\\Documents\\Folder";
}

Ideally dir[0] is of type wstring, not string.  You really should be using unicode everywhere when dealing with Windows APIs.  That will support users with unicode characters in their name properly.

Otherwise, if dir[0] is a string, then this:

char nameu[UNLEN + 1];
DWORD size = UNLEN + 1;
if (GetUserNameA(nameu, &size))
{
    dir[0] = "C:\\Users\\" + std::string(nameu) + "\\Documents\\Folder";
}

And finally, hardcoded Documents at the end of the assumed user profile path is also the incorrect way to get the users default Documents folder.  There's lots of scenarios where users move their Documents folder elsewhere.

Use SHGetKnownFolderPath instead.  That might be what you really need after all. Just invoke SHGetKnownFolderPath(FOLDERID_Documents) and then append "Folder" to the end of it.

So this is what you really want:

wchar_t* path=nullptr;
SHGetKnownFolderPathW(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &path);
dir[0] = std::wstring(path) + L"\\Folder";
CoTaskMemFree(path);

Or non-unicode:

char* path=nullptr;
SHGetKnownFolderPathA(FOLDERID_Documents, KF_FLAG_DEFAULT, nullptr, &path);
dir[0] = std::string(path) + "\\Folder";
CoTaskMemFree(path);


问:
gdb how to print variable name along with variable value like "$number = variable-name = variable-value"
By default, using p variable-name will display $num = variable-value, $num is the value history, but it there a way to print the variable name along with the variable value like $num = variable-name = variable-value?

I want this since I use

```<code>define p
  set $i = 0
  while $i < $argc
    eval "print $arg%d", $i
    set $i = $i + 1
  end
end
</code>```

in my ~/.gdbinit, to redefine p command so I can use p var1 var2 var3... to print multiple variables at once, but the print command only output $num = variable-value, and I don't know what the exact variable is in the output, the other situation is when I print the value history using just p $num, it is not that readable, I don't know the exact variable name.

NOTE: the variable may be int/char/pointer/array/vector/...

答:
In a nutshell, we want to output

```<code>$num = variable-name = variable-value
</code>```

instead of

```<code>$num = variable-value
</code>```

As far as I can tell, gdb adds to the value history in only three places: the print command, the call command, and the history-append! Scheme function. Since my Scheme is rusty, we'll need to use the CLI or Python to run print and modify its output.

Using the CLI

```<code>define pp
  set $i = 0
  while $i < $argc
    eval "pipe print $arg%d | awk -v name='$arg%d' '{ if (NR == 1 && $2 == \"=\") { $2 = \"= \" name \" =\" }; print }'", $i, $i
    set $i++
  end
end
</code>```

Pipe is new in gdb 10.

That awk command is, after unescaping,

```<code>awk -v name='$arg%d' '{ if (NR == 1 && $2 == "=") { $2 = "= " name " =" }; print }'
</code>```

which changes the = (second field) in $num = variable-value to = variable-name = . If gdb's print command outputs more than one line, the NR == 1 in the awk command makes sure the substitution is only done on the first line.

Security note: gdb's pipe command appears to parse the shell_command into tokens and uses execve to run it, rather than passing it to an actual shell. This prevents some code injection attacks (if, for instance, the $arg%d in name='$arg%d' contains single quotes), but you should be careful of running any shell command comprised of text you haven't vetted.

Using Python

```<code>class PP(gdb.Command):
  """print value history index, name, and value of each arg"""

  def __init__(self):
    super(PP, self).__init__("pp", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)

  def invoke(self, argstr, from_tty):
    for arg in gdb.string_to_argv(argstr):
      line = gdb.execute("print " + arg, from_tty=False, to_string=True)
      line = line.replace("=", "= " + arg + " =", 1)
      gdb.write(line)

PP()
</code>```

Here, we're using a more sed-like approach, using string.replace.

Sample session:

```<code>(gdb) set args a b c
(gdb) start
Starting program: /home/mp/argprint a b c

Temporary breakpoint 2, main (argc=4, argv=0x7ffffffee278) at argprint.c:4
4               for(int i=0; i < argc; i++) {
(gdb) pp i argc argv argv[0]@argc
$1 = i = 0
$2 = argc = 4
$3 = argv = (char **) 0x7ffffffee278
$4 = argv[0]@argc = {0x7ffffffee49f "/home/mp/argprint", 0x7ffffffee4b1 "a", 0x7ffffffee4b3 "b", 0x7ffffffee4b5 "c"}
</code>```

Body:
By default, using p variable-name will display $num = variable-value, $num is the value history, but it there a way to print the variable name along with the variable value like $num = variable-name = variable-value?

I want this since I use

define p
  set $i = 0
  while $i < $argc
    eval "print $arg%d", $i
    set $i = $i + 1
  end
end

in my ~/.gdbinit, to redefine p command so I can use p var1 var2 var3... to print multiple variables at once, but the print command only output $num = variable-value, and I don't know what the exact variable is in the output, the other situation is when I print the value history using just p $num, it is not that readable, I don't know the exact variable name.

NOTE: the variable may be int/char/pointer/array/vector/...

Body:
In a nutshell, we want to output

$num = variable-name = variable-value

instead of

$num = variable-value

As far as I can tell, gdb adds to the value history in only three places: the print command, the call command, and the history-append! Scheme function. Since my Scheme is rusty, we'll need to use the CLI or Python to run print and modify its output.

Using the CLI

define pp
  set $i = 0
  while $i < $argc
    eval "pipe print $arg%d | awk -v name='$arg%d' '{ if (NR == 1 && $2 == \"=\") { $2 = \"= \" name \" =\" }; print }'", $i, $i
    set $i++
  end
end

Pipe is new in gdb 10.

That awk command is, after unescaping,

awk -v name='$arg%d' '{ if (NR == 1 && $2 == "=") { $2 = "= " name " =" }; print }'

which changes the = (second field) in $num = variable-value to = variable-name = . If gdb's print command outputs more than one line, the NR == 1 in the awk command makes sure the substitution is only done on the first line.

Security note: gdb's pipe command appears to parse the shell_command into tokens and uses execve to run it, rather than passing it to an actual shell. This prevents some code injection attacks (if, for instance, the $arg%d in name='$arg%d' contains single quotes), but you should be careful of running any shell command comprised of text you haven't vetted.

Using Python

class PP(gdb.Command):
  """print value history index, name, and value of each arg"""

  def __init__(self):
    super(PP, self).__init__("pp", gdb.COMMAND_DATA, gdb.COMPLETE_EXPRESSION)

  def invoke(self, argstr, from_tty):
    for arg in gdb.string_to_argv(argstr):
      line = gdb.execute("print " + arg, from_tty=False, to_string=True)
      line = line.replace("=", "= " + arg + " =", 1)
      gdb.write(line)

PP()

Here, we're using a more sed-like approach, using string.replace.

Sample session:

(gdb) set args a b c
(gdb) start
Starting program: /home/mp/argprint a b c

Temporary breakpoint 2, main (argc=4, argv=0x7ffffffee278) at argprint.c:4
4               for(int i=0; i < argc; i++) {
(gdb) pp i argc argv argv[0]@argc
$1 = i = 0
$2 = argc = 4
$3 = argv = (char **) 0x7ffffffee278
$4 = argv[0]@argc = {0x7ffffffee49f "/home/mp/argprint", 0x7ffffffee4b1 "a", 0x7ffffffee4b3 "b", 0x7ffffffee4b5 "c"}


问:
SQLite, Filling in NULL with TEXT value
I have a table with 2 columns and 9 Rows, FirstName and LastName.
All rows of FirstName Column IS NOT NULL, but 1 row of LastName is NULL.

How would I put a value into NULL?

This is the Code I have:

```<code>SELECT Emp1.FirstName Employee, Emp2.FirstName Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
</code>```

Which produces:

I have tried IFNULL, but it didn't seem to work.

```<code>SELECT Emp1.FirstName Employee, Emp2.FirstName Manager, IFNULL('No Manager')
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
</code>```

答:
The syntax for ISNULL is slightly different. Try this:

```<code>SELECT Emp1.FirstName Employee, IFNULL(Emp2.FirstName, 'No Manager') as Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;
</code>```

Please let me know if I can help you further.

Title: SQLite, Filling in NULL with TEXT value

Body:
I have a table with 2 columns and 9 Rows, FirstName and LastName.
All rows of FirstName Column IS NOT NULL, but 1 row of LastName is NULL.

How would I put a value into NULL?

This is the Code I have:

SELECT Emp1.FirstName Employee, Emp2.FirstName Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;

Which produces:

I have tried IFNULL, but it didn't seem to work.

SELECT Emp1.FirstName Employee, Emp2.FirstName Manager, IFNULL('No Manager')
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;

Body:
The syntax for ISNULL is slightly different. Try this:

SELECT Emp1.FirstName Employee, IFNULL(Emp2.FirstName, 'No Manager') as Manager
FROM Employee Emp1
LEFT JOIN Employee Emp2 ON Emp2.EmployeeID = Emp1.ReportsTo;

Please let me know if I can help you further.


问:
Why is the result type of a sum of two unsigned integers different in Clang and GCC
I am writing some low level code for my emulator which involves a lot of 16 and 8 bit unsigned integers. I enabled -Wconversion warning in my project and all warnings are considered as errors (-Werror).

Consider this code snippet:

#include <cstdint>

int main ()
{
    uint16_t a = 4;
    uint16_t b = 6;
    uint16_t c = a + b;
}
```

<p>Until GCC 9.3 with <code>-std=c++17 -Wconversion -Werror</code> as compilation flags, gives the following error:</p>

<pre class="lang-cpp prettyprint-override"><code><source>: In function 'int main()':
<source>:7:20: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
    7 |     uint16_t c = a + b;

      |                  ~~^~~
</code>```

But the same code does not give this error for GCC 10.1, and for any compiler version of Clang (Tested it until Clang 5.0.0). Link to compiler explorer.

So my questions are the following:

IMO, addition of two unsigned ints should not be implicitly converted to an int. Or is my assumption wrong?

Why Clang and GCC(until 9.3) produce different results? Does the standard stipulate any constraints on this operation or is it up to the compiler vendor to decide?

What changed in GCC 10.1? Why is this error not popping up for GCC 10.1?

答:
I ran into the same warning for doing a bit shift:

```<code>uint8_t left_shift(uint8_t a, uint8_t b) { return a << b; }
</code>```

Clang output with -Wconversion warnings enabled:

```<code><source>:10:53: warning: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Wimplicit-int-conversion]

uint8_t left_shift(uint8_t a, uint8_t b) { return a << b; }
                                           ~~~~~~ ~~^~~~
</code>```

But the assembly listing shows no sign of the phantom int promotion others are referring to in this thread.  Only byte widths are used throughout:

https://godbolt.org/z/eSVaQW

```<code>left_shift(unsigned char, unsigned char):
        push    rbp
        mov     rbp, rsp
        mov     byte ptr [rbp - 1], dil
        mov     byte ptr [rbp - 2], sil
        movzx   eax, byte ptr [rbp - 1]
        movzx   ecx, byte ptr [rbp - 2]
        shl     eax, cl
        movzx   eax, al
        pop     rbp
        ret
</code>```

Body:
I am writing some low level code for my emulator which involves a lot of 16 and 8 bit unsigned integers. I enabled -Wconversion warning in my project and all warnings are considered as errors (-Werror).

Consider this code snippet:

#include <cstdint>

int main ()
{
    uint16_t a = 4;
    uint16_t b = 6;
    uint16_t c = a + b;
}

Until GCC 9.3 with -std=c++17 -Wconversion -Werror as compilation flags, gives the following error:

<source>: In function 'int main()':
<source>:7:20: error: conversion from 'int' to 'uint16_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
    7 |     uint16_t c = a + b;

      |                  ~~^~~

But the same code does not give this error for GCC 10.1, and for any compiler version of Clang (Tested it until Clang 5.0.0). Link to compiler explorer.

So my questions are the following:

IMO, addition of two unsigned ints should not be implicitly converted to an int. Or is my assumption wrong?

Why Clang and GCC(until 9.3) produce different results? Does the standard stipulate any constraints on this operation or is it up to the compiler vendor to decide?

What changed in GCC 10.1? Why is this error not popping up for GCC 10.1?

Body:
I ran into the same warning for doing a bit shift:

uint8_t left_shift(uint8_t a, uint8_t b) { return a << b; }

Clang output with -Wconversion warnings enabled:

<source>:10:53: warning: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Wimplicit-int-conversion]

uint8_t left_shift(uint8_t a, uint8_t b) { return a << b; }
                                           ~~~~~~ ~~^~~~

But the assembly listing shows no sign of the phantom int promotion others are referring to in this thread.  Only byte widths are used throughout:

https://godbolt.org/z/eSVaQW

left_shift(unsigned char, unsigned char):
        push    rbp
        mov     rbp, rsp
        mov     byte ptr [rbp - 1], dil
        mov     byte ptr [rbp - 2], sil
        movzx   eax, byte ptr [rbp - 1]
        movzx   ecx, byte ptr [rbp - 2]
        shl     eax, cl
        movzx   eax, al
        pop     rbp
        ret