weak

GCC behavior for unresolved weak functions

≯℡__Kan透↙ 提交于 2019-12-10 15:45:32
问题 Consider the simple program below: __attribute__((weak)) void weakf(void); int main(int argc, char *argv[]) { weakf(); } When compiling this with gcc and running it on a Linux PC, it segfaults. When running it on ARM CM0 (arm-none-eabi-gcc), the linker replace the undefined symbol by a jump to the following instruction and a nop. Where is this behavior documented? Is there possible ways to change it through command line options? I have been through GCC and LD documentations, there is no

JIT Optimization and Weak References

◇◆丶佛笑我妖孽 提交于 2019-12-10 12:57:02
问题 I have the following piece of code: private final List<WeakReference<T>> slaves; public void updateOrdering() { // removes void weak references // and ensures that weak references are not voided // during subsequent sort List<T> unwrapped = unwrap(); assert unwrapped.size() == this.slaves.size(); // **** could be reimplemented without using unwrap() **** Collections.sort(this.slaves, CMP_IDX_SLV); unwrapped = null;// without this, .... } Method unwrap() just creates a list of T 's referenced

__weak and autorelease pool in ARC in Xcode 4.2

送分小仙女□ 提交于 2019-12-10 10:08:31
问题 My project use ARC. I tested with the code below: NSString __weak *string; @autoreleasepool { string = [NSString stringWithString:@"AAA"]; } NSLog(@"string: %@", string); I think it output as: string: (null) but it actually output: string: AAA I don't understand it. What is the effect of __weak? EDIT: And this code below: NSString __weak *string; NSString __strong *str; @autoreleasepool { str = [NSString stringWithFormat:@"%@", @"AAA" ]; string = str; } NSLog(@"string: %@", string); It also

Is there a boost::weak_intrusive_pointer?

一世执手 提交于 2019-12-08 15:56:30
问题 For legacy reasons I need to use intrusive pointers, as I need the ability to convert raw pointers to smart pointers. However I noticed there is no weak intrusive pointer for boost. I did find a talk about it on the boost thread list, however nothing concrete. Does anyone know of a thread safe implementation of weak intrusive pointer? Thanks Rich 回答1: It does not make any sense. To elaborate: weak_ptr points to the same instance of a counter object that shared_ptr do. When the shared_ptr goes

Weak symbol link on Mac OS X

北城以北 提交于 2019-12-06 20:42:00
问题 Currently I encountered a weak link issue on Mac OS X 10.6.7 with Xcode 4.0.2. robin@chameleon:/tmp/o$ gcc --version i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) As the document http://developer.apple.com/library/mac/#technotes/tn2064/_index.html said, we can use gcc attribute ((weak_import)) for weak link symbol. However, the following sample code always throw compile error. As the following: weak.c : #include <stdlib.h> #include <stdio.h> extern int SayHello() _

boost::shared_ptr cycle break with weak_ptr

◇◆丶佛笑我妖孽 提交于 2019-12-06 13:36:20
I am currently in a situation like: struct A { shared_ptr<B> b; }; struct B { shared_ptr<A> a; }; //... shared_ptr<A> a(new A()); shared_ptr<B> b(new B()); a->b(b); b->a(a); I know this won't work, because the references would continue to point to each other. I've also been told that weak_ptr solves this issue. However, weak_ptr has no get or -> overload. I've heard mentions of 'use lock() ', but can anyone give code examples of how to do this correctly? Come on now. http://boost.org/doc/libs/1_42_0/libs/smart_ptr/weak_ptr.htm ^^^^^ EXAMPLE IS RIGHT THERE ^^^^^^ DAMN! I think the bigger issue

__weak and autorelease pool in ARC in Xcode 4.2

与世无争的帅哥 提交于 2019-12-05 18:39:24
My project use ARC. I tested with the code below: NSString __weak *string; @autoreleasepool { string = [NSString stringWithString:@"AAA"]; } NSLog(@"string: %@", string); I think it output as: string: (null) but it actually output: string: AAA I don't understand it. What is the effect of __weak? EDIT: And this code below: NSString __weak *string; NSString __strong *str; @autoreleasepool { str = [NSString stringWithFormat:@"%@", @"AAA" ]; string = str; } NSLog(@"string: %@", string); It also output as: string: AAA NSString __weak *string; @autoreleasepool { string = [NSString stringWithFormat:@

Python - how to check if weak reference is still available

ぃ、小莉子 提交于 2019-12-05 10:30:20
I am passing some weakrefs from Python into C++ class, but C++ destructors are actively trying to access the ref when the real object is already dead, obviously it crashes... Is there any Python C/API approach to find out if Python reference is still alive or any other known workaround for this ? Thanks If you call PyWeakref_GetObject on the weak reference it should return either Py_None or NULL, I forget which. But you should check if it's returning one of those and that will tell you that the referenced object is no longer alive. doublep From Python C API documentation: PyObject* PyWeakref

Weak symbol link on Mac OS X

萝らか妹 提交于 2019-12-05 01:59:00
Currently I encountered a weak link issue on Mac OS X 10.6.7 with Xcode 4.0.2. robin@chameleon:/tmp/o$ gcc --version i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3) As the document http://developer.apple.com/library/mac/#technotes/tn2064/_index.html said, we can use gcc attribute ((weak_import)) for weak link symbol. However, the following sample code always throw compile error. As the following: weak.c : #include <stdlib.h> #include <stdio.h> extern int SayHello() __attribute__((weak)); int main() { int result; if (SayHello!=NULL) { printf("SayHello is present!\n");

Trouble using scriptedmain in MinGW

半世苍凉 提交于 2019-12-04 15:44:35
I want to reproduce this Perl code in C, bundling API and CLI in the same C source code file ( scriptedmain ). This is done in Python with if __name__=="__main__": main() and in gcc/Unix, this looks like: $ gcc -o scriptedmain scriptedmain.c scriptedmain.h $ ./scriptedmain Main: The meaning of life is 42 $ gcc -o test test.c scriptedmain.c scriptedmain.h $ ./test Test: The meaning of life is 42 scriptedmain.h int meaning_of_life(); scriptedmain.c #include <stdio.h> int meaning_of_life() { return 42; } int __attribute__((weak)) main() { printf("Main: The meaning of life is %d\n", meaning_of