Skip to content

undefined symbol: iptc_init (libiptc compatibilitly) #5

Closed

Description

@freddy36

If libip4tc doesn't exist but libiptc does the module failes to load with the following error:

Traceback (most recent call last):                                                                                                                                                                                                          
  File "comment.py", line 3, in <module>                                                                                                                                                                                                    
    import iptc                                                                                                                                                                                                                             
  File "/usr/lib/pymodules/python2.6/iptc/__init__.py", line 110, in <module>                                                                                                                                                               
    class iptc(object):                                                                                                                                                                                                                     
  File "/usr/lib/pymodules/python2.6/iptc/__init__.py", line 112, in iptc                                                                                                                                                                   
    iptc_init = _libiptc.iptc_init                                                                                                                                                                                                          
  File "/usr/lib/python2.6/ctypes/__init__.py", line 366, in __getattr__                                                                                                                                                                    
    func = self.__getitem__(name)                                                                                                                                                                                                           
  File "/usr/lib/python2.6/ctypes/__init__.py", line 371, in __getitem__                                                                                                                                                                    
    func = self._FuncPtr((name_or_ordinal, self))                                                                                                                                                                                           
AttributeError: python: undefined symbol: iptc_init

Seems like ctypes.CDLL() doesn't throw an exception in case the lib couldn't be loaded.

Follwoing change should fix the problem:

diff --git a/iptc/__init__.py b/iptc/__init__.py
index 400111c..3d25f29 100644
--- a/iptc/__init__.py
+++ b/iptc/__init__.py
@@ -102,10 +102,15 @@ class ipt_entry_match(xt_entry_match):

 ipt_align = xt_align

-try:
-    _libiptc = ct.CDLL(ctypes.util.find_library("ip4tc"), use_errno = True)
-except:
-    _libiptc = ct.CDLL(ctypes.util.find_library("iptc"), use_errno = True)
+_libiptc_file = ctypes.util.find_library("ip4tc")
+
+if not _libiptc_file:
+    _libiptc_file = ctypes.util.find_library("iptc")
+
+if not _libiptc_file:
+    raise IPTCError("error: libiptc/libip4tc not found")
+
+_libiptc = ct.CDLL(_libiptc_file, use_errno = True)

 class iptc(object):
     """This class contains all libiptc API calls."""

Activity

  1. ldx commented on May 8, 2012

    @ldx
    Owner

    Very good, thanks for the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions