Different type pointer warning using libxml

New to FreeBASIC? Post your questions here.
Post Reply
MPJ
Posts: 2
Joined: Jun 06, 2023 15:30
Location: Rome (Italy)

Different type pointer warning using libxml

Post by MPJ »

Hello everyone,
I have a question / problem with the code below, assuming it seems to work properly, the compiler still warns me about pointers of different types.

Am I doing something wrong? sorry, but i'm not an expert programmer.

Code: Select all

Sub ValidateXMLfromXSD()
	Dim As xmlSchemaPtr schema = NULL
	Dim As xmlSchemaParserCtxtPtr schema_parser_ctxt = NULL
	Dim As Integer has_schema_errors = 0
   Dim As Integer ret = -1
   Dim As xmlSchemaValidCtxtPtr valid_ctxt = NULL
   
   schema_parser_ctxt = xmlSchemaNewParserCtxt(xsdfile)
   If (schema_parser_ctxt <> NULL) Then
		schema = xmlSchemaParse(schema_parser_ctxt)
      xmlSchemaFreeParserCtxt(schema_parser_ctxt)
      If (schema) Then
      	valid_ctxt = xmlSchemaNewValidCtxt(schema)
      EndIf
   EndIf
   
   Dim As xmlTextReaderPtr reader = xmlReaderForFile(xmlfile, NULL, 0)
   If (reader <> NULL) Then
   	If (valid_ctxt) Then
   		xmlTextReaderSchemaValidateCtxt(reader, valid_ctxt, 0)
   		xmlSchemaSetValidStructuredErrors(valid_ctxt, @schemaParseErrorHandler, @has_schema_errors)
   	EndIf
   	ret = xmlTextReaderRead(reader)
   	Do While (ret = 1)
   		ret = xmlTextReaderRead(reader)
   	Loop
   EndIf
   xmlFreeTextReader(reader)
   xmlCleanupParser()  

End Sub

Sub schemaParseErrorHandler(byval userData as any ptr, byval merror as xmlErrorPtr)
	Static As String test
	test += merror->Line & " " & merror->int2 & " " & *merror->message & !"\r\n"
	SetDlgItemText(hDlg, IDC_ERROR, StrPtr(test))
End Sub

Code: Select all

warning 3(2): Passing different pointer types, at parameter 2 of XMLSCHEMASETVALIDSTRUCTUREDERRORS()
angros47
Posts: 2253
Joined: Jun 21, 2005 19:04

Re: Different type pointer warning using libxml

Post by angros47 »

Can't tell for sure, but if you are using Windows, try adding CDecl to schemaParseErrorHandler:

Code: Select all

Sub schemaParseErrorHandler cdecl(byval userData as any ptr, byval merror as xmlErrorPtr)
MPJ
Posts: 2
Joined: Jun 06, 2023 15:30
Location: Rome (Italy)

Re: Different type pointer warning using libxml

Post by MPJ »

angros47 wrote: Jun 06, 2023 20:55 Can't tell for sure, but if you are using Windows, try adding CDecl to schemaParseErrorHandler
Thanks, it works!
And yes, I use Windows, but I still have to study a lot.
angros47
Posts: 2253
Joined: Jun 21, 2005 19:04

Re: Different type pointer warning using libxml

Post by angros47 »

Ok. Then the issue was that the function used a different calling convention: in Windows, by default Pascal-like calling convention is used, while the external library uses C calling convention (in fact, the definition was in an extern "c" block). The warning was due to your function using a different calling convention, that would have lead to a crash (since it was supposed to be called only if an error occurred, if there were no errors your program would have worked fine anyway). The Cdecl specified it had to use the C calling convention

Under Linux the C calling convention is used by default (you would notice no difference as long as you use only FreeBasic functions, unless you try to use variadic ones. So, that error would have not occurred, likely. That's why I asked if you were using Windows.
Post Reply