← Back to team overview

kicad-developers team mailing list archive

[PATCH 4/5] Use platform safe storage for pin numbers

 

The uint32_t type has exactly 32 bits, while the definition of "long" is up
to the compiler (although it happens to be 32 bits almost everywhere).
---
 eeschema/lib_pin.cpp | 4 ++--
 eeschema/lib_pin.h   | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/eeschema/lib_pin.cpp b/eeschema/lib_pin.cpp
index 6c67f8a..9b2c9ec 100644
--- a/eeschema/lib_pin.cpp
+++ b/eeschema/lib_pin.cpp
@@ -275,7 +275,7 @@ void LIB_PIN::SetNumber( const wxString& number )
     wxString tmp = ( number.IsEmpty() ) ? wxT( "~" ) : number;
 
     tmp.Replace( wxT( " " ), wxT( "_" ) );
-    long     oldNumber = m_number;
+    PinNum oldNumber = m_number;
     SetPinNumFromString( tmp );
 
     if( m_number != oldNumber )
@@ -1731,7 +1731,7 @@ void LIB_PIN::PinStringNum( wxString& aStringBuffer ) const
 }
 
 
-wxString LIB_PIN::PinStringNum( long aPinNum )
+wxString LIB_PIN::PinStringNum( PinNum aPinNum )
 {
     char ascii_buf[5];
 
diff --git a/eeschema/lib_pin.h b/eeschema/lib_pin.h
index 2e17264..72a84a1 100644
--- a/eeschema/lib_pin.h
+++ b/eeschema/lib_pin.h
@@ -84,6 +84,7 @@ enum DrawPinOrient {
     PIN_DOWN  = 'D'
 };
 
+typedef uint32_t PinNum;
 
 class LIB_PIN : public LIB_ITEM
 {
@@ -95,7 +96,7 @@ class LIB_PIN : public LIB_ITEM
     int      m_type;         ///< Electrical type of the pin.  See enum ElectricPinType.
     int      m_attributes;   ///< Set bit 0 to indicate pin is invisible.
     wxString m_name;
-    long     m_number;       ///< Pin number defined as 4 ASCII characters like "12", "anod",
+    PinNum   m_number;       ///< Pin number defined as 4 ASCII characters like "12", "anod",
                              ///< "G6", or "12".  It is stored as "12\0\0" and does not
                              ///< depend on endian type.
     int      m_numTextSize;
@@ -174,7 +175,7 @@ public:
      */
     void PinStringNum( wxString& aStringBuffer ) const;
 
-    long GetNumber() const { return m_number; }
+    PinNum GetNumber() const { return m_number; }
 
     wxString GetNumberString() const { return PinStringNum( m_number ); }
 
@@ -185,7 +186,7 @@ public:
      * @return aStringBuffer = the wxString to store the pin num as an
      *                         unicode string
      */
-    static wxString PinStringNum( long aPinNum );
+    static wxString PinStringNum( PinNum aPinNum );
 
     /**
      * Function SetPinNumFromString
-- 
2.1.4



Follow ups

References