[vlc-commits] [Git][videolan/vlc][3.0.x] 7 commits: upnp: Rename FromCFString

Jean-Baptiste Kempf (@jbk) gitlab at videolan.org
Sat Oct 1 08:17:31 UTC 2022



Jean-Baptiste Kempf pushed to branch 3.0.x at VideoLAN / VLC


Commits:
bc266652 by Marvin Scholz at 2022-10-01T08:05:30+00:00
upnp: Rename FromCFString

Preparation to add it to vlc_charset.h

- - - - -
233b0b87 by Marvin Scholz at 2022-10-01T08:05:30+00:00
include/vlc_charset: Add FromCFString for darwin

This is a helper function to obtain the copy of a char* from a
CFStringRef.

Changes compared to master:
 - Include CFString.h instead of the umbrella header
   to prevent a type clash with guid_t declared in the
   CoreFoundation headers.

(cherry picked from commit f4b57268547f27172966cc7d850f797acaaa77d3)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
0a0605d7 by Marvin Scholz at 2022-10-01T08:05:30+00:00
upnp: Use FromCFString from vlc_charset.h

- - - - -
4650bfe2 by Marvin Scholz at 2022-10-01T08:05:30+00:00
text_renderer/freetype: Use FromCFString on darwin

(cherry picked from commit 960a48626df9f0fcb4215394598977a347b34994)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
cbe4fe42 by Marvin Scholz at 2022-10-01T08:05:30+00:00
auhal: Use FromCFString

Fix #27043

(cherry picked from commit 43663467cb534b97c01c6d7828b4b942741a4529)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
cdd6c770 by Marvin Scholz at 2022-10-01T08:05:30+00:00
darwin/dirs: Use FromCFString

(cherry picked from commit 82c18a3b4b72b677f2576e4cc6197aaad2fc2a61)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -
fef232f9 by Marvin Scholz at 2022-10-01T08:05:30+00:00
darwinvlc: Use FromCFString

(cherry picked from commit d75d12bee277760353a4b710f1703d3ef3944b32)
Signed-off-by: Marvin Scholz <epirat07 at gmail.com>

- - - - -


6 changed files:

- bin/darwinvlc.m
- include/vlc_charset.h
- modules/audio_output/auhal.c
- modules/services_discovery/upnp.cpp
- modules/text_renderer/freetype/fonts/darwin.c
- src/darwin/dirs.c


Changes:

=====================================
bin/darwinvlc.m
=====================================
@@ -27,6 +27,9 @@
 #endif
 
 #include <vlc/vlc.h>
+#include <vlc_common.h>
+#include <vlc_charset.h>
+
 #include <stdlib.h>
 #include <locale.h>
 #include <signal.h>
@@ -251,21 +254,13 @@ int main(int i_argc, const char *ppsz_argv[])
         language = (CFStringRef)CFPreferencesCopyAppValue(CFSTR("language"),
                                                           kCFPreferencesCurrentApplication);
         if (language) {
-            CFIndex length = CFStringGetLength(language) + 1;
-            if (length > 0) {
-                CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
-                lang = (char *)malloc(maxSize);
-                if(lang) {
-                    CFStringGetCString(language, lang, maxSize - 1, kCFStringEncodingUTF8);
-                    if (strncmp( lang, "auto", 4 )) {
-                        char tmp[11];
-                        snprintf(tmp, 11, "LANG=%s", lang);
-                        putenv(tmp);
-
-                    }
-                }
-                free(lang);
+            lang = FromCFString(language, kCFStringEncodingUTF8);
+            if (strncmp( lang, "auto", 4 )) {
+                char tmp[11];
+                snprintf(tmp, 11, "LANG=%s", lang);
+                putenv(tmp);
             }
+            free(lang);
             CFRelease(language);
         }
     }


=====================================
include/vlc_charset.h
=====================================
@@ -124,6 +124,50 @@ VLC_API char * vlc_strcasestr(const char *, const char *) VLC_USED;
 VLC_API char * FromCharset( const char *charset, const void *data, size_t data_size ) VLC_USED;
 VLC_API void * ToCharset( const char *charset, const char *in, size_t *outsize ) VLC_USED;
 
+#ifdef __APPLE__
+# include <CoreFoundation/CFString.h>
+
+/* Obtains a copy of the contents of a CFString in specified encoding.
+ * Returns char* (must be freed by caller) or NULL on failure.
+ */
+VLC_USED static inline char *FromCFString(const CFStringRef cfString,
+    const CFStringEncoding cfStringEncoding)
+{
+    // Try the quick way to obtain the buffer
+    const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding);
+
+    if (tmpBuffer != NULL) {
+       return strdup(tmpBuffer);
+    }
+
+    // The quick way did not work, try the long way
+    CFIndex length = CFStringGetLength(cfString);
+    CFIndex maxSize =
+        CFStringGetMaximumSizeForEncoding(length, cfStringEncoding);
+
+    // If result would exceed LONG_MAX, kCFNotFound is returned
+    if (unlikely(maxSize == kCFNotFound)) {
+        return NULL;
+    }
+
+    // Account for the null terminator
+    maxSize++;
+
+    char *buffer = (char *)malloc(maxSize);
+
+    if (unlikely(buffer == NULL)) {
+        return NULL;
+    }
+
+    // Copy CFString in requested encoding to buffer
+    Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding);
+
+    if (!success)
+        FREENULL(buffer);
+    return buffer;
+}
+#endif
+
 #ifdef _WIN32
 VLC_USED
 static inline char *FromWide (const wchar_t *wide)


=====================================
modules/audio_output/auhal.c
=====================================
@@ -28,6 +28,7 @@
 
 #import <vlc_plugin.h>
 #import <vlc_dialog.h>                      // vlc_dialog_display_error
+#import <vlc_charset.h>                     // FromCFString
 
 #import <CoreAudio/CoreAudio.h>             // AudioDeviceID
 #import <CoreServices/CoreServices.h>
@@ -505,16 +506,7 @@ RebuildDeviceList(audio_output_t * p_aout, UInt32 *p_id_exists)
             continue;
         }
 
-        length = CFStringGetLength(device_name_ref);
-        length++;
-        psz_name = malloc(length);
-        if (!psz_name)
-        {
-            CFRelease(device_name_ref);
-            return;
-        }
-        CFStringGetCString(device_name_ref, psz_name, length,
-                           kCFStringEncodingUTF8);
+        psz_name = FromCFString(device_name_ref, kCFStringEncodingUTF8);
         CFRelease(device_name_ref);
 
         msg_Dbg(p_aout, "DevID: %i DevName: %s", i_id, psz_name);


=====================================
modules/services_discovery/upnp.cpp
=====================================
@@ -1562,40 +1562,6 @@ done:
 #include <SystemConfiguration/SystemConfiguration.h>
 #include "vlc_charset.h"
 
-inline char *FromCFString(const CFStringRef cfString,
-                          const CFStringEncoding cfStringEncoding)
-{
-    // Try the quick way to obtain the buffer
-    const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding);
-    if (tmpBuffer != NULL) {
-        return strdup(tmpBuffer);
-    }
-
-    // The quick way did not work, try the long way
-    CFIndex length = CFStringGetLength(cfString);
-    CFIndex maxSize = CFStringGetMaximumSizeForEncoding(length, cfStringEncoding);
-
-    // If result would exceed LONG_MAX, kCFNotFound is returned
-    if (unlikely(maxSize == kCFNotFound)) {
-        return NULL;
-    }
-
-    // Account for the null terminator
-    maxSize++;
-
-    char *buffer = (char *)malloc(maxSize);
-    if (unlikely(buffer == NULL)) {
-        return NULL;
-    }
-
-    // Copy CFString in requested encoding to buffer
-    Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding);
-
-    if (!success)
-        FREENULL(buffer);
-    return buffer;
-}
-
 inline char *getPreferedAdapter()
 {
     SCDynamicStoreRef session = SCDynamicStoreCreate(NULL, CFSTR("session"), NULL, NULL);


=====================================
modules/text_renderer/freetype/fonts/darwin.c
=====================================
@@ -33,6 +33,7 @@
 
 #include <vlc_common.h>
 #include <vlc_filter.h>                                      /* filter_sys_t */
+#include <vlc_charset.h>                                     /* FromCFString */
 
 #include <CoreFoundation/CoreFoundation.h>
 #include <CoreText/CoreText.h>
@@ -42,44 +43,6 @@
 char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor);
 void addNewFontToFamily(filter_t *p_filter, CTFontDescriptorRef iter, char *path, vlc_family_t *family);
 
-/* Obtains a copy of the contents of a CFString in specified encoding.
- * Returns char* (must be freed by caller) or NULL on failure.
- */
-static char* CFStringCopyCString(CFStringRef cfString, CFStringEncoding cfStringEncoding)
-{
-    // Try the quick way to obtain the buffer
-    const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding);
-
-    if (tmpBuffer != NULL) {
-       return strdup(tmpBuffer);
-    }
-
-    // The quick way did not work, try the long way
-    CFIndex length = CFStringGetLength(cfString);
-    CFIndex maxSize =
-        CFStringGetMaximumSizeForEncoding(length, cfStringEncoding);
-
-    // If result would exceed LONG_MAX, kCFNotFound is returned
-    if (unlikely(maxSize == kCFNotFound)) {
-        return NULL;
-    }
-
-    // Account for the null terminator
-    maxSize++;
-
-    char *buffer = (char *)malloc(maxSize);
-
-    if (unlikely(buffer == NULL)) {
-        return NULL;
-    }
-
-    // Copy CFString in requested encoding to buffer
-    Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding);
-
-    if (!success)
-        FREENULL(buffer);
-    return buffer;
-}
 
 char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
 {
@@ -91,7 +54,7 @@ char* getPathForFontDescription(CTFontDescriptorRef fontDescriptor)
         CFRelease(url);
         return NULL;
     }
-    char *retPath = CFStringCopyCString(path, kCFStringEncodingUTF8);
+    char *retPath = FromCFString(path, kCFStringEncodingUTF8);
     CFRelease(path);
     CFRelease(url);
     return retPath;
@@ -253,7 +216,7 @@ vlc_family_t *CoreText_GetFallbacks(filter_t *p_filter, const char *psz_family,
     CFStringRef fallbackFontFamilyName = CTFontCopyFamilyName(fallbackFont);
 
     /* create a new family object */
-    char *psz_fallbackFamilyName = CFStringCopyCString(fallbackFontFamilyName, kCFStringEncodingUTF8);
+    char *psz_fallbackFamilyName = FromCFString(fallbackFontFamilyName, kCFStringEncodingUTF8);
     if (psz_fallbackFamilyName == NULL) {
         msg_Warn(p_filter, "Failed to convert font family name CFString to C string");
         goto done;


=====================================
src/darwin/dirs.c
=====================================
@@ -28,6 +28,7 @@
 #endif
 
 #include <vlc_common.h>
+#include <vlc_charset.h>
 #include "../libvlc.h"
 
 #include <libgen.h>
@@ -144,18 +145,8 @@ static char *getAppDependentDir(vlc_userdir_t type)
     CFBundleRef mainBundle = CFBundleGetMainBundle();
     if (mainBundle) {
         CFStringRef identifierAsNS = CFBundleGetIdentifier(mainBundle);
-        if (identifierAsNS) {
-            CFIndex len = CFStringGetLength(identifierAsNS);
-            CFIndex size = CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8);
-            char *identifier = calloc(len + 1, sizeof(char));
-            if (identifier != NULL) {
-                Boolean ret = CFStringGetCString(identifierAsNS, identifier, size, kCFStringEncodingUTF8);
-                if (ret)
-                    name = identifier;
-                else
-                    free(identifier);
-            }
-        }
+        if (identifierAsNS)
+            name = FromCFString(identifierAsNS, kCFStringEncodingUTF8);
     }
 
     char *psz_parent = config_GetHomeDir ();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ed93768cedee7dae31a5b44d57a38d59da4dd1cf...fef232f9f51af5503cd11de24075311463d4b561

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ed93768cedee7dae31a5b44d57a38d59da4dd1cf...fef232f9f51af5503cd11de24075311463d4b561
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list