[Pkg-wmaker-commits] [wmforecast] 09/63: malloc and realloc changed to wmalloc and wrealloc; timer handler is now WMAddPersistentTimerHandler instead of pthread
Doug Torrance
dtorrance-guest at moszumanska.debian.org
Mon Aug 17 11:20:32 UTC 2015
This is an automated email from the git hooks/post-receive script.
dtorrance-guest pushed a commit to branch master
in repository wmforecast.
commit aca69567e592d8996b4d5145d5af4ab14dc27468
Author: Doug Torrance <dtorrance at monmouthcollege.edu>
Date: Sat Apr 19 22:16:23 2014 -0500
malloc and realloc changed to wmalloc and wrealloc; timer handler is now WMAddPersistentTimerHandler instead of pthread
---
ChangeLog | 6 +++++
configure | 45 ------------------------------------
configure.ac | 1 -
wmforecast.c | 75 +++++++++++++++++++++++++++---------------------------------
4 files changed, 40 insertions(+), 87 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f0716c4..e90d91c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,10 @@
2015-04-18 Doug Torrance <dtorrance at monmouthcollege.edu>
+ * wmforecast.c: switched timer handler from pthread to WINGs's native
+ WMAddPersistentTimerHandler; as a result, ThreadData struct renamed
+ UpdateData; updateDockapp now takes UpdateData as an argument
+ * configure.ac: removed check for pthread
+ * wmforecast.c: changed all calls to malloc and realloc to use WINGs's
+ native wmalloc and wrealloc
* wmforecast.c (updateDockapp): added "loading" text while downloading
new weather data
* wmforecast.c (refresh, main): new function, refreshes weather data
diff --git a/configure b/configure
index 60d5aa4..ba026cb 100755
--- a/configure
+++ b/configure
@@ -3756,51 +3756,6 @@ _ACEOF
fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for pthread_create in -lpthread" >&5
-$as_echo_n "checking for pthread_create in -lpthread... " >&6; }
-if ${ac_cv_lib_pthread_pthread_create+:} false; then :
- $as_echo_n "(cached) " >&6
-else
- ac_check_lib_save_LIBS=$LIBS
-LIBS="-lpthread $LIBS"
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-
-/* Override any GCC internal prototype to avoid an error.
- Use char because int might match the return type of a GCC
- builtin and then its argument prototype would still apply. */
-#ifdef __cplusplus
-extern "C"
-#endif
-char pthread_create ();
-int
-main ()
-{
-return pthread_create ();
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
- ac_cv_lib_pthread_pthread_create=yes
-else
- ac_cv_lib_pthread_pthread_create=no
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext conftest.$ac_ext
-LIBS=$ac_check_lib_save_LIBS
-fi
-{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pthread_pthread_create" >&5
-$as_echo "$ac_cv_lib_pthread_pthread_create" >&6; }
-if test "x$ac_cv_lib_pthread_pthread_create" = xyes; then :
- cat >>confdefs.h <<_ACEOF
-#define HAVE_LIBPTHREAD 1
-_ACEOF
-
- LIBS="-lpthread $LIBS"
-
-fi
-
ac_config_files="$ac_config_files Makefile icons/Makefile"
diff --git a/configure.ac b/configure.ac
index 963129a..3224c21 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,7 +7,6 @@ AC_PROG_CC
PKG_CHECK_MODULES([libxml2],[libxml-2.0])
PKG_CHECK_MODULES([libcurl],[libcurl])
AC_CHECK_LIB(WINGs,WMCreateWindow)
-AC_CHECK_LIB(pthread,pthread_create)
AC_CONFIG_FILES([Makefile icons/Makefile])
AM_MISSING_PROG(HELP2MAN, help2man, $missing_dir)
AC_OUTPUT
\ No newline at end of file
diff --git a/wmforecast.c b/wmforecast.c
index f54de23..714b20c 100755
--- a/wmforecast.c
+++ b/wmforecast.c
@@ -25,7 +25,6 @@
#include <curl/curl.h>
#include <libxml/tree.h>
#include <getopt.h>
-#include <pthread.h>
#define color(c) WMCreateNamedColor(screen,c,True)
@@ -68,11 +67,11 @@ typedef struct {
WMScreen *screen;
Dockapp *dockapp;
Preferences *prefs;
-} ThreadData;
+} UpdateData;
Forecast *newForecast()
{
- Forecast *forecast = malloc(sizeof(Forecast));
+ Forecast *forecast = wmalloc(sizeof(Forecast));
forecast->day = NULL;
forecast->low = NULL;
forecast->high = NULL;
@@ -82,7 +81,7 @@ Forecast *newForecast()
ForecastArray *newForecastArray()
{
- ForecastArray *array = malloc(sizeof(ForecastArray));
+ ForecastArray *array = wmalloc(sizeof(ForecastArray));
array->length = 0;
array->forecasts = NULL;
return array;
@@ -91,13 +90,13 @@ ForecastArray *newForecastArray()
void appendForecast(ForecastArray *array, Forecast *forecast)
{
array->length++;
- array->forecasts = (Forecast *)realloc(array->forecasts, sizeof(Forecast)*(array->length));
+ array->forecasts = (Forecast *)wrealloc(array->forecasts, sizeof(Forecast)*(array->length));
array->forecasts[(array->length)-1] = *forecast;
}
Weather *newWeather()
{
- Weather *weather = malloc(sizeof(Weather));
+ Weather *weather = wmalloc(sizeof(Weather));
weather->temp = NULL;
weather->text = NULL;
weather->title = NULL;
@@ -148,7 +147,7 @@ void freeWeather(Weather *weather)
void setTitle(Weather *weather, const char *title)
{
- weather->title = realloc(weather->title, strlen(title) + 1);
+ weather->title = wrealloc(weather->title, strlen(title) + 1);
strcpy(weather->title, title);
}
@@ -162,9 +161,9 @@ void setConditions(Weather *weather,
RContext *context;
char *filename;
- weather->temp = realloc(weather->temp, strlen(temp) + 1);
+ weather->temp = wrealloc(weather->temp, strlen(temp) + 1);
strcpy(weather->temp, temp);
- weather->text = realloc(weather->text, strlen(text) + 1);
+ weather->text = wrealloc(weather->text, strlen(text) + 1);
strcpy(weather->text, text);
context = WMScreenRContext(screen);
@@ -179,13 +178,13 @@ void setForecast(Forecast *forecast,
const char *text
)
{
- forecast->day = realloc(forecast->day, strlen(day) + 1);
+ forecast->day = wrealloc(forecast->day, strlen(day) + 1);
strcpy(forecast->day, day);
- forecast->low = realloc(forecast->low, strlen(low) + 1);
+ forecast->low = wrealloc(forecast->low, strlen(low) + 1);
strcpy(forecast->low, low);
- forecast->high = realloc(forecast->high, strlen(high) + 1);
+ forecast->high = wrealloc(forecast->high, strlen(high) + 1);
strcpy(forecast->high, high);
- forecast->text = realloc(forecast->text, strlen(text) + 1);
+ forecast->text = wrealloc(forecast->text, strlen(text) + 1);
strcpy(forecast->text, text);
}
@@ -219,7 +218,7 @@ WMWindow *WMCreateDockapp(WMScreen *screen, const char *name, int argc, char **a
Dockapp *newDockapp(WMScreen *screen, int argc, char **argv)
{
- Dockapp *dockapp = malloc(sizeof(Dockapp));
+ Dockapp *dockapp = wmalloc(sizeof(Dockapp));
WMFrame *frame;
WMWindow *window;
@@ -284,7 +283,7 @@ char *getBalloonText(Weather *weather)
void setError(Weather *weather, WMScreen *screen, const char *errorText)
{
weather->errorFlag = 1;
- weather->errorText = realloc(weather->errorText, strlen(errorText) + 1);
+ weather->errorText = wrealloc(weather->errorText, strlen(errorText) + 1);
strcpy(weather->errorText, errorText);
@@ -310,10 +309,10 @@ WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
size_t realsize = size * nmemb;
struct MemoryStruct *mem = (struct MemoryStruct *)userp;
- mem->memory = realloc(mem->memory, mem->size + realsize + 1);
+ mem->memory = wrealloc(mem->memory, mem->size + realsize + 1);
if(mem->memory == NULL) {
/* out of memory! */
- printf("not enough memory (realloc returned NULL)\n");
+ printf("not enough memory (wrealloc returned NULL)\n");
return 0;
}
@@ -345,7 +344,7 @@ Weather *getWeather(WMScreen *screen, Preferences *prefs)
}
weather = newWeather();
- chunk.memory = malloc(1);
+ chunk.memory = wmalloc(1);
chunk.size = 0;
curl_global_init(CURL_GLOBAL_ALL);
@@ -443,8 +442,13 @@ Weather *getWeather(WMScreen *screen, Preferences *prefs)
return weather;
}
-void updateDockapp(WMScreen *screen, Dockapp *dockapp, Preferences *prefs)
+static void updateDockapp(void *data)
{
+ UpdateData *d = (UpdateData *)data;
+
+ WMScreen *screen = d->screen;
+ Dockapp *dockapp = d->dockapp;
+ Preferences *prefs = d->prefs;
Weather *weather;
WMPixmap *icon;
@@ -485,7 +489,7 @@ void updateDockapp(WMScreen *screen, Dockapp *dockapp, Preferences *prefs)
Preferences *setPreferences(int argc, char **argv)
{
int c;
- Preferences *prefs = malloc(sizeof(Preferences));
+ Preferences *prefs = wmalloc(sizeof(Preferences));
//set defaults
prefs->units = "f";
@@ -597,29 +601,19 @@ Preferences *setPreferences(int argc, char **argv)
return prefs;
}
-ThreadData *newThreadData(WMScreen *screen, Dockapp *dockapp, Preferences *prefs)
+UpdateData *newUpdateData(WMScreen *screen, Dockapp *dockapp, Preferences *prefs)
{
- ThreadData *data = malloc(sizeof(ThreadData));
+ UpdateData *data = wmalloc(sizeof(UpdateData));
data->screen = screen;
data->dockapp = dockapp;
data->prefs = prefs;
return data;
}
-void *timerLoop(void *args)
-{
- ThreadData *data = args;
- for (;;) {
- updateDockapp(data->screen, data->dockapp, data->prefs);
- sleep(60*data->prefs->interval);
- }
-}
-
-static void refresh(XEvent *event, void *args)
+static void refresh(XEvent *event, void *data)
{
- ThreadData *data = args;
if (WMIsDoubleClick(event) && event->xbutton.button == Button1)
- updateDockapp(data->screen, data->dockapp, data->prefs);
+ updateDockapp(data);
}
int main(int argc, char **argv)
@@ -627,25 +621,24 @@ int main(int argc, char **argv)
Display *display;
Dockapp *dockapp;
Preferences *prefs;
- pthread_t thread;
- ThreadData *data;
+ UpdateData *data;
WMScreen *screen;
prefs = setPreferences(argc, argv);
- XInitThreads();
-
WMInitializeApplication("wmforecast", &argc, argv);
display = XOpenDisplay("");
screen = WMCreateScreen(display, DefaultScreen(display));
dockapp = newDockapp(screen, argc, argv);
- data = newThreadData(screen, dockapp, prefs);
-
- pthread_create(&thread, NULL, timerLoop, data);
+ data = newUpdateData(screen, dockapp, prefs);
WMCreateEventHandler(WMWidgetView(dockapp->icon), ButtonPressMask,
refresh, data);
+ updateDockapp(data);
+ WMAddPersistentTimerHandler(1000*60*prefs->interval,
+ updateDockapp, data);
+
WMScreenMainLoop(screen);
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-wmaker/wmforecast.git
More information about the Pkg-wmaker-commits
mailing list