<div dir="ltr"><div class="gmail_quote">On Sun, Jun 17, 2012 at 2:02 AM, Bernd <span dir="ltr"><<a href="mailto:prof7bit@googlemail.com" target="_blank">prof7bit@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
I am translating parts of the libpurple headers. Now I seem to have a<br>
problem with this:<br>
<br>
<br>
typedef enum<br>
{<br>
PURPLE_PLUGIN_UNKNOWN = -1, /**< Unknown type. */<br>
PURPLE_PLUGIN_STANDARD = 0, /**< Standard plugin. */<br>
PURPLE_PLUGIN_LOADER, /**< Loader plugin. */<br>
PURPLE_PLUGIN_PROTOCOL /**< Protocol plugin. */<br>
<br>
} PurplePluginType;<br>
<br>
<br>
typedef int PurplePluginPriority;<br>
<br>
<br>
struct _PurplePluginInfo<br>
{<br>
unsigned int magic;<br>
unsigned int major_version;<br>
unsigned int minor_version;<br>
PurplePluginType type; // <-- maybe this is the problem?<br>
char *ui_requirement;<br>
unsigned long flags;<br>
GList *dependencies;<br>
PurplePluginPriority priority;<br>
<br>
char *id;<br>
char *name;<br>
char *version;<br>
char *summary;<br>
char *description;<br>
char *author;<br>
char *homepage;<br>
<br>
/**<br>
* If a plugin defines a 'load' function, and it returns FALSE,<br>
* then the plugin will not be loaded.<br>
*/<br>
gboolean (*load)(PurplePlugin *plugin);<br>
gboolean (*unload)(PurplePlugin *plugin);<br>
void (*destroy)(PurplePlugin *plugin);<br>
<br>
void *ui_info; /**< Used only by UI-specific plugins to build a<br>
preference screen with a custom UI */<br>
void *extra_info;<br>
PurplePluginUiInfo *prefs_info; /**< Used by any plugin to display<br>
preferences. If #ui_info has been specified, this will be ignored. */<br>
<br>
/**<br>
* This callback has a different use depending on whether this<br>
* plugin type is PURPLE_PLUGIN_STANDARD or PURPLE_PLUGIN_PROTOCOL.<br>
*<br>
* If PURPLE_PLUGIN_STANDARD then the list of actions will show up<br>
* in the Tools menu, under a submenu with the name of the plugin.<br>
* context will be NULL.<br>
*<br>
* If PURPLE_PLUGIN_PROTOCOL then the list of actions will show up<br>
* in the Accounts menu, under a submenu with the name of the<br>
* account. context will be set to the PurpleConnection for that<br>
* account. This callback will only be called for online accounts.<br>
*/<br>
GList *(*actions)(PurplePlugin *plugin, gpointer context);<br>
<br>
void (*_purple_reserved1)(void);<br>
void (*_purple_reserved2)(void);<br>
void (*_purple_reserved3)(void);<br>
void (*_purple_reserved4)(void);<br>
};<br>
<br>
<br>
<br>
I have translated it as follows:<br></blockquote><div><br>you have few problems here.<br>1. Please use ctypes instead, they are set to work properly with 64 bit etc.. and are properly sized to fit C's type sizes.<br>
For example C's int, is not equal to Pascal's Integer, but to longint of Pascal<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
<br>
{$calling cdecl}<br>
<br>
type<br>
TPurplePluginType = (<br>
PURPLE_PLUGIN_UNKNOWN := -1, // Unknown type.<br>
PURPLE_PLUGIN_STANDARD := 0, // Standard plugin.<br>
PURPLE_PLUGIN_LOADER, // Loader plugin.<br>
PURPLE_PLUGIN_PROTOCOL // Protocol plugin.<br>
);<br>
<br>
TPurplePluginPriority = Integer;<br>
<br>
TPurplePluginInfo = packed record<br>
magic: Integer;<br>
major_version: Integer;<br>
minor_version: Integer;<br>
plugintype: TPurplePluginType;<br>
ui_requirement: PChar;<br>
flags: LongInt;<br>
dependencies: PGList;<br>
priority: TPurplePluginPriority;<br>
id: PChar;<br>
name: PChar;<br>
version: PChar;<br>
summary: PChar;<br>
description: PChar;<br>
author: PChar;<br>
homepage: PChar;<br>
load: function(plugin: PPurplePlugin): GBoolean;<br>
unload: function(plugin: PPurplePlugin): GBoolean;<br>
destroy: procedure(plugin: PPurplePlugin);<br>
ui_info: Pointer;<br>
extra_info: Pointer;<br>
prefs_info: PPurplePluginUiInfo;<br>
actions: function(plugin: PPurplePlugin; context: Pointer): PGList;<br>
<br>
_purple_reserved1: Pointer;<br>
_purple_reserved2: Pointer;<br>
_purple_reserved3: Pointer;<br>
_purple_reserved4: Pointer;<br></blockquote><div><br>This 4 types are actually callback rather then "simple" pointers. It will work, but personally I prefer it as a callback when I can avoid general "Pointer".<br>
</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
end;<br>
<br>
This works perfectly well on windows 32 bit and Linux 32 bit but today<br>
someone helped me compile it on linux x86_64 and from the debug output<br>
of libpurple it seems that when I pass it this record initialized with<br>
my values it *can* detect that plugintype is set to<br>
PURPLE_PLUGIN_PROTOCOL because then it will try to read extra_info and<br>
it thinks it is null, probably it is off a few bytes.<br>
<br>
I cannot test this myself because I don't have a 64 bit Linux. When an<br>
experienced programmer (should be most on this list) looks at this<br>
header what is the obvious thing that might break it on 64 bit?<br>
Pointers should be ok, but what is with int and Integer and what is<br>
with enums? And are there maybe also certain compiler switches that<br>
influence it? What might be wrong?<br>
<span class="HOEnZb"><font color="#888888"><br>
Bernd<br>
_______________________________________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/mailman/listinfo/fpc-pascal</a><br>
</font></span></blockquote></div><br></div>