I have a bunch of Cython files which cimport others in a complex dependency order. And the problem is, some cimport will make this error during compiling: 'Blahblah' redeclarared
This issue is solved in C the very simple way with include guard:
#ifndef XXX_HH
#define XXX_HH
...
#endif
I can't find such include-guard similar feature in Cython, any work-around, generically? (not ad-hoc)
Not really an answer to make a #ifndef-similar, but just to share the issue, it's rather weird. The problem was due to cimport-ing a forward declaration of a class itself.
File 1 common.pxd
cdef public struct myclass
cdef public cppclass output1:
myclass* value
cdef public cppclass output2:
float value
# Many more definitions...
File 2 myclass.pxd
# Due to common.pxd has so many definitions,
# this asterisk was used to cimport
# ERROR! IT INCLUDES THE FORWARD DECLARATION OF myclass
from common cimport *
# OK HERE: INCLUDE 1 BY 1
from common cimport output1,output2,...
cdef public cppclass myclass:
pass
Related
I tried to create a Class and the constructor always gave me a Syntax Error about the *new method then I just copied the Example from the documentation:
MyClass {
// this is a normal constructor method
*new { | arga, argb, argc |
^super.new.init(arga, argb, argc)
}
init { | arga, argb, argc |
// do initiation here
}
}
and still got this:
ERROR: syntax error, unexpected '*', expecting '}'
in interpreted text
line 6 char 5:
*new { | arga, argb, argc |
^
^super.new.init(arga, argb, argc)
-----------------------------------
ERROR: Command line parse failed
-> nil
From my own class i get the same error concerning the constructor. Where am I wrong?
If you check out the Writing Classes helpfile, there's a bit at the top that's easy to miss about where to save your classes.
https://depts.washington.edu/dxscdoc/Help/Guides/WritingClasses.html
NOTE: Class definitions are statically compiled when you launch
SuperCollider or "recompile the library." This means that class
definitions must be saved into a file with the extension .sc, in a
disk location where SuperCollider looks for classes. Saving into the
main class library (SCClassLibrary) is generally not recommended. It's
preferable to use either the user or system extension directories.
Platform.userExtensionDir; // Extensions available only to your user account
Platform.systemExtensionDir; // Extensions available to all users on the machine
It is not possible to enter a class definition into an interpreter
window and execute it.
The the Save As Extension option under the file menu. Then recompile the interpretter and try using your class.
I am using doxygen + breathe + Sphinx to document C source code.
In my conf.py I have set:
breathe_show_define_initializer = True
and
html_theme = 'sphinx_rtd_theme'
In my C source code I have defines such as:
#define FOO 12U //!< example #define
In the xml generated from doxygen, I see:
<name>FOO</name>
<initializer>12U</initializer>
<briefdescription>
<para>example #define </para>
</briefdescription>
So far so good!
The problem is the output from Sphinx is missing white space between the name and the initializer. i.e. as shown, no space between FOO and 12U:
FOO12U
example #define
I tried using both:
.. doxygendefine:: FOO
and I tried the group which has a number of defines:
.. doxygengroup:: MY_DEFINES_GROUP
If I change html_theme = 'alabaster'
Then there is a space between FOO and 12U
Any thoughts - am I missing a configuration?
I found this question via Google since I ran into the same issue. I'm posting my solution here which I hacked up and it seems to work for my case in the hopes of saving someone else time. My solution was to insert a "no break space" after each name of the define (but before the value).
Create a custom css: under _static/custom-signame.css (which is where I store my other custom css files)
The contents of the file are:
/* add a space to fix Breathe+Sphinx rtd_theme with
breathe_show_define_initializer */
.sig-name::after {
content: "\00a0";
}
Make sure that conf.py is updated to include the new custom css created in step 2:
html_static_path = ['_static']
html_css_files = [
'custom-table.css',
'custom-signame.css',
]
When I really should call refresh function manually in module Curses in Ruby? I think that it's unclear in the docs.
Thanks in advance.
The refresh method points out to the external function refresh():
static VALUE
curses_refresh(VALUE obj)
{
curses_stdscr();
refresh();
return Qnil;
}
And you can see the documentation of that refresh() method in the curs_refresh manual:
The refresh and wrefresh routines (or wnoutrefresh and doupdate) must
be called to get actual output to the terminal, as other routines mere‐
ly manipulate data structures. The routine wrefresh copies the named
window to the physical terminal screen, taking into account what is al‐
ready there to do optimizations. The refresh routine is the same, us‐
ing stdscr as the default window. Unless leaveok has been enabled, the
physical cursor of the terminal is left at the location of the cursor
for that window.
In modern Linux you can see the declaration of that function or macros in /usr/include/ncurses.h or /usr/include/curses.h. Example:
extern NCURSES_EXPORT(int) refresh (void); /* generated */
#define refresh() wrefresh(stdscr)
And this is the part of Ruby's curses.c that refers to the header files:
#if defined(HAVE_NCURSES_H)
# include <ncurses.h>
#elif defined(HAVE_NCURSES_CURSES_H)
# include <ncurses/curses.h>
#elif defined(HAVE_CURSES_COLR_CURSES_H)
# ifdef HAVE_STDARG_PROTOTYPES
# include <stdarg.h>
# else
# include <varargs.h>
# endif
# include <curses_colr/curses.h>
#else
# include <curses.h>
...
# endif
#endif
I'm trying to dynamically call functions of external library on Linux/Unix system.
I have some success with dl library but only when primitive C types are used and arguments are passed by value:
require 'dl/import'
module LibM
extend DL::Importer
dlload 'libm.so'
extern 'double sin(double)'
end
puts LibM.sin(3.14159265358979323846 / 2) # 1.0
However how can be interfaced functions using more complex types like C structs or if arguments are pointers where results of the call are stored ?
module LibX11
extend DL::Importer
dlload 'libX11.so.6'
extern 'Display *XkbOpenDisplay (char *display_name, int *event_rtrn, int *error_rtrn, int *major_in_out, int *minor_in_out, int *reason_rtrn)'
end
Display is a big struct, at event_rtrn is stored some result etc.
I've taken a look at DL::CStructBuilder and it looks can do the job, but as the documentation is very brief and no working examples found I'm lost here how it has to be properly used.
I have to add standard Ruby 1.9 modules have to be used (if possible) as installation of additional gems on the target machine is prohibited.
I am facing with interfacing with C libraries in this period (I am writing a wrapper for libgtop), and I choosed to use ffi, which is quite well documented (although the documentation sometimes is a bit outdated) and above all its mailing list is full of people who give you an helping hand when you are in trouble.
So I propose you a solution which uses ffi:
require 'ffi'
module LibX11
extend FFI::Library
ffi_lib 'libX11.so.6'
# Display *XkbOpenDisplay (char *display_name, int *event_rtrn, int *error_rtrn, int *major_in_out, int *minor_in_out, int *reason_rtrn)
attach_function :XkbOpenDisplay, [:pointer, :pointer, :pointer, :pointer, :pointer, :pointer], :pointer
end
Then you have to describe the Display struct layout, like written here:
class Display < FFI::Struct
layout :value, :double,
:other_value, :char,
...
end
And then you do something like this:
p1 = FFI::MemoryPointer.new(:char)
p2 = FFI::MemoryPointer.new(:int)
p3 = FFI::MemoryPointer.new(:int)
p4 = FFI::MemoryPointer.new(:int)
p5 = FFI::MemoryPointer.new(:int)
p6 = FFI::MemoryPointer.new(:int)
# write to pointer if needed, otherwise it is a null pointer
# p1.write_char('a')
# p2.write_int(1)
# ...
struct_pointer = LibX11.XkbOpenDisplay(p1, p2, p3, p4, p5, p6)
# read the struct
struct = Display.new(display_struct_pointer)
p Hash[ s.members.map { |m| [ m, s[m] ] } ]
I didn't tested the code, but it should be roughly correct. Let me now if it isn't.
After some research about DL on ruby 2.0 I found that it is deprecated and replaced with fiddle, you would consider to use it rather than DL if you can't use FFI. Fiddle seems to be available for ruby 1.9.3 and 1.9.2 too
This question is a bit specific, but here goes: I'd like to use ZZipLib with SDL. (http://zziplib.sourceforge.net/) ZZipLib comes with a file called SDL_rwops_zzip.c that is specifically intended to make it easy to plug into SDL's file calls. And I have in fact done this without trouble on the Mac.
The problem is on Windows it won't compile. The code in question is from SDL_rwops_zzip.c:
#define SDL_RWOPS_ZZIP_DATA(_context) \
((_context)->hidden.unknown.data1)
#define SDL_RWOPS_ZZIP_FILE(_context) (ZZIP_FILE*) \
((_context)->hidden.unknown.data1)
static int _zzip_seek(SDL_RWops *context, int offset, int whence) // line 30
{
return zzip_seek(SDL_RWOPS_ZZIP_FILE(context), offset, whence);
}
The errors I get are:
SDL_rwops_zzip.c(31): warning C4028: formal parameter 1 different from declaration
SDL_rwops_zzip.c(31): warning C4028: formal parameter 3 different from declaration
SDL_rwops_zzip.c(31): warning C4029: declared formal parameter list different from definition
SDL_rwops_zzip.c(31): error C2491: '_read' : definition of dllimport function not allowed
This Stack Overflow post gives some info on that error:
definition of dllimport function not allowed
but I really don't understand what to do to resolve this error in this particular situation.
I solved the problem by recompiling zziplib using a built-from-scratch Visual Studio 10 Project (the upgraded visual studio 7 project did not produce a working library or .dll), and then by commenting out these lines in conf.h:
# if !__STDC__
# ifndef _zzip_lseek
# define _zzip_lseek _lseek
# endif
# ifndef _zzip_read
# define _zzip_read _read
# endif
# ifndef _zzip_write
# define _zzip_write _write
# endif
# if 0
# ifndef _zzip_stat
# define _zzip_stat _stat
# endif
# endif
# endif // !__STDC__
#endif
and this:
# ifndef _zzip_lseek
# define _zzip_lseek lseek
# endif
# ifndef _zzip_read
# define _zzip_read read
# endif
# ifndef _zzip_write
# define _zzip_write write
# endif