Changeset 5500 in project


Ignore:
Timestamp:
08/18/07 04:24:19 (13 years ago)
Author:
Kon Lovett
Message:

Dropped use of CFStringGetCStringPtr.

Location:
macosx
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • macosx/macosx-eggdoc.scm

    r5402 r5500  
    3636    (author (url "mailto:klovett@pacbell.net" "Kon Lovett"))
    3737    (history
     38     (version "2.002" "Dropped invalid use of 'CFStringGetCStringPtr'.")
    3839     (version "2.001" "Use of unsigned-c-string*. Bugfix for macosx:open-url.")
    3940     (version "2.0" "Changed macosx:machine-location & macosx:console-user to return a vector. Deprecated macosx:get-bundle-path, use macosx:main-bundle-path. Added macosx:session-info.")
  • macosx/macosx-env.scm

    r5402 r5500  
    77;;
    88;; - No SCDynamicStoreCopyProxies support
     9;;
     10;; - No CFStringGetCStringPtr use since memory allocation is not performed.
     11;; This is sub-par but makes the Scheme invocation more complex.
    912
    1013(declare
    11         (uses lolevel)
    1214  (no-procedure-checks)
    1315        (no-bound-checks)
     
    5456#define VECLEN(v) (sizeof(v)/sizeof((v)[0]))
    5557
    56 static const unsigned char *
    57 cfsr_to_utf8buf (CFStringRef cfsr, CFIndex char_len, unsigned char **buf)
    58 {
    59         CFIndex buflen = char_len + 1;
    60         *buf = ((unsigned char *) C_malloc (buflen));
    61         if (! CFStringGetCString (cfsr, (char *) *buf, buflen, kCFStringEncodingUTF8)) {
    62                 C_free (*buf);
    63                 *buf = NULL;
     58static void
     59cfsr_to_utf8str (CFStringRef cfsr, unsigned char **outstr)
     60{
     61#       define LONG_CHARS_PER_UTF8 6
     62        CFIndex buflen = LONG_CHARS_PER_UTF8 * CFStringGetLength (cfsr) + 1;
     63        *outstr = ((unsigned char *) C_malloc (buflen));
     64        if (! CFStringGetCString (cfsr, (char *) *outstr, buflen, kCFStringEncodingUTF8)) {
     65                C_free (*outstr);
     66                *outstr = NULL;
    6467        }
    65         return ((const unsigned char *) *buf);
    66 }
    67 
    68 static const unsigned char *
    69 cfsr_to_utf8str (CFStringRef cfsr, unsigned char **buf)
    70 {
    71         const char *str = CFStringGetCStringPtr (cfsr, kCFStringEncodingUTF8);
    72         if (str) {
    73                 *buf = NULL;
    74                 return ((const unsigned char *) str);
    75         } else {
    76 #               define LONG_CHARS_PER_UTF8 6
    77                 return cfsr_to_utf8buf (cfsr, LONG_CHARS_PER_UTF8 * CFStringGetLength (cfsr), buf);
    78 #               undef LONG_CHARS_PER_UTF8
    79         }
    80 }
    81 
    82 static const unsigned char *
    83 machine_name (unsigned char **buf)
    84 {
    85         return cfsr_to_utf8str (CSCopyMachineName(), buf);
    86 }
    87 
    88 static const unsigned char *
    89 short_user_name (unsigned char **buf)
    90 {
    91         return cfsr_to_utf8str (CSCopyUserName (true), buf);
    92 }
    93 
    94 static const unsigned char *
    95 long_user_name (unsigned char **buf)
    96 {
    97         return cfsr_to_utf8str (CSCopyUserName (false), buf);
     68#       undef LONG_CHARS_PER_UTF8
     69}
     70
     71static void
     72machine_name (unsigned char **outstr)
     73{
     74        cfsr_to_utf8str (CSCopyMachineName(), outstr);
     75}
     76
     77static void
     78short_user_name (unsigned char **outstr)
     79{
     80        cfsr_to_utf8str (CSCopyUserName (true), outstr);
     81}
     82
     83static void
     84long_user_name (unsigned char **outstr)
     85{
     86        cfsr_to_utf8str (CSCopyUserName (false), outstr);
    9887}
    9988
     
    111100}
    112101
    113 static const unsigned char *
    114 computer_name (unsigned char **buf, SCDynamicStoreRef store)
     102static void
     103computer_name (unsigned char **outstr, SCDynamicStoreRef store)
    115104{
    116105  /* Assumes UTF8 encoding! */
    117106        CFStringRef cfsr = SCDynamicStoreCopyComputerName (store, NULL);
    118         const unsigned char *str = cfsr_to_utf8str (cfsr, buf);
     107        cfsr_to_utf8str (cfsr, outstr);
    119108        CFRelease (cfsr);
    120         return str;
    121 }
    122 
    123 static const unsigned char *
    124 console_user (unsigned char **buf, uint32_t *puid, uint32_t *pgid, SCDynamicStoreRef store)
     109}
     110
     111static void
     112console_user (unsigned char **outstr, uint32_t *puid, uint32_t *pgid, SCDynamicStoreRef store)
    125113{
    126114        uid_t uid;
    127115        gid_t gid;
    128116        CFStringRef cfsr = SCDynamicStoreCopyConsoleUser (store, &uid, &gid);
    129         const unsigned char *str = cfsr_to_utf8str (cfsr, buf);
     117        cfsr_to_utf8str (cfsr, outstr);
    130118        CFRelease (cfsr);
    131119        *puid = uid;
    132120        *pgid = gid;
    133         return str;
    134 }
    135 
    136 static const unsigned char *
    137 local_host_name (unsigned char **buf, SCDynamicStoreRef store)
     121}
     122
     123static void
     124local_host_name (unsigned char **outstr, SCDynamicStoreRef store)
    138125{
    139126        CFStringRef cfsr = SCDynamicStoreCopyLocalHostName (store);
    140         const unsigned char *str = cfsr_to_utf8str (cfsr, buf);
     127        cfsr_to_utf8str (cfsr, outstr);
    141128        CFRelease (cfsr);
    142         return str;
    143 }
    144 
    145 static const unsigned char *
    146 location_name (unsigned char **buf, SCDynamicStoreRef store)
     129}
     130
     131static void
     132location_name (unsigned char **outstr, SCDynamicStoreRef store)
    147133{
    148134        CFStringRef cfsr = SCDynamicStoreCopyLocation (store);
    149         const unsigned char *str = cfsr_to_utf8str (cfsr, buf);
     135        cfsr_to_utf8str (cfsr, outstr);
    150136        CFRelease (cfsr);
    151         return str;
    152 }
    153 
    154 static const unsigned char *
    155 main_bundle_path (unsigned char **buf)
     137}
     138
     139static void
     140main_bundle_path (unsigned char **outstr)
    156141{
    157142  CFBundleRef bundle = CFBundleGetMainBundle();
     143  *outstr = NULL;
    158144  if (NULL != bundle) {
    159145    CFURLRef url = CFBundleCopyExecutableURL (bundle);
    160146    if (NULL != url) {
    161147      long buflen = pathconf ("/", _PC_PATH_MAX); /* Any pathname will do */
    162       *buf = ((unsigned char *) C_malloc (buflen));
    163       if (NULL != buf) {
    164           if (CFURLGetFileSystemRepresentation (url, true, *buf, buflen))
    165             return *buf;
    166           else
    167             C_free (buf);
     148      *outstr = ((unsigned char *) C_malloc (buflen));
     149      if (NULL != outstr) {
     150        if (!CFURLGetFileSystemRepresentation (url, true, *outstr, buflen)) {
     151          C_free (outstr);
     152          *outstr = NULL;
     153        }
    168154      }
    169155    }
    170156  }
    171   return NULL;
    172157}
    173158
     
    201186#define session_UserIsActive    0x0010
    202187
    203 static const unsigned char *
    204 this_session_info_2 (unsigned char **buf, uint32_t *puid, uint32_t *pcon, uint32_t *pbit)
     188static void
     189this_session_info_2 (unsigned char **outstr, uint32_t *puid, uint32_t *pcon, uint32_t *pbit)
    205190{
    206191  CFDictionaryRef sessionInfoDict = CGSessionCopyCurrentDictionary();
     
    214199    CFNumberGetValue (consoleSet, kCFNumberSInt32Type, pcon);
    215200    *pbit = (CFBooleanGetValue (loginCompleted) << 1) | CFBooleanGetValue (userIsActive);
    216     return cfsr_to_utf8str (shortUserName, buf);
     201    cfsr_to_utf8str (shortUserName, outstr);
     202  } else {
     203    *outstr = NULL;
    217204  }
    218   return NULL;
    219205}
    220206<#
     
    223209
    224210(define-macro (call/unsigned-string-result C-NAME . EXTRA)
    225         `(let-location ([buf unsigned-c-string*])
    226                  ($ unsigned-c-string* ,C-NAME #$buf ,@EXTRA) ) )
     211        `(let-location ([outstr unsigned-c-string*])
     212           ($ void ,C-NAME #$outstr ,@EXTRA)
     213                 outstr ) )
    227214
    228215(define-macro (foreign-mask-set? ?bits ?c-nam)
  • macosx/macosx-url.scm

    r5402 r5500  
    1313
    1414static int
    15 open_url (const char * urlstr, int len)
     15open_url (const char *urlstr, int len)
    1616{
    1717        OSStatus    sta = 1;
  • macosx/macosx.html

    r5402 r5500  
    158158<h3>Version</h3>
    159159<ul>
     160<li>2.002 Dropped invalid use of 'CFStringGetCStringPtr'.</li>
    160161<li>2.001 Use of unsigned-c-string*. Bugfix for macosx:open-url.</li>
    161162<li>2.0 Changed macosx:machine-location &amp; macosx:console-user to return a vector. Deprecated macosx:get-bundle-path, use macosx:main-bundle-path. Added macosx:session-info.</li>
  • macosx/macosx.setup

    r5402 r5500  
    11(include "setup-header")
    22
    3 (install-dynld macosx-env "2.001" +dollar
     3(install-dynld macosx-env "2.002" +dollar
    44        -framework CoreFoundation -framework CoreServices -framework SystemConfiguration
    55        -framework Security -framework ApplicationServices
    66        (documentation "macosx.html"))
    77
    8 (install-dynld macosx-url "2.001" +dollar
     8(install-dynld macosx-url "2.002" +dollar
    99        -framework CoreFoundation -framework ApplicationServices
    1010        (documentation "macosx.html"))
Note: See TracChangeset for help on using the changeset viewer.