]> git.wh0rd.org - fontconfig.git/commitdiff
Add FcConfigReference() (#17124)
authorBehdad Esfahbod <behdad@behdad.org>
Fri, 22 Aug 2008 22:08:07 +0000 (18:08 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Sat, 14 Feb 2009 00:53:59 +0000 (16:53 -0800)
doc/fcconfig.fncs
fontconfig/fontconfig.h
src/fccfg.c
src/fcint.h

index 16d1000b9a47900612586d435f35703bc38e98dc..3ceab9218828d316459bb87d61a0a839f3c851d8 100644 (file)
 Creates an empty configuration.
 @@
 
+@RET@           FcConfig *
+@FUNC@          FcConfigReference
+@TYPE1@         FcConfig *                      @ARG1@          config
+@PURPOSE@      Increment config reference count
+@DESC@
+Add another reference to <parameter>config</parameter>. Configs are freed only
+when the reference count reaches zero.
+If <parameter>config</parameter> is NULL, the current configuration is used.
+In that case this function will be similar to FcConfigGetCurrent() except that
+it increments the reference count before returning and the user is responsible
+for destroying the configuration when not needed anymore.
+@@
+
 @RET@           void
 @FUNC@          FcConfigDestroy
 @TYPE1@         FcConfig *                      @ARG1@          config
 @PURPOSE@      Destroy a configuration
 @DESC@
-Destroys a configuration and any data associated with it.  Note that calling
-this function with the return from FcConfigGetCurrent will place the library
-in an indeterminate state.
+Decrements the config reference count. If all references are gone, destroys
+the configuration and any data associated with it.
+Note that calling this function with the return from FcConfigGetCurrent will
+cause a new configuration to be created for use as current configuration.
 @@
 
 @RET@           FcBool
index 55e1763b071b429176b726ee8516a4289d8ee7d1..41490728d1cfb4b5f7f0d4d9e782e80837068f54 100644 (file)
@@ -342,6 +342,9 @@ FcConfigFilename (const FcChar8 *url);
 FcPublic FcConfig *
 FcConfigCreate (void);
 
+FcPublic FcConfig *
+FcConfigReference (FcConfig *config);
+
 FcPublic void
 FcConfigDestroy (FcConfig *config);
 
index 85ad0f511570222decb7dc7d564fbce9c6e24e91..70748c86075abda717de371d4d63e75d85ceed30 100644 (file)
@@ -92,6 +92,8 @@ FcConfigCreate (void)
 
     config->rescanTime = time(0);
     config->rescanInterval = 30;    
+
+    config->ref = 1;
     
     return config;
 
@@ -191,11 +193,29 @@ FcSubstDestroy (FcSubst *s)
     }
 }
 
+FcConfig *
+FcConfigReference (FcConfig *config)
+{
+    if (!config)
+    {
+       config = FcConfigGetCurrent ();
+       if (!config)
+           return 0;
+    }
+
+    config->ref++;
+
+    return config;
+}
+
 void
 FcConfigDestroy (FcConfig *config)
 {
     FcSetName  set;
 
+    if (--config->ref > 0)
+       return;
+
     if (config == _fcConfig)
        _fcConfig = 0;
 
index 5798702bba977355f23d5bb8f4a199eefecc7585..370dd7e80fc7acc0a5476a787f85c2c7c5478c6b 100644 (file)
@@ -483,6 +483,8 @@ struct _FcConfig {
      */
     time_t     rescanTime;         /* last time information was scanned */
     int                rescanInterval;     /* interval between scans */
+
+    int                ref;                /* reference count */
 };
  
 extern FcPrivate FcConfig      *_fcConfig;