cairocffi throws an error with pango - cairo

context = cairocffi.Context(surface)
# pangocairo.pango_cairo_set_antialias(cairo.ANTIALIAS_SUBPIXEL)
context.translate(movex, movey)
context.rotate(twist)
layout = gobject_ref(pangocairo.pango_cairo_create_layout(context._pointer))
In the last line of this code cairocffi give a weird error
TypeError: initializer for ctype 'cairo_t *' appears indeed to be 'cairo_t *', but the types are different (check that you are not e.g. mixing up different ffi instances)
What could be the problem here?

Related

How to resolve 'The method observe(Viewer) is ambiguous for the type IViewerValueProperty<Viewer,Object>' compiler error

I was trying to use the org.eclipse.core.databinding plugin to bind my TableViewer input change.
When I tried to add the binding by below code:
1. TableViewer tableViewer = new TableViewer(parent);
2. IViewerObservableValue<Target> target = ViewerProperties.input(TableViewer.class).observe(tableViewer);
3. UpdateValueStrategy<String, Target> updateValueStrategy = new UpdateValueStrategy<>();
updateValueStrategy.setConverter(...);
4. this.bindingContext.bindValue(target, source, new UpdateValueStrategy<>(UpdateValueStrategy.POLICY_NEVER),
updateValueStrategy);
But, at line number 2, I'm getting an compiler error that 'The method observe(Viewer) is ambiguous for the type IViewerValueProperty<Viewer,Object>' compiler error.
When I look into the source of IViewerObservableValue, There are 2 methods similar, I tried type casting with Viewer or Object for tableViewer variable passed, but, I'm still getting the error.
`/**
* Returns an {#link IViewerObservableValue} observing this value property
* on the given viewer
*
* #param viewer
* the source viewer
* #return an observable value observing this value property on the given
* viewer
*/
public IViewerObservableValue<T> observe(Viewer viewer);
/**
* This method is redeclared to trigger ambiguous method errors that are hidden
* by a suspected Eclipse compiler bug 536911. By triggering the bug in this way
* clients avoid a change of behavior when the bug is fixed. When the bug is
* fixed this redeclaration should be removed.
*/
#Override
public IObservableValue<T> observe(S viewer);`
what I'm doing wrong?
Sorry Everyone, I have figured it out, We can do by following:
IViewerValueProperty<TableViewer, Target> target = ViewerProperties.<TableViewer, Target>input();
IObservableValue<Target> observe = target.observe(tableViewer);
I had forgot to add generic classes to the input() method call, which would have identified the specific observer(viewer) method.
Previously, as I had not provided the generics, the compiler was unable to distinguish between the observe(viewerType) and observe(S).
Thanks,
Pal

Is there any difference between initializing with empty values or null value?

Is there any difference between these two part of code? (I am specially using Flutter/Dart but also interested to know about this in any other popular languages like C/C++, Java, JS, Python, etc.)
Code1:
String a = null; (in Flutter: a = null as String; )
List<T> = null; (in Flutter: List<T> = null as List<T>;)
Code 2:
String a = '';
List<T> = [];
With Dart nullsafety your first examples are invalid (assuming you meant to have a variable name on your List). If a variable can contain null the type needs a '?' suffix:
String? a = null;
List<T>? b = null;
But with or without nullsafety or '?', use of the variables in your second example won't result in runtime errors. For example a.trim(): if a is null a runtime error will occur because you're trying to call (null).trim(). In your second example no error because there is a String object to access, even though that String object is empty of characters. Same for your List: b.forEach((e) {}) when b==null a runtime error occurs because there's no Object to find forEach() - i.e. the runtime doesn't know what to do with (null).forEach(). In your second example the forEach() doesn't execute the function because List b is empty, but there's no runtime error because there's an Object to call forEach() on.
In C: NULL for pointers is usually synonymous with 0. The result of trying to access memory address NULL is "undefined" in C, because it could be valid as 0x00 in some instances like embedded systems or low-level system code, but will usually result in your process being terminated (crash).

Compile error for zxing library

ZXPDF417Codeword *codeword = [self.detectionResultColumnsInternal[barcodeColumn] codewords][codewordsRow];
/My Projects/in Loyal SVN/new source Inloyal/ProjectCode_Inloyal_21-May/ZBarSDK/ZXingObjC/pdf417/decoder/ZXPDF417DetectionResult.m:144:38: Expected method to read array element not found on object of type 'NSString *'
Replace it with:
ZXPDF417Codeword *codeword = ((NSArray *)[self.detectionResultColumnsInternal[barcodeColumn] codewords])[codewordsRow];
It should work I think.

Xcode 6 beta 2 debugger not showing variable contents after call to String.componentsSeparatedByString

For some reason LLDB is not showing me the contents of variables while I am stepping through my Swift code. The actual execution works fine, but no matter what I try I can't see the contents of my strings!
Here's what I see in the variable list:
At this point type contains "name" and value contains "Logan". But you wouldn't be able to tell that looking here. If I use the "quick look" button, it says the value is "(None)".
And I get this kind of gibberish when I try to po a String from the console:
(lldb) po space
error: <REPL>:1:1: error: non-nominal type '$__lldb_context' cannot be extended
extension $__lldb_context {
^
<REPL>:11:5: error: 'Space.Type' does not have a member named '$__lldb_wrapped_expr_0'
$__lldb_injected_self.$__lldb_wrapped_expr_0(
^
However this varies. Sometimes I'll get something like:
class name = __NSAtom
or
Printing description of [0]:
(String) [0] = {
core = {
_baseAddress = Builtin.RawPointer = 0x00000001004016f0
_countAndFlags = -4611686018427387894
_owner = Some {
Some = (instance_type = Builtin.RawPointer = 0x0000000100401820 -> 0x00007fff7b3d5390 (void *)0x00007fff7b3d5340: __NSCFString)
}
}
}
or
Printing description of declaration:
(String) declaration = <DW_OP_piece for offset 8: top of stack is not a piece>
...but never the actual contents of the string!
Update:
I've noticed the problem only seems to start occurring once a call to componentsSeparatedByString() is made in the function. (This happens right at the top so as I was stepping I didn't notice that the debugger actually does show the value until this point.) So something weird is going on with that function. I've updated the question title to reflect this new information.
Interestingly, it seems once the string has been "corrupted" by this call, you can't view it anywhere else, even when passed to a different function. And any regular string variables are not viewable either. Definitely a bug, but I wonder if there's a workaround. It's getting really hard to debug my program!
When I've been encountering this, I've used either NSLog("\(myThing)") in the compiled code I want to debug, or have been calling expression NSLog("\(myThing)") while in the debugger's REPL
(note that you do not want to do NSLog("(someVariable)") as the expanded string could contain % format sequences - use NSLog("%#", "(someVariable)") or NSLog("%#", someVariable) instead)
I'd like to add an update: this problem still occurs in the latest versions of Xcode, both 6.2 release and 6.3 beta.
The problem is part of componentsSeparatedByString, and if you replace that with split everything works fine. I had four instances of this, and as soon as I changed them my app stopped crashing with a Zombie release of NSString, and all my variable names started working. I changed things like this...
let bits = value!.componentsSeparatedByString(" ")
with...
let bits = split(value!, { $0 == " "}, maxSplit: Int.max, allowEmptySlices: false)
I don't think split is nearly as readable, but at least it works!

Accessing elements of a struct instance variable in Objective-C using the getter

I have an instance variable which is a struct, for example:
struct Data {
UInt32 i;
UInt32 arr[1];
};
And a property is defined in my class:
#property struct Data data; // and the corresponding #synthesize in the imp file
Now, I am aware that changing the values of i and arr through the getter of data is conceptually wrong, since I will be accessing the copy of data returned by the getter (the correct way is accessing it using self->data).
However some general Objective-C questions arise regarding the following lines:
self.data.i = 1; // produces compile error
self.data.arr[0] = 1; // compiles ok
First, why does the first line produces a compile error, and the 2nd line does not?
Second, if the dot syntax in the above line (self.data) is just a syntactic sugar to [self data], why do I get 2 different (although similar) compile errors?
self.data.i = 1; // error: Expression is not assignable
[self data].i = 1; // error: Semantic Issue: Assigning to 'readonly' return result of an objective-c message not allowed
Actually, structs are passed by value in C (and Objective C). That means that your property actually returns a read only copy (rvalue) of the internal "Data" type. The assignment is to the temporary returned copy, which the compiler (rightfully) flags as a bit suspect.
The second line that compiles correctly does so since self.data.arr returns a read only UInt32*, but when you index it with [0] and write to that, you're not writing to the pointer, you're writing to the memory that it points to which is allowed.