What does NSLog really do?

I have a strange problem. I am using a method from Apple's private private applications in my application. When I call it the first time, it works. When I call him a second time immediately, without anything in between, he falls. However, if I installed NSLog between two calls, it works fine. So I'm trying to remove NSLog and put for-loops, sleep (), printf ("...") and fprintf (stderr, "...") between them to emulate NSLog, but that does not help. I am wondering how the method knows that I am using NSLog? In other words, what does NSLog actually do to influence the behavior of a method?

Many thanks!

EDIT:

I seem to have solved this problem. I will share my decision here and hope it can be useful for some people.

I am creating a multitouch application using MultitouchSupport.framework. I copied the code from http://aladino.dmi.unict.it/?a=multitouch and added CFReleaseat the end of the loop. So basically, my main method is as follows:

int main(void) { 
    int i; 
    NSMutableArray* deviceList = (NSMutableArray*)MTDeviceCreateList(); //grab our device list 
    for(i = 0; i<[deviceList count]; i++) { //iterate available devices 
        MTRegisterContactFrameCallback([deviceList objectAtIndex:i], touchCallback); //assign callback for device 
        MTDeviceStart([deviceList objectAtIndex:i], 0); //start sending events 
    }
    CFRelease((CFMutableArrayRef)deviceList); 
    printf("Ctrl-C to abort\n"); 
    sleep(-1); 
    return 0; 
}

After starting up, "Software received signal:" EXC_BAD_ACCESS "will be displayed for a while." And here is the stack trace:

#0 0x7fff8795496e in ParsedMultitouchFrameRepInitialize
#1 0x7fff879565b1 in mt_HandleMultitouchFrame
#2 0x7fff87955a03 in mt_DequeueDataFromDriver
#3 0x7fff87955b29 in mt_DequeueMultitouchDataFromDriverThreadEntry
#4 0x7fff831b3456 in _pthread_start
#5 0x7fff831b3309 in thread_start

However, if I put the NSLog below MTDeviceStart, it will not work.

The reason I added CFRelease((CFMutableArrayRef)deviceList)to the source code is because I think that objects created from functions named * Create * or * Copy * must be released by themselves. But it turns out that if I delete it, as the source code does, it will not work, even without using NSLog.

, , deviceList ? , NSLog, , ?

+3
4

- :

static inline void NSLogMessageString(NSString *string){
  NSString *date=[[NSDate date]
   descriptionWithCalendarFormat:@"%Y-%m-%d %H:%M:%S.%F"
                        timeZone:nil locale:nil];
  NSString *process=[[NSProcessInfo processInfo] processName];

  NSLogFormat(@"%@ %@[%d:%lx] %@",date,process,NSPlatformProcessID(),NSPlatformThreadID(),string);
}

void NSLogv(NSString *format,va_list arguments) {
  NSString *string=NSStringNewWithFormat(format,nil,arguments,NULL);

  NSLogMessageString(string);

 [string release];
}

void NSLog(NSString *format,...) {
  va_list arguments;

  va_start(arguments,format);

  NSLogv(format,arguments);
}

lol, , , NSLogging, ..

+2

. , . /, , , () , . , syslogd ( Xcode, iPCU NSLogs , , ); IPC .

syslog() (#import <syslog.h>, syslog(LOG_INFO, "Hello there!");, , , (. man 3 syslog).

+1

NSLog , , , , , NSLog , stdout. printf "heisenbugs" (.. , ).

+1

This might be a memory management issue: perhaps a third-party release. If you post a trace, this can help you fix the problem. (As it turns out, someone on Twitter I'm following mentioned something like this last night).

0
source

Source: https://habr.com/ru/post/1760859/


All Articles