Git Product home page Git Product logo

ctypesgen's People

Watchers

 avatar

ctypesgen's Issues

Structures change type from python readable!

Well I took a library called libdlo and produced a wrapper. Here is the code I 
ran...

>>> info = dlo_mode_t()
>>> info
<dlo.struct_dlo_mode_s object at 0xb6c4df80>
>>> info = dlo_get_mode(uid)
>>> info
<dlo.LP_struct_dlo_mode_s object at 0xb692d030>

Now the C code is...

dlo_mode_t    *mode_info;
info = dlo_get_mode(uid);

I am on Debian 7.0 Wheezy armhf Raspberry Pi, but this doesn't really have to 
do with my issue.

So it seems that the structures produced by ctypes is not compatible with those 
made by the wrapper!
I tried doing something like 
`LP_struct_dlo_mode_s = struct_dlo_mode_s`
Yet it didn't work, It's really hard to jerry-rig this stuff hahaha

Original issue reported on code.google.com by [email protected] on 30 Jun 2014 at 8:51

issue with Apple's "C" headers

What steps will reproduce the problem?
1. download and install grass dependence for osx [1]
2. checkout grass source code from SVN repository [2]
3. configure [3] & make (you'll need fftw (in /usr/local/) and tcltk.framework) 
[4]


What is the expected output? What do you see instead?

this is the ctypsgen  log errors during the build [5]
i tried to patch ctypesgen with this patch [6] 

What version of the product are you using? On what operating system?
i'm using the lates ctypsgen SVN revision on Mac OS X 10.6.3

Please provide any additional information below.

Recently GRASS GIS switched from swig to ctype+ctypsgen
unluky the build ends with error (see logs) 
looks like an issue with Apple's "C" headers being incompatible
with anything other than Apple's version of gcc. 

[1] Unix Compatibility Frameworks http://www.kyngchaos.com/software/frameworks 
[2] svn checkout https://svn.osgeo.org/grass/grass/trunk grass_trunk
[3] http://www.geofemengineering.it/data/grass_configure
[4] http://www.geofemengineering.it/data/ext_dep.7z
[5] http://www.geofemengineering.it/data/grass_lib_python_osx_log.txt
[6] http://www.geofemengineering.it/data/preprocessor.py

please contact me directly i will be happy to test patch
or to provide any kind of test and detailed log
i'm sure this fix will be usefull for all the Ctypsgen OSX users

thanks!

Original issue reported on code.google.com by [email protected] on 3 Jun 2010 at 7:07

Failed to parse real anonymous field in struct.

For code like this:

typedef struct SteamState_struct{
    char region;
    union{
        int R1;
        long int R4;
        float R2;
        double R3;
    };
} SteamState;

the union part will be discarded. If I give the union a name like 'rvalue', the 
union will be generated properly.

The same is true for anonymous enum inside struct.

ctypes Structure class has a special attribute for _anonymous_.


Original issue reported on code.google.com by [email protected] on 24 Jun 2011 at 2:46

LICENSE and README disagree on license

As of r141, the README file cites and links the 2-clause BSD license, but the 
LICENSE file contains the 3-clause. (It also lists copyright through 2008 only).

Assuming the 2-clause is the intended version, can LICENSE be replaced with the 
2-clause version?

Thanks.

Original issue reported on code.google.com by [email protected] on 2 Apr 2012 at 8:41

No errno support

As near as I can see, there's no support for the use_errno (or use_last_error 
for that matter) parameters.  It seems like a simple command line switch could 
add this in pretty easily, unless I'm missing some good reason not to.

If no one's got time to work on it, I could probably write the patch myself, 
but I wouldn't want to start doing so if there's a specific reason to not 
include it.

Original issue reported on code.google.com by [email protected] on 31 May 2013 at 12:23

Patch: add support for bool type and __attribute()

The following patch contains my (experimental) implementation for supporting 
the bool type and parsing of __attribute()s on function parameters.

This is my first patch ever for an open source project; feedback and some 
comments on the way of working would be most welcome.

Original issue reported on code.google.com by [email protected] on 17 Jul 2013 at 3:07

Attachments:

WindowsError does not exist in cygwin

In libraryloader.py, loaderclass["cygwin"] = WindowsLibraryLoader, but 
WindowsError is not defined in cygwin python. So any exception raised will be 
fatal if it is tried to be matched to WindowsError.

Original issue reported on code.google.com by [email protected] on 30 Sep 2013 at 4:25

POINTER/None work around for 64 bit platforms breaks pointer argument parsing

The following work around in preamble.py seems to break pointer argument 
parsing:

def POINTER(obj):
    p = ctypes.POINTER(obj)

    # Convert None to a real NULL pointer to work around bugs
    # in how ctypes handles None on 64-bit platforms
    if not isinstance(p.from_param, classmethod):
        def from_param(cls, x):
            if x is None:
                return cls()
            else:
                return x
        p.from_param = classmethod(from_param)

    return p

To reproduce the problem:

------ library libptr.so -----------

#include <stdio.h>
#include "ptr.h"

/*
gcc -m64 -fPIC -shared -o libptr.so ptr.c
/usr/local/bin/ctypesgen.py -o ptr.py ptr.h -l ptr
*/

struct private_s {
  int dummy;
};

void go(private_t *p) {
  if(p == 0)
    fprintf(stderr, "p is supposed to contain an address\n");
}

----- interface ptr.h -----------

#ifndef _PTR_H_
#define _PTR_H_

typedef struct private_s* private_t;
void go(private_t *p);

#endif

-------- test program ptrtest.py ----------

#!/usr/bin/env python
from ptr import *
if __name__ == "__main__":
  p = private_t()
  go(p)


Now running ptrtest.py I get: "p is supposed to contain an address"

but if I change the POINTER function to:
POINTER=ctypes.POINTER
everything works as expected.

This is tested on Ubuntu 11.10 x86_64 with Python 2.7.2+

Original issue reported on code.google.com by [email protected] on 10 Feb 2012 at 2:49

Feature request: option to treat certain pointers as opaque

It would be really nice to be able to ask ctypesgen to not recursively define 
certain kinds of pointers and simply treat them as opaque (void *).  For 
example, I keep Berkeley DB "DB *" pointers around.  The python bindings 
shouldn't need to care that it's a DB pointer as I'm never going to dereference 
it, and the fact that it _does_ care means it tries to write wrappers for the 
DB struct, which basically means it tries to write wrappers for all of Berkeley 
DB.  I don't want or need that, and it explodes the size (and complexity) of 
the generated file.

(Thanks for all your work though...great tool!)

Original issue reported on code.google.com by [email protected] on 5 Aug 2011 at 6:27

Ignore load_library failure at runtime, sometimes?

I have a library that I'm running on darwin and on linux.

On linux, the linker needs -ltermcap -lreadline, but on darwin it only
needs -lreadline, and there is no termcap.dylib.

I was hoping I could create a single mylib.py that could load readline. 
However, if I use -ltermcap -lreadline to build mylib.py, the module won't
load in python, because there's no -ltermcap, so load_library will raise an
ImportError.  However, on darwin this doesn't matter, because readline
doesn't need termcap, and I'm not referencing any symbols defined in
libtermcap.

In load_library, I tried commenting out the raise ImportError, and
returning None instead, but I'm not sure if that will cause other problems.

Original issue reported on code.google.com by [email protected] on 17 Dec 2008 at 11:16

Fix undefined global/name in ctypesgencore/printer_python/printer.py

Some generated files will fail to build because it hits the print_module method 
in ctypesgencore/printer_python/printer.py which looks like this:

    def print_module(self,module): 
        print >>self.file, 'from %s import *' % name

"name" isn't defined. I have attached a fix.

Original issue reported on code.google.com by kanzure on 11 Sep 2013 at 2:02

Attachments:

Feature request: support #pragma pack

First of all I'd like to say thanks for creating such a useful project. I am 
using it to generate a python ctypes interface for the GSSAPI library on Mac OS 
X and have found one place I need to manually edit the generated code - the 
header for the library contains:

#pragma pack(push,2)
... struct definitions ...
#pragma pack(pop)

and when ctypesgen creates the Structure classes for each struct it omits to 
add a _pack_=2 class attribute, so the alignment of the structs isn't right.
Editing the generated code fixes the problem but it would be great to have 
support for #pragma pack in ctypesgen.

Original issue reported on code.google.com by [email protected] on 13 Jan 2013 at 11:20

Add Python 3 support.

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 31 Oct 2013 at 7:04

PosixLibraryLoader Ignores "include" directives in /etc/ld.so.conf

PosixLibraryLoader._create_ld_so_cache expects each line of /etc/ld.so.conf to 
be a directory, when in fact those lines could be a directory or an "include" 
statement.

For instance my /etc/ld.so.conf on Ubuntu 12.04 Precise Pangolin looks like 
this:

    include /etc/ld.so.conf.d/*.conf

The result is that the code generated by ctypesgen is not able to find any 
libraries.

I was able to fix this by replacing this code:

        try: directories.extend([dir.strip() for dir in open('/etc/ld.so.conf')])
        except IOError: pass


With:

        ldconfs = ['/etc/ld.so.conf']
        for ldconf in ldconfs:
            try:
                for line in open(ldconf):
                    # parse inclusions
                    if line.startswith('include '):
                        pattern = line[8:].strip()
                        ldconfs.extend(glob.glob(pattern))
                    # strip comments
                    elif not line.startswith('#'):
                        directories.append(line.strip())
            except IOError:
                pass


Original issue reported on code.google.com by [email protected] on 28 Apr 2012 at 7:14

New C extension in Snow Leopard breaks C parsing

What steps will reproduce the problem?
1. Install Snow Leopard
2. Try to use ctypesgen against something that uses stdlib.h

What is the expected output? What do you see instead?
I should get no errors when creating the wrapper but instead I get a lot of 
Syntax errors.

The reason for this is as of Snow Leopard (OS X 10.6), there is a new C 
extension in the standard headers called blocks (http://bit.ly/8foNUD).  
Basically, this new extension allows you to create function pointers with a '^' 
character.  We need to either disable blocks functionality on OS X or add 
support for a function pointer using '^'.

Original issue reported on code.google.com by [email protected] on 21 Jan 2010 at 4:48

"Syntax error at '\n'" on a valid C macro.

Hi,

The C parser in ctypesgen (version 0.r125) gives a syntax error on some header 
files that GCC accepts. Example output:

    Error: /usr/include/libxml2/libxml/xmlstring.h:35: Syntax error at '\n'

This message comes from the ctypesgencore.parser.cgrammar.p_error function.

To reproduce, create a file named "test.h" containing:

    typedef unsigned char xmlChar;
    #define BAD_CAST (xmlChar *)

(This is extracted from xmlstring.h)
Then, run: ctypesgen.py -o test.py test.h

This error interrupts everything and test.py ends up with no content generated 
from header files. (It has no mention of xmlChar, BAD_CAST, or anything else.)

It seems that the parser sees this #define as a macro with a xmlChar parameter 
and a missing definition is missing, while it is really a parameter-less macro.

ctypesgencore.parser.yacc.Parser.parse does something like this:

    token = actions.get((statestack[-1], lookahead.type), None)

When the error is triggered, statestack[-1] is 293 and lookahead.type is 
PP_END_DEFINE. I guess that the fix should go somewhere in the cgrammar module, 
but I had no idea where to go from there.

Original issue reported on code.google.com by [email protected] on 3 Dec 2011 at 5:29

Enhancement: Support 'bool'

It would be most excellent if you would support 'bool' return and argument 
types, as ctypes has a c_bool: 
http://docs.python.org/library/ctypes.html#ctypes.c_bool.

Currently, in my library, I am losing my functions with this type:
Error: <input>:16: Syntax error at 'bool'

Original issue reported on code.google.com by [email protected] on 13 Jul 2011 at 3:49

library search path incomplete if generated script used as module

What steps will reproduce the problem?
1. generate a wrapper x.py for a libx.so used as part of a module
2. place libx.so in the same dir as x.py
3. in y.py in another dir, do 'import x'

What is the expected output? What do you see instead?
Ideally ctypesgen should generate x.py such that it checks x.py's own path and 
find libx.so.  What happens currently is that it searches only the cwd, which 
is y.py's dir and fails to find libx.so

What version of the product are you using? On what operating system?
latest version, on OS X

Please provide any additional information below.
The fix is to change libraryloader.py and add a search path 
'os.path.dirname(__file__)'

Original issue reported on code.google.com by yizhang84 on 1 Oct 2011 at 2:17

Unexpected "Warning: No libraries specified"

What steps will reproduce the problem?
--------------------------------------

1. Run ctypesgen without specifying -l option on command line
2.
3.

What is the expected output? What do you see instead?
-----------------------------------------------------

I wouldn't expect to see a warning. I am using ctypesgen to simply parse a C 
header file (with no libraries) and generate the appropriate Python ctypes 
code. I realise that ctypesgen is capable of much more, but I don't like it 
warning me about something that isn't a problem. Instead, I see "Warning: No 
libraries specified".

I realise this wont be your highest priority bug....!

What version of the product are you using? On what operating system?
--------------------------------------------------------------------

Latest. Ubuntu 12.04

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 31 Oct 2013 at 9:19

Include SVN revision number in ctypesgen version

I've uploaded it http://code.google.com/p/ctypesgen/ and manually added SVN 
revision to version number in setup.py This information can be updated 
semi-automatically. Feel free to copy the svn revision extraction function from 
http://bitbucket.org/techtonik/pypi-rietveld/src/tip/refresh.py

Original issue reported on code.google.com by [email protected] on 20 Sep 2010 at 1:24

-m option not working

What steps will reproduce the problem?
1. invoke with -m<module> option

What is the expected output? What do you see instead?
error happens

What version of the product are you using? On what operating system?
latest version, OS X

Please provide any additional information below.
the variable 'name' used in function print_module in the following file should 
obviously be 'module':
http://code.google.com/p/ctypesgen/source/browse/trunk/ctypesgencore/printer_pyt
hon/printer.py

Original issue reported on code.google.com by yizhang84 on 1 Oct 2011 at 8:04

enum types issue

Consider the following header:

---------------------
enum testenum_e {
  dummy0=0,
  dummy1,
};

struct teststruct_s {
  int dummy;
};
---------------------

This will give me the following object types in python:
enum_testenum_e
struct_teststruct_s
teststruct_s

But no "testenum_e" object type. To get "testenum_e" I need to typedef the 
enum. I think it would be an good idea if the above header would produce an 
"testenum_e = enum_testenum_e" without having to specify the typedef (btw 
ctypeslib behaves like this).

If someone could point me in the right direction I'll be happy to provide a 
patch.

This is tested on Ubuntu 11.10 x86_64 with Python 2.7.2+ and ctypesgen r137.



Original issue reported on code.google.com by [email protected] on 13 Feb 2012 at 1:43

Preserve #ifdef #else #endif

Some codes could be optionally included into the binary through #ifdef like 
directives. Currently there are not means to deal with that.

Especially when some data types are #ifdef to different size like 'double' and 
'long doubt'. These could cause segfault when used in struct.

If the #ifdef is turned into
  if USE_LONG_DOUBLE == 1:
     real = ctypes.longdouble
  else
     real = ctypes.double

Then USE_LONG_DOUBLE can be set in the python code before import the ctypes 
wrapped module.

Original issue reported on code.google.com by [email protected] on 23 May 2011 at 7:29

Tests failing to find correct printer (SVN r141)

What steps will reproduce the problem?
1.  svn checkout http://ctypesgen.googlecode.com/svn/trunk/ ctypesgen-read-only
2.  cd ctypesgen-read-only/test
3.  python testsuite.py

What is the expected output? What do you see instead?

Expect all tests to pass, instead see this error:

======================================================================
ERROR: Tests from structures.py
----------------------------------------------------------------------
Traceback (most recent call last):
  File "testsuite.py", line 219, in setUp
    self.module, output = ctypesgentest.test(header_str)
  File "/home/jlisee/projects/ctypesgen-read-only/test/ctypesgentest.py", line 40, in test
    ctypesgencore.printer.WrapperPrinter("temp.py",options,descriptions)
AttributeError: 'module' object has no attribute 'printer'

What version of the product are you using? On what operating system?

Ubuntu 10.04 32bit
Python 2.6.5
SVN r141

Please provide any additional information below.

I have attached a patch which fixes the error by using the python_printer 
instead of printer but I am unsure if this is the correct thing to do (Also 
this issue was introduced in r128).

Original issue reported on code.google.com by [email protected] on 2 Feb 2013 at 3:11

Attachments:

generated code doesn't work with python 2.6

What steps will reproduce the problem?

subversion ctypes bindings use ctypesgen. Unfortunately according to dev@ 
member ctypesgen doesn't work with python 2.6:

http://subversion.tigris.org/ds/viewMessage.do?
dsForumId=462&dsMessageId=1312346

What version of the product are you using? On what operating system?

svn rev 68

Original issue reported on code.google.com by [email protected] on 12 Mar 2009 at 11:12

Need RTLD_GLOBAL for linux?

I notice that for Darwin, libraryloader.py automatically adds RTLD_GLOBAL
to the dlopen flags.

On linux, I need RTLD_GLOBAL too though.  For example, this works for me:

import ctypes
ctypes.CDLL('/lib64/libtermcap.so.2', mode=ctypes.RTLD_GLOBAL |
ctypes.RTLD_NOW)
ctypes.CDLL('/usr/lib64/libreadline.so')

But this doesn't:

import ctypes

ctypes.CDLL('/lib64/libtermcap.so.2')
ctypes.CDLL('/usr/lib64/libreadline.so')

$ python t.py
Traceback (most recent call last):
  File "t.py", line 4, in ?
    ctypes.CDLL('/usr/lib64/libreadline.so')
  File "/usr/lib64/python2.4/site-packages/ctypes/__init__.py", line 340,
in __init__
    self._handle = _dlopen(self._name, mode)
OSError: /usr/lib64/libreadline.so: undefined symbol: BC

The same thing happens if I call dlopen directly from C, so it's not a
ctypes issue.

Original issue reported on code.google.com by [email protected] on 17 Dec 2008 at 7:36

Tests failing to find libc.so.6 and libm.so.6 on 64bit Ubuntu (SVN r147)

What steps will reproduce the problem?
1. Checkout the code
2. Go into the test directory
3. Run "./testsuite.py"

What is the expected output? What do you see instead?

I expect to see all tests pass instead I see 11 errors all like this:

======================================================================
ERROR: test_bad_args_string_not_number (__main__.MathTest)
Based on math_functions.py
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./testsuite.py", line 252, in setUp
    self.module, output = ctypesgentest.test(header_str, libraries=libraries, all_headers=True)
  File "/home/jlisee/projects/ctypesgen-read-only/test/ctypesgentest.py", line 52, in test
    module = __import__("temp")
  File "/home/jlisee/projects/ctypesgen-read-only/test/temp.py", line 598, in <module>
    _libs["libm.so.6"] = load_library("libm.so.6")
  File "/home/jlisee/projects/ctypesgen-read-only/test/temp.py", line 367, in load_library
    raise ImportError("%s not found." % libname)
ImportError: libm.so.6 not found

What version of the product are you using? On what operating system?

Ubuntu 12.04 64bit, SVN r147.


Please provide any additional information below.

I have attached a patch to fix the issue.  There are still 3 tests failing with 
"AttributeError: type object 'c_uint' has no attribute '_fields_'" in the 
generated "temp.py" file.

Original issue reported on code.google.com by [email protected] on 28 Feb 2013 at 3:02

Attachments:

Issue with _anonymous_ fields of non-struct types

What steps will reproduce the problem?
1. Checkout software
2. Go into test directory
3. Run "./testsuite.py"

What is the expected output? What do you see instead?

I expect all the tests to pass, instead I get 3 of these errors:

======================================================================
ERROR: test_structures (__main__.StructuresTest)
Tests from structures.py
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./testsuite.py", line 220, in setUp
    self.module, output = ctypesgentest.test(header_str)
  File "/home/jlisee/projects/ctypesgen-read-only/test/ctypesgentest.py", line 53, in test
    reload(module)  # import twice, this hack ensure that "temp" is force loaded (there *must* be a better way to do this)
  File "/home/jlisee/projects/ctypesgen-read-only/test/temp.py", line 622, in <module>
AttributeError: type object 'c_uint' has no attribute '_fields_


What version of the product are you using? On what operating system?

Python 2.7, Ubuntu 12.04 64 bit SVN r147 (with patch from Issue 39)

Please provide any additional information below.

The python docs say 
(http://docs.python.org/2/library/ctypes.html#ctypes.Structure._anonymous_):

Say "An optional sequence that lists the names of unnamed (anonymous) fields. 
_anonymous_ must be already defined when _fields_ is assigned, otherwise it 
will have no effect."

The generated code is:

# /usr/include/x86_64-linux-gnu/bits/waitstatus.h: 70
class struct_anon_21(Structure):
    pass

struct_anon_21.__slots__ = [
    '__w_termsig',
    '__w_coredump',
    '__w_retcode',
    'unnamed_1',
]

struct_anon_21._anonymous_ = [
    'unnamed_1',
]

struct_anon_21._fields_ = [
    ('__w_termsig', c_uint, 7),
    ('__w_coredump', c_uint, 1),
    ('__w_retcode', c_uint, 8),
    ('unnamed_1', c_int),
]

And the referenced source:

http://repo-genesis3.cbi.utsa.edu/crossref/ns-sli/usr/include/bits/waitstatus.h.
html

Original issue reported on code.google.com by [email protected] on 28 Feb 2013 at 3:32

Libdirs ignored on Windows (option -L)

I'm on Windows and called ctypesgen with two library search paths. The library 
to load was dependant on other DLLs in the same directory. The library search 
paths were ignored and I got errors. Here I have the code for two methods that 
I changed. I changed them in the generated file. But it seems the classes that 
I changed are always copied to the generated file. So I would suggest adjusting 
the source.

In the class _WindowsLibrary:
    def __init__(self, path):
        directory = os.path.dirname(path)
        file_ = os.path.basename(path)
        previous_directory = os.getcwd()
        os.chdir(directory)
        self.cdll = ctypes.cdll.LoadLibrary(file_)
        self.windll = ctypes.windll.LoadLibrary(file_)
        os.chdir(previous_directory)

In the class WindowsLibraryLoader:
    def getplatformpaths(self, libname):
        if os.path.sep not in libname:
            for name in self.name_formats:
                for directory in self.other_dirs:
                    path = name % libname
                    path = os.path.join(directory, path)
                    if os.path.exists(path):
                        yield path
                path = ctypes.util.find_library(name % libname)
                if path:
                    yield path

Original issue reported on code.google.com by [email protected] on 27 May 2012 at 11:16

Support casts in macros

Input:

#define GET_BAR(x) (((struct foo*)(x))->bar)

Expected output:

def GET_BAR(x):
    return (cast(x, POINTER(struct_foo)).contents.bar)

Actual output:

def GET_BAR(x):
    return (x.contents.bar)

For some reason ctypesgen ignores typecasts in macros. There's a comment in 
expressions.py on line 266 that says "there seems not to be any reasonable way 
to translate C typecasts to Python". I wrote that comment years ago, but I 
can't remember what the problem was.

Original issue reported on code.google.com by [email protected] on 11 Aug 2011 at 4:48

ctypesgen doesn't seem to support the example on the front page

The ctypesgen page says you can write:

 $ FLAGS = `apr-1-config --cppflags --includes`
 $ python wrap.py $FLAGS -llibapr-1.so $HOME/include/apr-1/apr*.h -o apr.py

On my computer, `apr-1-config --cppflags --includes` produces:

 -DDARWIN -DSIGPROCMASK_SETS_THREAD_MASK -no-cpp-precomp -
I/usr/local/apr/include/apr-1 

Ctypesgen doesn't support -D or -no-cpp-precomp and it would throw an error if 
anybody tried 
this example.

Solution: update the front page?

Original issue reported on code.google.com by [email protected] on 1 Jul 2008 at 4:01

Wrap 'c' with ord()

The c codes is like:

    #define CHR(ch1,ch2,ch3,ch4) (((ch1)<<24)|((ch2)<<16)|((ch3)<<8)|(ch4))
    #define DEFAULT_LANG            CHR('d','f','l','t')

The generated code:
    def CHR(ch1, ch2, ch3, ch4):
        return ((((ch1 << 24) | (ch2 << 16)) | (ch3 << 8)) | ch4)
    try:
        DEFAULT_LANG = (CHR ('d', 'f', 'l', 't'))
    except:
        pass

This of course doesn't work. If an ord() is used to surrounding characters, it 
will work ok.

        DEFAULT_LANG = (CHR (ord('d'), ord('f'), ord('l'), ord('t')))

Another way to solve this problem is to provide a mechanism to overrides 
generated code. Like user defined CHR() was used instead of autogen CHR():

    def _override_CHR(ch1, ch2, ch3, ch4):
        return ((((ord(ch1) << 24) | (ord(ch2) << 16)) | (ord(ch3) << 8)) | ord(ch4))



Original issue reported on code.google.com by [email protected] on 25 May 2011 at 9:31

ctypesgen fails if given an --includedir ( -I ) arg with spaces in the directory name

What steps will reproduce the problem?
1. On a setup with Visual Studio 2008
2. ctypesgen.py -a -l c:\windows\syswow64\kernel32.dll -o kernel32.py -I 
"c:\Program Files\Microsoft SDKs\Windows\v6.0A\Include" -I "
c:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include" "c:\Program 
Files\Microsoft SDKs\Windows\v6.0A\Include\windows.h"

What is the expected output? What do you see instead?
Expected: a kernel32.py module with many structs and function prototypes
What I see: 
ERROR: gcc -E: gcc: error: Files\Microsoft: No such file or directory
ERROR: gcc -E: gcc: error: SDKs\Windows\v6.0A\Include: No such file or directory
ERROR: gcc -E: gcc: error: Files: No such file or directory
ERROR: gcc -E: gcc: error: (x86)\Microsoft: No such file or directory
ERROR: gcc -E: gcc: error: Visual: No such file or directory
ERROR: gcc -E: gcc: error: Studio: No such file or directory
ERROR: gcc -E: gcc: error: 9.0\VC\include: No such file or directory

Afterwards, kernel32.py exists, but only with the basic template code.


What version of the product are you using? On what operating system?
svn checkout rev147

Please provide any additional information below.

Attached is a simple patch that fixes the issue.
The bug is passing the extra include dirs to the gcc command line without 
surrounding them in quotes.
Patch to preprocess.py simply surrounds the -I command line args passed to gcc 
withou quotes.

Original issue reported on code.google.com by [email protected] on 18 Apr 2013 at 10:38

Attachments:

LibraryLoader should prefer /lib64 for 64 bit apps, but not for 32 bit

If I run a module generated by ctypesgen on a 64-bit machine, the
PosixLibraryLoader inserts both /usr/lib and /lib64 (in that order) into
the load path.  However, Fedora distributes rpms that contain both 32-bit
libraries in /usr/lib and 64-bit libraries in /lib64.  As a result, when
running in a 64-bit python, ctypesgen will load the 32-bit library, which
causes the application to crash.  I actually get this error:

  File "/usr/lib/python2.4/site-packages/mylib.py", line 393, in ?
    _libs["readline"] = load_library("readline")
  File "/usr/lib/python2.4/site-packages/mylib.py", line 192, in load_library
    return self.load(path)
  File "/usr/lib/python2.4/site-packages/mylib.py", line 208, in load
    raise ImportError,e
ImportError: /usr/lib/libreadline.so.5.1: wrong ELF class: ELFCLASS32

Additionally, my machine uses a ld.so.conf that only contains the line
include /etc/ld.so.conf.d/*
so the attempt to load ld.so.conf doesn't work.

Instead, ctypesgen should try to detect whether it is running in a 64-bit
application, and set up the correct library paths accordingly.  Or, maybe
there could be a better way for me to set the library loading path at build
time or runtime.

Original issue reported on code.google.com by [email protected] on 17 Dec 2008 at 12:06

Support gcc __attribute__((__packed__))

This tool works like a charm, my only issue is that packed data structures does 
not get recognised.

The .c file:
struct __attribute__((__packed__)) {

Should become:

class struct_something(Structure):
    __pack__ = 1
    pass

In the .py file. Ctypes already have support for this. So i guess it's a simple 
matter of finding the attribute in the parser.

Original issue reported on code.google.com by [email protected] on 10 Oct 2013 at 1:26

OS X -framework and -F flags not handled

What steps will reproduce the problem?

1. ctypesgen [options] -framework SomeFramework

What is the expected output? What do you see instead?

ctypesgen.py: error: no such option: -f

What version of the product are you using? On what operating system?

SVN r125, OS X 10.x.

Please provide any additional information below.

OS X frameworks are another type of shared library, so they should be handled 
similar to libraries (dyld should handle them just like .dylib libraries).

Locating them is different.  -F/path/to/folder is used like -L to add to the 
search path (another option ctypesgen needs to handle).  DYLD_FRAMEWORK_PATH is 
the equivalent env var to DYLD_LIBRARY_PATH.  File names are in the form 
/path/to/framework/folder/SomeFramework.framework/SomeFramework, which is 
usually an alias to a specific version 
.../SomeFramework.framework/Versions/[version]/SomeFramework, no file extension.

Original issue reported on code.google.com by [email protected] on 28 Jan 2011 at 5:28

Feature request: Remove prefix from function names

This is a feature request.

The exported function names in some libraries are prefixed with the library 
name or an abbreviation of it. It would be nice, if there would be an option to 
strip off the prefix.

Example without the option: pyultimatelib.ultimate_create_something()
Example with the option set to "ultimate_": pyultimatelib.create_something()

What version of the product are you using? On what operating system?
latest version
Windows XP, SP2

Original issue reported on code.google.com by [email protected] on 2 May 2012 at 11:19

find_names_in_modules code incorrect in r121

names.union(dir(module)) will not actually alter names.

This function will always return the empty set.


Original issue reported on code.google.com by pmaupin on 14 Sep 2011 at 9:06

Revision 86 fixes 64-bit but breaks 32-bit

What steps will reproduce the problem?
1. Build subversion ctypes-python bindings
2. Run test cases. 

What is the expected output? What do you see instead?

It should run the test cases.

Instead I get segmentation fault.

What version of the product are you using? On what operating system?

trunk

Please provide any additional information below.

With revision 85 everything works file. I think r86 was an OS X specific hack. 
I am not able to find out what exactly is wrong with r86.

Original issue reported on code.google.com by [email protected] on 12 Aug 2010 at 8:49

Parsing errors with specific #define usage.

Hello. 
I am using ctypesgen to generate automatically some python bindings from c.


What steps will reproduce the problem?

This is a simplified version of what my problem is.
1. Consider the following definitions in file file.h.
   #define SIZE(x) sizeof(x)
   #define INT_SIZE SIZE(int)

2. I run:
   ctypesgen.py file.h -o file.py

3. I get an error about parsing the INT_SIZE definition.


What is the expected output? What do you see instead?

The expected output should be a file containing INT_SIZE definition.
The relevant output error is:
WARNING: Could not parse macro "#define INT_SIZE SIZE ( int )"
and the file.py does not contain INT_SIZE.


What version of the product are you using? On what operating system?

I am using the latest (r151) version.
Operating System: Linux Ubuntu 14.04 LTS x64


Please provide any additional information below.

The real problem is similar to the problem described above and occurs when 
file.h contains the following:
   #include <linux/types.h>
   #define CRIOGET         _IOWR('c', 101, __u32)
   //Some other definitions similar to CRIOGET using definitions from  
   //ioctl.h

And run: 
python ctypesgen.py --include=sys/ioctl.h file.h -o file.py

I get the same parsing error.

I used a custom file in python to define those definitions and use 
--insert-file option. But I wonder if this could work without this workaround.

Regards.
Tilemachos.

Original issue reported on code.google.com by [email protected] on 9 Mar 2015 at 1:45

Load symbols on demand?

Currently, the generated wrapper loads all the symbols from libxxx.so at 
import. It could consume a lot of memory at import even if we only use a few 
symbols from the library.

Would it be possible to import the symbols on demand.

Something like:

class ModuleName:
    def __init__(self):
        self.__symbols = {
            'sym1': None,
            'sym2': None,
        }
        self.__symbol_info = {
            'sym1': (libobj, retype, argtypes),
            'sym1': (libobj, retype, argtypes),
        }

    def __get__(self, name):
        if name not in self.__symbols:
            raise SomeError
        obj = self.__symbols[name]
        if obj is None:
            obj = self.load_symbols(name)
            self.__symbbols[name] = obj
        return obj

Maybe make the __symbols and __symbol_info into global variables.

Then we can:

    from ModuleName import ModuleName
    ModuleName.sym1(blah, blah)



Original issue reported on code.google.com by [email protected] on 21 May 2011 at 6:30

Provide CFUNCTYPE prototype name for function pointers defined in Structure

When wrapping a function pointer inside a structure, there is not corresponding 
CFUNCTYPE prototype type provided so we can initialize the prototype. Like

struct ui_interface {
    void (*post_warning)(const char *title,const char *statement,...);
    char *(*open_file)(const char *title, const char *defaultfile,
        const char *initial_filter);
}

ctypesgen correctly defined the types for post_warning and open_file as
functype like:

struct_ui_interface._fields_ = [
    ('post_warning', CFUNCTYPE(UNCHECKED(None), String, String)),
    ('open_file', CFUNCTYPE(UNCHECKED(String), String, String, String)),
]

But it should provide struct_ui_interface_post_warning_func and
struct_ui_interface_open_file_func so that we can create the CFUNCTYPE object
easily.

struct_ui_interface_post_warning_func =  CFUNCTYPE(UNCHECKED(None), String, 
String))

struct_ui_interface_open_file_func = CFUNCTYPE(UNCHECKED(String), String, 
String, String))




Original issue reported on code.google.com by [email protected] on 21 May 2011 at 12:42

String argument issue

I have a function which takes "String" as argument. If I create a string buffer 
using create_string_buffer and parse that as the argument to the function, it 
fails. The attached patch adds the conversion for c_char arrays which fixes 
this issue.

Please apply.



Original issue reported on code.google.com by [email protected] on 24 Apr 2012 at 11:50

Attachments:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.