Index: macholib/macholib/mach_o.py
===================================================================
--- macholib/macholib/mach_o.py	(revision 31)
+++ macholib/macholib/mach_o.py	(working copy)
@@ -108,7 +108,7 @@
     def __str__(self):
         return '%s.%s.%s' % (self.major, self.minor, self.rev)
 
-class mach_timestamp_helper(p_ulong):
+class mach_timestamp_helper(p_uint):
     def __str__(self):
         return time.ctime(self)
 
@@ -117,13 +117,13 @@
 
 class mach_header(Structure):
     _fields_ = (
-        ('magic', p_ulong),
+        ('magic', p_uint),
         ('cputype', cpu_type_t),
         ('cpusubtype', cpu_subtype_t),
-        ('filetype', p_ulong),
-        ('ncmds', p_ulong),
-        ('sizeofcmds', p_ulong),
-        ('flags', p_ulong),
+        ('filetype', p_uint),
+        ('ncmds', p_uint),
+        ('sizeofcmds', p_uint),
+        ('flags', p_uint),
     )
     def _describe(self):
         bit = 1L
@@ -145,12 +145,12 @@
         )
 
 class mach_header_64(mach_header):
-    _fields_ = mach_header._fields_ + (('reserved', p_ulong),)
+    _fields_ = mach_header._fields_ + (('reserved', p_uint),)
 
 class load_command(Structure):
     _fields_ = (
-        ('cmd', p_ulong),
-        ('cmdsize', p_ulong),
+        ('cmd', p_uint),
+        ('cmdsize', p_uint),
     )
 
 LC_REQ_DYLD = 0x80000000L
@@ -178,7 +178,7 @@
 LC_DYLD_INFO_ONLY = 0x22 | LC_REQ_DYLD
 
 # this is really a union.. but whatever
-class lc_str(p_ulong):
+class lc_str(p_uint):
     pass
 
 p_str16 = pypackable('p_str16', str, '16s')
@@ -187,14 +187,14 @@
 class segment_command(Structure):
     _fields_ = (
         ('segname', p_str16),
-        ('vmaddr', p_ulong),
-        ('vmsize', p_ulong),
-        ('fileoff', p_ulong),
-        ('filesize', p_ulong),
+        ('vmaddr', p_uint),
+        ('vmsize', p_uint),
+        ('fileoff', p_uint),
+        ('filesize', p_uint),
         ('maxprot', vm_prot_t),
         ('initprot', vm_prot_t),
-        ('nsects', p_ulong), # read the section structures ?
-        ('flags', p_ulong),
+        ('nsects', p_uint), # read the section structures ?
+        ('flags', p_uint),
     )
 
 class segment_command_64(Structure):
@@ -206,8 +206,8 @@
         ('filesize', p_ulonglong),
         ('maxprot', vm_prot_t),
         ('initprot', vm_prot_t),
-        ('nsects', p_ulong), # read the section structures ?
-        ('flags', p_ulong),
+        ('nsects', p_uint), # read the section structures ?
+        ('flags', p_uint),
     )
 
 SG_HIGHVM = 0x1
@@ -218,15 +218,15 @@
     _fields_ = (
         ('sectname', p_str16),
         ('segname', p_str16),
-        ('addr', p_ulong),
-        ('size', p_ulong),
-        ('offset', p_ulong),
-        ('align', p_ulong),
-        ('reloff', p_ulong),
-        ('nreloc', p_ulong),
-        ('flags', p_ulong),
-        ('reserved1', p_ulong),
-        ('reserved2', p_ulong),
+        ('addr', p_uint),
+        ('size', p_uint),
+        ('offset', p_uint),
+        ('align', p_uint),
+        ('reloff', p_uint),
+        ('nreloc', p_uint),
+        ('flags', p_uint),
+        ('reserved1', p_uint),
+        ('reserved2', p_uint),
     )
 
 class section_64(Structure):
@@ -235,14 +235,14 @@
         ('segname', p_str16),
         ('addr', p_ulonglong),
         ('size', p_ulonglong),
-        ('offset', p_ulong),
-        ('align', p_ulong),
-        ('reloff', p_ulong),
-        ('nreloc', p_ulong),
-        ('flags', p_ulong),
-        ('reserved1', p_ulong),
-        ('reserved2', p_ulong),
-        ('reserved3', p_ulong),
+        ('offset', p_uint),
+        ('align', p_uint),
+        ('reloff', p_uint),
+        ('nreloc', p_uint),
+        ('flags', p_uint),
+        ('reserved1', p_uint),
+        ('reserved2', p_uint),
+        ('reserved3', p_uint),
     )
 
 SECTION_TYPE = 0xffL
@@ -300,7 +300,7 @@
     _fields_ = (
         ('name', lc_str),
         ('minor_version', mach_version_helper),
-        ('header_addr', p_ulong),
+        ('header_addr', p_uint),
     )
 
 class fvmlib_command(Structure):
@@ -341,8 +341,8 @@
 class prebound_dylib_command(Structure):
     _fields_ = (
         ('name', lc_str),
-        ('nmodules', p_ulong),
-        ('linked_modules', p_ulong),
+        ('nmodules', p_uint),
+        ('linked_modules', lc_str),
     )
 
 class dylinker_command(Structure):
@@ -356,14 +356,14 @@
 
 class routines_command(Structure):
     _fields_ = (
-        ('init_address', p_ulong),
-        ('init_module', p_ulong),
-        ('reserved1', p_ulong),
-        ('reserved2', p_ulong),
-        ('reserved3', p_ulong),
-        ('reserved4', p_ulong),
-        ('reserved5', p_ulong),
-        ('reserved6', p_ulong),
+        ('init_address', p_uint),
+        ('init_module', p_uint),
+        ('reserved1', p_uint),
+        ('reserved2', p_uint),
+        ('reserved3', p_uint),
+        ('reserved4', p_uint),
+        ('reserved5', p_uint),
+        ('reserved6', p_uint),
     )
 
 class routines_command_64(Structure):
@@ -380,32 +380,32 @@
 
 class symtab_command(Structure):
     _fields_ = (
-        ('symoff', p_ulong),
-        ('nsyms', p_ulong),
-        ('stroff', p_ulong),
-        ('strsize', p_ulong),
+        ('symoff', p_uint),
+        ('nsyms', p_uint),
+        ('stroff', p_uint),
+        ('strsize', p_uint),
     )
 
 class dysymtab_command(Structure):
     _fields_ = (
-        ('ilocalsym', p_ulong),
-        ('nlocalsym', p_ulong),
-        ('iextdefsym', p_ulong),
-        ('nextdefsym', p_ulong),
-        ('iundefsym', p_ulong),
-        ('nundefsym', p_ulong),
-        ('tocoff', p_ulong),
-        ('ntoc', p_ulong),
-        ('modtaboff', p_ulong),
-        ('nmodtab', p_ulong),
-        ('extrefsymoff', p_ulong),
-        ('nextrefsyms', p_ulong),
-        ('indirectsymoff', p_ulong),
-        ('nindirectsyms', p_ulong),
-        ('extreloff', p_ulong),
-        ('nextrel', p_ulong),
-        ('locreloff', p_ulong),
-        ('nlocrel', p_ulong),
+        ('ilocalsym', p_uint),
+        ('nlocalsym', p_uint),
+        ('iextdefsym', p_uint),
+        ('nextdefsym', p_uint),
+        ('iundefsym', p_uint),
+        ('nundefsym', p_uint),
+        ('tocoff', p_uint),
+        ('ntoc', p_uint),
+        ('modtaboff', p_uint),
+        ('nmodtab', p_uint),
+        ('extrefsymoff', p_uint),
+        ('nextrefsyms', p_uint),
+        ('indirectsymoff', p_uint),
+        ('nindirectsyms', p_uint),
+        ('extreloff', p_uint),
+        ('nextrel', p_uint),
+        ('locreloff', p_uint),
+        ('nlocrel', p_uint),
     )
 
 INDIRECT_SYMBOL_LOCAL = 0x80000000L
@@ -413,75 +413,75 @@
 
 class dylib_table_of_contents(Structure):
     _fields_ = (
-        ('symbol_index', p_ulong),
-        ('module_index', p_ulong),
+        ('symbol_index', p_uint),
+        ('module_index', p_uint),
     )
 
 class dylib_module(Structure):
     _fields_ = (
-        ('module_name', p_ulong),
-        ('iextdefsym', p_ulong),
-        ('nextdefsym', p_ulong),
-        ('irefsym', p_ulong),
-        ('nrefsym', p_ulong),
-        ('ilocalsym', p_ulong),
-        ('nlocalsym', p_ulong),
-        ('iextrel', p_ulong),
-        ('nextrel', p_ulong),
-        ('iinit_iterm', p_ulong),
-        ('ninit_nterm', p_ulong),
-        ('objc_module_info_addr', p_ulong),
-        ('objc_module_info_size', p_ulong),
+        ('module_name', p_uint),
+        ('iextdefsym', p_uint),
+        ('nextdefsym', p_uint),
+        ('irefsym', p_uint),
+        ('nrefsym', p_uint),
+        ('ilocalsym', p_uint),
+        ('nlocalsym', p_uint),
+        ('iextrel', p_uint),
+        ('nextrel', p_uint),
+        ('iinit_iterm', p_uint),
+        ('ninit_nterm', p_uint),
+        ('objc_module_info_addr', p_uint),
+        ('objc_module_info_size', p_uint),
     )
 
 class dylib_module_64(Structure):
     _fields_ = (
-        ('module_name', p_ulong),
-        ('iextdefsym', p_ulong),
-        ('nextdefsym', p_ulong),
-        ('irefsym', p_ulong),
-        ('nrefsym', p_ulong),
-        ('ilocalsym', p_ulong),
-        ('nlocalsym', p_ulong),
-        ('iextrel', p_ulong),
-        ('nextrel', p_ulong),
-        ('iinit_iterm', p_ulong),
-        ('ninit_nterm', p_ulong),
-        ('objc_module_info_size', p_ulong),
+        ('module_name', p_uint),
+        ('iextdefsym', p_uint),
+        ('nextdefsym', p_uint),
+        ('irefsym', p_uint),
+        ('nrefsym', p_uint),
+        ('ilocalsym', p_uint),
+        ('nlocalsym', p_uint),
+        ('iextrel', p_uint),
+        ('nextrel', p_uint),
+        ('iinit_iterm', p_uint),
+        ('ninit_nterm', p_uint),
+        ('objc_module_info_size', p_uint),
         ('objc_module_info_addr', p_ulonglong),
     )
 
 class dylib_reference(Structure):
     _fields_ = (
         # XXX - ick, fix
-        ('isym_flags', p_ulong),
+        ('isym_flags', p_uint),
         #('isym', p_ubyte * 3),
         #('flags', p_ubyte),
     )
 
 class twolevel_hints_command(Structure):
     _fields_ = (
-        ('offset', p_ulong),
-        ('nhints', p_ulong),
+        ('offset', p_uint),
+        ('nhints', p_uint),
     )
 
 class twolevel_hint(Structure):
     _fields_ = (
       # XXX - ick, fix
-      ('isub_image_itoc', p_ulong),
+      ('isub_image_itoc', p_uint),
       #('isub_image', p_ubyte),
       #('itoc', p_ubyte * 3),
   )
 
 class prebind_cksum_command(Structure):
     _fields_ = (
-        ('cksum', p_ulong),
+        ('cksum', p_uint),
     )
 
 class symseg_command(Structure):
     _fields_ = (
-        ('offset', p_ulong),
-        ('size', p_ulong),
+        ('offset', p_uint),
+        ('size', p_uint),
     )
 
 class ident_command(Structure):
@@ -491,7 +491,7 @@
 class fvmfile_command(Structure):
     _fields_ = (
         ('name', lc_str),
-        ('header_addr', p_ulong),
+        ('header_addr', p_uint),
     )
 
 class uuid_command (Structure):
@@ -506,8 +506,8 @@
 
 class linkedit_data_command (Structure):
     _fields_ = (
-        ('dataoff',   p_ulong),
-        ('datassize', p_ulong),
+        ('dataoff',   p_uint),
+        ('datassize', p_uint),
     )
 
 
@@ -548,13 +548,17 @@
     LC_DYLD_INFO_ONLY:  dylib_command,
 }
 
+#this is another union.
+class n_un(p_int):
+    pass
+
 class nlist(Structure):
     _fields_ = (
-        ('n_un', p_long),
+        ('n_un', n_un),
         ('n_type', p_ubyte),
         ('n_sect', p_ubyte),
         ('n_desc', p_short),
-        ('n_value', p_ulong),
+        ('n_value', p_uint),
     )
 
 N_STAB = 0xe0
@@ -600,15 +604,15 @@
 FAT_MAGIC = 0xcafebabeL
 class fat_header(Structure):
     _fields_ = (
-        ('magic', p_ulong),
-        ('nfat_arch', p_ulong),
+        ('magic', p_uint),
+        ('nfat_arch', p_uint),
     )
 
 class fat_arch(Structure):
     _fields_ = (
         ('cputype', cpu_type_t),
         ('cpusubtype', cpu_subtype_t),
-        ('offset', p_ulong),
-        ('size', p_ulong),
-        ('align', p_ulong),
+        ('offset', p_uint),
+        ('size', p_uint),
+        ('align', p_uint),
     )
Index: macholib/macholib/MachO.py
===================================================================
--- macholib/macholib/MachO.py	(revision 31)
+++ macholib/macholib/MachO.py	(working copy)
@@ -282,7 +282,8 @@
     def rewriteDataForCommand(self, idx, data):
         lc, cmd, old_data = self.commands[idx]
         hdrsize = sizeof(lc.__class__) + sizeof(cmd.__class__)
-        data = data + ('\x00' * (4 - (len(data) % 4)))
+        align = struct.calcsize('L')
+        data = data + ('\x00' * (align - (len(data) % align)))
         newsize = hdrsize + len(data)
         self.commands[idx] = (lc, cmd, data)
         self.changedHeaderSizeBy(newsize - lc.cmdsize)
